Dicomread a File and Dicomwrite it results in different outputs...

I have a very weird problem.
I open a DicomFile and save it without changing a thing, but when I look at the dcm in synedra view, they are different.
The original files goes from -4096 to 4096 but the save file only from 0 to 4096. I then tried to stretch the file by myself i.o.:
x = (2.*x-4096);
But this was also not working, dicomwrite cuts the values below 0...
dinfo = dicominfo('testDicom.dcm');
x = dicomread(dinfo);
dicomwrite(x, 'testDicom2.dcm', dinfo)
Any ideas?
Best Ingo

6 Comments

The PixelData field generally stores positive integers, which are then modified with the RescaleSlope and RescaleIntercept fields to cover the entire range. When reading the file Matlab doens't apply this transformation and will keep the data in a uint16 format. That is probably the direction to investigate.
Did you convert to double before rescaling?
Hey Rik,
Thank you for your response and yes, it is in double. In Matlab, the images look as they should look but after converting they changed.
AFter using dicomwrite, I have loaded again the dicoms and in the header the RescaleSlope and RescaleIntercept are missing. Is there a way to write these fields to the dicom ?
When I convert it into double, i have to additionally divide the image by 256^2 otherwise the values are in range of 0 - 65500.
Best Ingo
Strange. If the fields are in dinfo they should be written normally.
Matlab doesn't have a great track record for writing dicom. Reading dicom is fine, if a bit on the slow side due to all the error mitigation.
Yes, so I do this:
dinfo = dicominfo('testDicom.dcm');
dinfo.RescaleIntercept
dinfo.RescaleSlope
x = dicomread(dinfo);
y = 2.*double(x)-4096;
dicomwrite(uint16(y), 'testDicom2.dcm', dinfo)
-4096
2
Then I do this:
dinfo = dicominfo('testDicom2.dcm');
dinfo.RescaleIntercept
dinfo.RescaleSlope
Reference to non-existent field 'RescaleIntercept'.
Okay, I solved the problem!
If I would have read the manual carefully I have to use the option ( 'CreateMode', 'copy' ):
dicomwrite(x, 'testDicom2.dcm', dinfo 'CreateMode', 'copy');
Thanks for your help again and best wishes
Ingo
Please post the solution as an answer and accept it. That way people with a similar problem can more easily find the solution.

Sign in to comment.

 Accepted Answer

Okay, I solved the problem!
If I would have read the manual carefully I have to use the option ( 'CreateMode', 'copy' ):
dicomwrite(x, 'testDicom2.dcm', dinfo 'CreateMode', 'copy');
Thanks for your help again and best wishes
Ingo

More Answers (0)

Categories

Find more on Convert Image Type in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!