Clear Filters
Clear Filters

how to convert dicom RT structure to binary mask

32 views (last 30 days)
I am using the MATLAB documentation for converting ROIs stored in my DICOM-RT structure into binary masks. I am using [536,536,25] as the image size for the imref3d function. However, when I run the code it gives me this warning and the binary masks are empty. Can some please tell me what is going wrong?
"Warning: [20] contours have been found to be of incorrect Geometric type and have been omitted from
mask creation
> In images.internal.dicom.createMaskHelp (line 135)
In dicomContours/createMask (line 361) "
Here is my code:
info = dicominfo('p001_Pre_RT.dcm');
contour = dicomContours(info);
stat = contour.ROIs;
referenceInfo = imref3d([352,352,25],xlim,ylim,zlim);
contourIndex = 3; %non-enhancing mask
neMask_pt01 = createMask(contour, contourIndex, referenceInfo);

Answers (1)

Simon Chan
Simon Chan on 17 Jan 2022
It uses world coordinates in x,y & z axis which is shown in your attached png file. So you need to capture the axis information to create the referenceInfo.
info = dicominfo('p001_Pre_RT.dcm');
rtContours = dicomContours(info);
plotContour(rtContours); % Your attached figure here
ax = gca; % Get the axis information here
referenceInfo = imref3d([536,536,25],ax.XLim,ax.YLim,ax.ZLim);
contourIndex = 3;
rtMask = createMask(rtContours, contourIndex, referenceInfo);
volshow(rtMask); % Just check you are able to obtain the masks
Raheema Al Karim Damani
Raheema Al Karim Damani on 19 Jan 2022
Edited: Raheema Al Karim Damani on 19 Jan 2022
Okay so the only thing that got rid of that warning for me was to go into the CreateMask function and then edit this code on the line if numel(geoTypes) == numel(contours) && false
to if numel(geoTypes) == numel(contours)
this way I am actually able to get the binary masks but they do not look correct. I'm not sure what do.
Simon Chan
Simon Chan on 20 Jan 2022
I think the masks created by MATLAB are correct since they matches what you see in plotContour command.
When you rotate the contours in plotContour, you are able to see the contours only appears in some of the slices, and there exist a large gap between them. So a lot of masks created are blank.
So the main concern is that whether the RT Structure file is created correctly.
May be this file was created via a in-house software, or a third party software or both? or I may be wrong.
Anyway, I spend some time on your attached zip file and found the followings:
(1) Review ROIContourSequence and found that
For ROI#1,
ReferencedSOPClassUID: '1.2.840.10008.'
ReferencedSOPInstanceUID: '2.16.840.1.114362.1.11940992.24221775583.597460774.939.450'
However, for ROI#2 to ROI#5
ReferencedSOPClassUID: '1.2.840.10008.'
ReferencedSOPInstanceUID: '1.2.840.113619.'
(2) Review ContourImageSequence in RTReferencedSeriesSequence found that
ReferencedSOPClassUID: '1.2.840.10008.'
ReferencedSOPInstanceUID: '2.16.840.1.114362.1.11940992.24221775583.597460774.939.450'
It seems ROI#2 to ROI#5 were created separately from ROI#1 where the reference images are different.
(3) I checked All contours are CLOSED_PLANAR and hence createMask should be able to create the mask for you. The warning message may suggests that there are some inconsistency in the RT Structure file that the program is declined to do it and that is the reason why you need to edit the code to make it work.
I would suggest to create the RT Structure file from the beginning one more time and try again.

Sign in to comment.


Find more on DICOM Format in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!