0

I am new to Image Processing and want to know how can I pre-process dicom images using python. I am following the below tutorial:dicom in python I do not have the SliceThickness attribute in my data. How can I calculate it?

This is a sample dataset which I have:

Dataset

Here is my code:

import pydicom
import os
import numpy
from matplotlib import pyplot, cm

PathDicom = "xyz\images"
lstFilesDCM = []  # creating an empty list
for dirName, subdirList, fileList in os.walk(PathDicom):
    for filename in fileList:
        if ".dcm" in filename.lower():  # checking whether the file's DICOM
            lstFilesDCM.append(os.path.join(dirName,filename))

RefDs = pydicom.read_file(lstFilesDCM[0])
ConstPixelDims = (int(RefDs.Rows), int(RefDs.Columns), len(lstFilesDCM)) #Load dimensions based on the number of rows, columns, and slices (along the Z axis)
ConstPixelSpacing = (float(RefDs.PixelSpacing[0]), float(RefDs.PixelSpacing[1]), float(RefDs.SliceThickness)) # Load spacing values (in mm)

This is the error I got:

'FileDataset' object has no attribute 'SliceThickness'
4

2 回答 2

3

Tarmo R 的评论是正确的。查看您的数据,它具有 CR(计算机放射成像)作为模态,这是一张单张图片,因为它基本上是数字 X 射线。因此它永远不会有 SliceThickness 属性。

在这种情况下,您可以立即获得一个包含像素数据的 numpy 数组:

image_pixel_data = RefDs.pixel_array
于 2018-09-05T14:27:06.543 回答
0

这对我有用:

RefDs.pixel_array

它将图像直接转换为 numpy 数组。

于 2018-09-06T06:11:24.647 回答