Save binary image into .dcm

Hi
I have segmented an organ from a CT scan (original image given in DICOM) and I would like to save the segmented image (binary one) as .dcm due to I need to use it after in other software that only read .dcm. Could someone explain me how I can do that?
Thank you in advance.

7 个评论

Isabel - do you have the Image Processing Toolbox? If so, try the dicomwrite function
dicomwrite(X, filename) writes the binary, grayscale, or truecolor image X to the file filename, where filename is a string specifying the name of the Digital Imaging and Communications in Medicine (DICOM) file to create.
I have used dicomwrite dicomwrite(reshape(seg17,[512 512 1 268]), 'ct_seg.dcm', info, 'CreateMode', 'copy'); where seg17 is my binary segmentation (512x512x268 logical) and info is the metadata obtained with dicominfo.
However when I run it, I got the follow warning and when I load it into the other software (itk-snap) I found out that it's flipped and that the spacing and origing is different than the original image. Do you know why this can occur?
% Warning: Logical data will be scaled to fit the range [0, 255].
In iptformats\private\dicom_encode_pixel_cells at 17
In iptformats\private\dicom_prep_ImagePixel>encodePixelData at 272
In iptformats\private\dicom_prep_ImagePixel at 19
In iptformats\private\dicom_copy_IOD at 31
In dicomwrite>write_message at 267
In dicomwrite at 199
Isabel - what do you mean by flipped? Is the image transposed or flipped left to right? And is the origin different?
To avoid the warning message, you can probably just convert the data to 8-bit unsigned integers and multiply by 255 (since the binary data is just 0s or 1s). Something like
seg17 = 255*uint8(seg17);
Why are you doing the reshape, and so adding the extra dimension?
Hi Geoff
I used reshape because otherwise when I use dicomwrite I get the follow errors:
% Error using dicom_prep_ImagePixel>getPhotometricInterp (line 127)
Cannot determine photometric interpretation.
Error in dicom_prep_ImagePixel (line 9)
metadata.(dicom_name_lookup('0028', '0004', dictionary)) = getPhotometricInterp(metadata, X, map, txfr, dictionary);
Error in dicom_copy_IOD (line 31)
metadata = dicom_prep_ImagePixel(metadata, X, map, options.txfr, dictionary);
Error in dicomwrite>write_message (line 267)
[attrs, status] = dicom_copy_IOD(X, map, ...
Error in dicomwrite (line 199)
[status, options] = write_message(X, filename, map, metadata, options);
I was checking these errors in previous questions here, and one solution was to apply reshape.
With flipped I mean that the segmentation after convert it to .dcm is upside down with respect to the original image. And yes the origin is different; in the original image the origin is -141.715x308.715x1675.4 and voxel spacing 0.570313x0.570313x0.799927 and in the segmented image is origin -141.715x-308.715x1889 and voxel spacing 0.570313x0.570313x1
I don't know why it is happening because I'm copy the same metadata from the original image to the segmented one. Any ideas?
Thanks for your comments and help
Isabel - I'm not sure why that would be happening. Out of curiosity, if you read the file back in to MATLAB (with dicomread) are the images upside down? Is the meta data (as obtained with dicominfo) the same as the original, or has it been changed too?
You could try to flip the image before writing it to file with flipud. Something like
dicomwrite(flipud(reshape(seg17,[512 512 1 268])), 'ct_seg.dcm', info, 'CreateMode', 'copy');
You could also check the status of the dicomwrite as
status = dicomwrite(flipud(reshape(seg17,[512 512 1 268])), ...
'ct_seg.dcm', info, 'CreateMode', 'copy');
Hi Geoff!
To flip the image I used flipdim(seg17,3) due to my image is a volume and flipud only allow 2D, but thanks for the suggestion anyway.
About my problem I finally manage to fix it. The problem was not in the way to create the DICOM file with dicomwrite, the problem was in the way that ITK-Snap read the headers when you load a CT scan. So, now everything is working fine.
Thank you for your help!
Glad that you were able to get everything working, Isabel!

请先登录,再进行评论。

回答(0 个)

提问:

2014-8-19

Community Treasure Hunt

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

Start Hunting!

Translated by