This example shows how to create a new DICOM series for a modified DICOM image.
In the DICOM standard, images can be organized into series. By default, when you write an image with metadata to a DICOM file,
dicomwrite puts the image in the same series. You typically only start a new DICOM series when you modify the image in some way. To make the modified image the start of a new series, assign a new DICOM unique identifier to the SeriesInstanceUID metadata field.
Read an image from a DICOM file into the workspace.
I = dicomread('CT-MONO2-16-ankle.dcm');
Display the image. Because the DICOM image data is signed 16-bit data, automatically scale the display range so that the minimum pixel value is black and the maximum pixel value is white.
Read the metadata from the DICOM file.
info = dicominfo('CT-MONO2-16-ankle.dcm');
To identify the series an image belongs to, view the value of the SeriesInstanceUID property.
ans = '1.2.840.113622.214.171.1241.1031152382.365.736169244'
This example modifies the image by removing all of the text from the image. Text in the image appears white. Find the maximum value of all pixels in the image, which corresponds to the white text.
textValue = max(I(:));
The background of the image appears black. Find the minimum value of all pixels in the image, which corresponds to the background.
backgroundValue = min(I(:));
To remove the text, set all pixels with the maximum value to the minimum value.
Imodified = I; Imodified(Imodified == textValue) = backgroundValue;
View the processed image.
To write the modified image as a new series, you need a new DICOM unique identifier (UID). Generate a new UID using the
dicomuid is guaranteed to generate a unique UID.
uid = dicomuid
uid = '126.96.36.199.4.1.95188.8.131.52.26579106419417001827022017773125436101'
Set the value of the SeriesInstanceUID field in the metadata associated with the original DICOM file to the generated value.
info.SeriesInstanceUID = uid;
Write the modified image to a new DICOM file, specifying the modified metadata structure, info, as an argument. Because you set the SeriesInstanceUID value, the written image is part of a new series.
To verify this operation, view the image and the SeriesInstanceUID metadata field in the new file.