How to copy the Dicom private tags in another Dicom file using the dicomwrite function accurately?
Show older comments
Hi, I need to copy the Dicom info from one file to another. The Dicom file I have consists of many private tags and I want to copy them to the another file that I am writing using the MATLAB dicomwrite function.
info = dicominfo('ABCD.1.img'); % it has may private tags
fileID1 = fopen('data.s', 'r');
data1 = fread(fileID1); % I am writing this as a dicom file
fclose(fileID1);
dicomwrite(data1, 'new_image.img', info, 'CreateMode', 'Copy','WritePrivate', true);
metadata = dicominfo('new_image.img');
isequal(info, metadata) % .....> returns logical 0.
When I do this, all the private tags becomes uint8 and [0;0;0;0]...... format (some nonsense values). How can I copy the info accurately?
7 Comments
Rik
on 23 Feb 2021
Since those private tags are not in the dicom dictionary Matlab is using, it will assume your data is uint8 to preserve everything, as that will read and write your data as bytes.
Did you attempt to unwind the structs to find which exact fields are different? I believe there is a submission on the FEX that can do that for you.
blues
on 23 Feb 2021
blues
on 23 Feb 2021
Although you could create a dicom dictionary for Matlab to use, that might not be necessary.
I don't have a link to the submission I mentioned, so you will have to do the same thing I would need to do: do a Google search. I believe the submission was able to merge structs as well, so you could also try that in your search terms. (and yes, I meant the file exchange)
As a last note: if you want a dictionary to extend with your own entries, here is the 2011 dictionary I adapted to be compatible with Matlab. I'm working on a dicom reader, but it is fairly low priority, resulting in the dictionary being ready 3 years ago, and the reader not being ready to publish yet.
If you're looking for the meaning of VR and VM: they stand for value representation and value multiplicity. VR is a shorthand for the data type and VM describes the number of bytes a tag can span (if I recall correctly). You should look up the NEMA document I mention in the comments of the dictionary file I linked. I know dicom can be very confusing and information about it can be unstructured and scattered. That's what you get if you start using something from the mid-80s.
In addition to dicom being old, not every dicom file will be compliant. One of the main reasons my dicom reader has been delayed is because it has trouble dealing with improper files. Ironically that is what makes it so much faster than the built-in Matlab tools.
blues
on 24 Feb 2021
Ken K
on 4 Jun 2021
I am facing the same problem. Can you elaborate on your statement about appending the dicom dictionary? How did you manage to write the private tags such that they are not in uint8? Would you mind sharing the script for this?
Cheers
Rik
on 4 Jun 2021
The private tags are private, so there isn't a general definition. The definition might be standard for your specific field/application. Once you know what a specific tag means, you can define the VR and VM. The VR will ensure the data is read in the correct data type.
Doing custom work with DICOM is not trivial. Know what you're getting yourself into. There will be a lot of googling involved and a lot of conflicting information.
Answers (0)
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!