Dicom Header Editing & Image Intensity Scaling for output

I'm reading in a dicom image that is missing a few fields in the header information and I would like to add those fields and output the image data untouched as a dicom with the new header information. I have looked at the dicom-dict.txt file to ensure that I have the right fieldnames, but when I write out the dicom, it doesn't keep the original header information. Also, when I go to display the image, the LUT appears to be inverted or cutoff (rather than having -2048 - + 2048 scaling, it has 0 - 4096 scaling).
Greatly appreciate your help in Advance ... Cheers

3 Comments

Can you copy the code you're using?
Have you seen the DICOMWRITE examples?
Code Posted ... I have looked at the examples, but maybe I'm missing something.

Sign in to comment.

Answers (3)

here is the bit of code i'm using:
x = dicomread('Test_Image');
xinfo = dicominfo('Test_Image');
xinfo.PatientID = '123456';
xout = dicomwrite(x,'Test_Image','gray',xinfo);
I have tried copying the header to a new variable and editing the new one with out any success. I have also messed around with the 'CreateMode' option and still no results.
I just need to be able to add the 'PatientID' field to the header and write out the dicom image untouched.
thanks

1 Comment

Why are you calling it with 'gray'? I don't see this in the documentation.

Sign in to comment.

X = dicomread('CT-MONO2-16-ankle.dcm');
metadata = dicominfo('CT-MONO2-16-ankle.dcm');
metadata.PatientID = '12343';
dicomwrite(X, 'ct_file.dcm', metadata);
info = dicominfo('ct_file.dcm');
info.PatientID
Unable to replicate.

2 Comments

I've tried that as well and I get a series of errors:
Error using dicom_prep_metadata (line 97)
Unsupported SOP class (1.2.840.10008.5.1.4.1.1.1) in full verification mode.
Consider using 'CreateMode' with a value of 'Copy'.
Type help dicomwrite for more details.
Error in dicom_create_IOD (line 27)
metadata = dicom_prep_metadata(IOD_UID, metadata, X, map, options.txfr, dictionary);
Error in dicomwrite>write_message (line 263)
[attrs, status] = dicom_create_IOD(SOP_UID, X, map, ...
Error in dicomwrite (line 200)
[status, options] = write_message(X, filename, map, metadata, options);
Let me rephrase that ... You're example, which I have tried works fine. But when I substitute my image, those are the errors I get.

Sign in to comment.

I think I have figured out the header editing part by using the following command on output:
xout = dicomwrite(x,'Test_Image.dcm',xinfo,'CreateMode','Copy');
But the image intensity remains the inverse of the original image. Any ideas?

1 Comment

I think the output of dicomwrite gives you an image with uint16 values (unsigned 16 bit integers) so it can't display negative values as you seem to have -2048 - + 2048 scaling

Sign in to comment.

Categories

Asked:

AFH
on 27 Jan 2012

Commented:

on 11 Apr 2016

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!