dicomwrite assigning incorrect VR and data type
Ältere Kommentare anzeigen
Hi,
I've scripts for anonymising dicom files. Dicoms are read in with dicominfo and dicomwrite. This has working well for a period of time on MRI data. I have previously expanded this to ECG dicoms without issue. I've come back after a while to reuse the script for similarly acquired ECG data and dicomwrite is failing due to the waveform data being uint16 and the vr_details generated during write being incorrect with uint8.
Error message:
.................
Error using dicom_add_attr>validate_data (line 122)
Attribute (5400,1010) has wrong data type.
Error in dicom_add_attr (line 107)
attr_str(pos).Data = validate_data(data, attr_str(pos), specificCharacterSet);
Error in dicom_convert_meta_to_attr (line 39)
attr = dicom_add_attr([], tag(1), tag(2), dictionary, specificCharacterSet, data, VR);
Error in dicom_convert_meta_to_attr>encode_item (line 151)
new_attr = dicom_convert_meta_to_attr(attr_names{p}, item_struct, dictionary, txfr, specificCharacterSet);
Error in dicom_convert_meta_to_attr>encode_SQ (line 125)
data = encode_item(SQ_struct.(items{p}), dictionary, txfr, specificCharacterSet);
Error in dicom_convert_meta_to_attr (line 26)
data = encode_SQ(metadata.(attr_name), dictionary, txfr, specificCharacterSet);
Error in dicom_copy_IOD (line 65)
new_attr = dicom_convert_meta_to_attr(attr_name, metadata, dictionary, options.txfr, specificCharacterSet);
Error in dicomwrite>write_message (line 280)
[attrs, status] = dicom_copy_IOD(X, map, ...
Error in dicomwrite (line 211)
[status, options] = write_message(X, filename, map, metadata, options);
......................
From what I can see all the correct VR data is in original dicom file and the subsequent header from dicominfo but isn't being used for the write.
WaveformSequence.Item_1 details:

vr_details caught from exception during write:

I'm using this command to write the data
dicomwrite(dcm_data, [dest_folder,fname], dcm_hdr1, 'CreateMode','copy','WritePrivate',true,)
and have tried adding
dicomwrite(dcm_data, [dest_folder,fname], dcm_hdr1, 'CreateMode','copy','WritePrivate',true, 'UseDictionaryVR', false);
I've also tried read the header with this flag set to true (I think defualt) and false.
dcm_hdr1 = dicominfo(file_to_anon, 'useVRHeuristic',false)
I've also tried to write the dicom using the original header but this has the same result as does dicomanon.
I've looked at the header data in Weasis and it gives the correct information:

I assume that matlab isn't using the data in the header to define the atrributes and using a default?
Any advice on what I can do?
This is happening on both 2021b and 2022a. I will update one of these machines to 2023a but hopes aren't high. Fails on clean 2023a too.
2 Kommentare
Rik
am 17 Jun. 2023
If I recall correctly, Matlab tends to use very old DICOM dictionaries. Usually that isn't a problem, since the standard is so stable.
In this case you might want to try if you can copy the default dictionary file and edit it for this attribute. If I recall correctly you should be able to specify a dictionary when writing.
Iain Pierce
am 19 Jun. 2023
Antworten (0)
Kategorien
Mehr zu Read and Write Image Data from Files finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!