# Mask of dicom image

**URL:** <https://discourse.slicer.org/t/mask-of-dicom-image/23684>\
**Category:** Radiomics\
**Created:** [June 2, 2022, 1:23pm UTC](https://discourse.slicer.org/t/mask-of-dicom-image/23684 "2022-06-02T13:23:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Van\_Tran\_Sang\_Huynh](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/van_tran_sang_huynh/32/15043_2.png) [@Van\_Tran\_Sang\_Huynh](https://discourse.slicer.org/u/Van_Tran_Sang_Huynh)\
**Post date:** [June 2, 2022, 1:23pm UTC](https://discourse.slicer.org/t/mask-of-dicom-image/23684/1 "2022-06-02T13:23:30Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![JoostJM](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/joostjm/32/1091_2.png) [@JoostJM](https://discourse.slicer.org/u/JoostJM)\
**Post date:** [June 4, 2022, 12:33pm UTC](https://discourse.slicer.org/t/mask-of-dicom-image/23684/2 "2022-06-04T12:33:46Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Van\_Tran\_Sang\_Huynh](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/van_tran_sang_huynh/32/15043_2.png) [@Van\_Tran\_Sang\_Huynh](https://discourse.slicer.org/u/Van_Tran_Sang_Huynh)\
**Post date:** [June 5, 2022, 1:33pm UTC](https://discourse.slicer.org/t/mask-of-dicom-image/23684/4 "2022-06-05T13:33:39Z")

</div>

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

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/7/6/76c5c538d533dfd81cc96f74c0dce08e4d9e9051.png)
