Dicom write error RImage

15 views (last 30 days)
Javier Sanchez Ruiperez
Javier Sanchez Ruiperez on 7 Oct 2020
Commented: jorge bojorquez on 25 Nov 2020
I am trying to alter an image and then write it back to .dcm format with its original header metadata. This is an RT image radiograph file (meaning it has structure contour data included in the header attributes (50xx,3000)). Using dicomwrite, I get the error: "Error using dicom_add_attr>validate_data (line 122) Attribute (5000,3000) has wrong data type."
I have done nothing to the header data besides read it directly from the original dicom file. I need to write this image back to dicom with its header intact. Are there any options to ignore discrepancies in Matlab's validation?
Here is a test that produces the error:
img = dicomread('RI.Field 1.dcm');
hdr = dicominfo('RI.Field 1.dcm');
dicomwrite(img,'file.dcm',hdr,'CreateMode','copy');
I have read that the solution is Convert each structure to uint16 before passing the metadata to dicomwrite but i don't know how to do it.
  1 Comment
jorge bojorquez
jorge bojorquez on 25 Nov 2020
1) You need to identify the error:
Error using dicom_add_attr>validate_data (line 122): Attribute (5000,3000) has wrong data type.
In the case, it is attribute (5000, 3000).
2) Look for this attribute (Dicom tag) in your structure: Atribute (5000,3000) = hdr.CurveData_0
Just google "Dicom 5000,3000" because It seems that matlab does not show the dicom tags (e.g. 5000,3000)
For this case, it is expecting a uint16 and it is a double:
3) So, you need to change this attribute to uint16.
hdr.CurveData_0 = uint16(hdr.CurveData_0)
4) Now, you should not have a problem writing your file:
dicomwrite(img,'file.dcm',hdr,'CreateMode','copy');
If you have a problem with another attribute (tag), just repeat the process.

Sign in to comment.

Answers (1)

Kiran Felix Robert
Kiran Felix Robert on 5 Nov 2020
Hi Javier,
DICOMWRITE does a minimal level of metadata content verification when the CreateMode parameter is given a value of "copy". It makes sure that the datatype of the input matches the expected. So, the Field Corresponding to the attribute needs to be of the appropriate data type.
Suppose the field which causes a data type mismatch is the Gantry ID Field, the Following code can be used to solve it. (The Gantry ID Field requires a data type of ‘LO or long text or char),
info = dicominfo(image);
Im = dicomread(info);
info.GantryID = char(info.GantryID'); % Changing the data type
dicomwrite(Im, newname, info, 'CreateMode', 'copy')
Kiran Felix Robert

Categories

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!