Reputation: 48966
I have a dicom
image which I read in matlab
as:
I=dicomread('xyz.dcm');
In displaying it, I used the following command:
imshow(I,[])
What I want to ask about is, how can I write it through imwrite
, such that I get the image as seen using the above imshow
command?
I for instance tried this:
imwrite(I,'xyz.png','png');
but, get a dark image.
Any ideas on that?
Thanks.
Upvotes: 2
Views: 2924
Reputation: 71
Hey I had the same problem and it seems that one of the solutions is very simple. Just check whether you are passing a string as filenames for the destination file.
I was passing the output of the fullfile function (this one outputs a cell). What happens it that imwrite function parces the inputs (vargins) and looks for the first variable with char type. It uses this index to find the argument that specifies the datatype and consequently define the colormap. If your file path is a cell, it will get the wrong index and output strange errors.
I hope this helps
Upvotes: 1
Reputation: 114926
It seems like dicom image has a 16-bit depth, which is larger than the usual 8-bit.
To verify that this is indeed the case type
>> class( I )
I would expect the output to be uint16
.
If so, try:
imwrite( I, 'xyz.png', 'bitdepth', 16 );
Upvotes: 2
Reputation: 3461
When you read the image, get the colormap as well
[I, map]=dicomread('xyz.dcm');
Now when you save it, give imwrite the colormap also.
imwrite(I,map,'xyz.png','png');
And by the way, the last png isn't necessary usually. MATLAB will see the .png extension and know to save it as a png.
Upvotes: 1