dicomContours.createMask issue

6 views (last 30 days)
Christopher Rookyard
Christopher Rookyard on 16 Apr 2021
Answered: Shivam Lahoti on 11 Mar 2025
I have ROI contour data, stored in DICOM-RT structures.
I import using dicominfo, then extract the contours using dicomContours, e.g.:
roiData = dicominfo('my_dicom_roi.dcm');
roiContours = dicomContours('info');
And I would import a dicom image that the ROI was drawn on, including the "spatial" variable, to pass to the createMask function:
[image,spatialData] = dicomreadVolume('my_dicom_image.dcm');
mask = createMask(roiContours,1,spatialData);
Now, if I look at the slice positions in the image and the ROI data, I find that in the binary image "mask", the ROI appears to be shifted by a slice.
An example will demonstrate:
Let's say the extremes in the 3rd dimension of the ROI contour data are -48, and -10, and these, using the "spatial" information, correspond to slices 32 and 49, respectively. So, I would expect the ROI in the mask image to begin at slice 32, and finish at slice 49, but, if I look at the slices the ROI appears within the "mask" image, it starts at 31, and finishes at 48.
I cannot see an obvious reason for this, and I wonder if anybody has any suggestions. Any help would be gratefully received.
  3 Comments
Doug Moseley
Doug Moseley on 14 Sep 2021
I see the same issue. I think I traced it to a coordinate transformation and the classic fence post problem AND a 1-based indexing scheme.
The DICOM ImagePositionPatient parameter defines the center of the upper/outer pixel. So the mapping between a pixel 'i' and spatial coordinate 'x' for a 1-based array is defined by:
i = (x-Sx)/dx + 1
where
i is the pixel index, i is an element of [1,Ni]
Ni is the number of pixels in a dimension.
x is the spatial image coordinate in [mm]
dx is the image plane pixel spacing in [mm]
Sx is the Image Position Patient parameter which is computed by:
Sx = -(Ni-1)*dx/2
Use the "imref3d" to define the coordinate system rather than the "spatial" returned from "dicomreadVolume".
I think the bug is on line 115,116 and 117 of "createMaskHelp.m" where the -0.5 is subtracted.
D.
Andreas Wetscherek
Andreas Wetscherek on 28 Jun 2022
Hi,
we recently encountered a problem with the dicomContours as well, in particular the createMask function. We also observed a shift by one slice in some, but not all cases. It worked fine in Matlab 2020b, but is not producing the correct results in 2021b anymore. We identified, that in the file createMaskHelp.m, the following line was changed between 2020b and 2021b:
dataToMask{contour}(:,3) = round(dataToMask{contour}(:,3));
in 2021b it is:
dataToMask{contour}(:,3) = ceil(dataToMask{contour}(:,3));
Reversing this changed fixed the issue for us.
Cheers,
Andreas

Sign in to comment.

Answers (1)

Shivam Lahoti
Shivam Lahoti on 11 Mar 2025
Hi Christopher,
I understand you are facing the issue with "dicomContours.createMask".
I believe this issue was there till MATLAB release R2021a. The only workaround was to manually shift the slice indices by one when using "createMask" function. However, this issue is fixed from MATLAB release R2021b, therefore it would work as expected without any manual shifts.
I hope this helps resolve the query.
Regards,
Shivam.

Community Treasure Hunt

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

Start Hunting!