Mask of dicom image

I use python pyradiomics for feature extraction. I have imported the DICOM image but about the masking part i still don’t know if i did it right or not. If my masking part is wrong, please tell me how to correct and mask the dicom image!!! Please
import SimpleITK as sitk
import matplotlib.pyplot as plt

imageName = ‘C:/Users/Admin/Desktop/CERR/Gui SV/CT3.DCM’
maskName = ‘C:/Users/Admin/Desktop/CERR/Gui SV/CT3.DCM’
image = sitk.ReadImage(imageName)
mask = sitk.ReadImage(maskName)

ndImg = sitk.GetArrayFromImage(image)
ndLbl = sitk.GetArrayFromImage(mask)
plt.imshow(ndImg[0])
plt.show()
plt.imshow(ndLbl[0])
plt.show()

settings = {}
settings[‘binWidth’] = 25

If enabled, resample image (resampled image is automatically cropped.

settings[‘resampledPixelSpacing’] = None # [3,3,3] is an example for defining resampling (voxels with size 3x3x3mm)
settings[‘interpolator’] = sitk.sitkBSpline
settings[‘label’] = 1 #Since the mask area has a pixel value of 1 (otherwise it is 0).

#Check the integrity of the mask and create a bbox# 2020/1/23 Addendum
bb, correctedMask = imageoperations.checkMask(image, mask)
if correctedMask is not None:
mask = correctedMask
image, mask = imageoperations.cropToTumorMask(image, mask, bb)

firstOrderFeatures = radiomics.firstorder.RadiomicsFirstOrder(image, mask, **settings)

firstOrderFeatures.enableFeatureByName(‘Mean’, True)

firstOrderFeatures.enableAllFeatures()

print('Will calculate the following first order features: ‘)
for f in firstOrderFeatures.enabledFeatures.keys():
print(’ ', f)
print(getattr(firstOrderFeatures, ‘get%sFeatureValue’ % f).doc)

print(‘Calculating first order features…’)
results = firstOrderFeatures.execute()
print(‘done’)

print('Calculated first order features: ‘)
for (key, val) in six.iteritems(results):
print(’ ', key, ‘:’, val)

There are 2 main points regarding your code:

  1. The code you use does not reflect the intended use of PyRadiomics. It’s much, much, much better to use the featureextractor module, it’s designed for this.
  2. You load the same file as both image and mask. Generally, your mask should be an image containing only 1’s and 0’s identifying your region. This mask is obtained by segmenting the lesion on the DICOM images. This can be done for example using slicer.

Did you find this code useful? And can you help me in more detail about creating labels for lung cancer dicom images.

1 Like