MATLAB: How to edit a DICOM image

Image Processing Toolbox

How do I edit a DICOM image (e.g. overlaying a black box) while maintaining the DICOM file format?

Best Answer

There currently is no image processing function to directly add features to a DICOM image. Instead, use the following workflow to edit the desired image and rewrite to a DICOM file:
1) Read in and display DICOM image
img = dicomread('FILENAME.dcm');
imshow(img,'DisplayRange',[]);
2) Plot desired features onto the image (e.g. 'rectangle')
3) Get image data array for updated figure
img = getframe();
4) Write image data to new DICOM file
dicomwrite(img.cdata,'FILENAME_REDACTED.dcm')
If you would like to maintain the metadata from the original file, store it using 'dicominfo' and pass the resulting struct as an argument to 'dicomwrite'.