MATLAB Answers

0

write (save) an image file

Asked by Elysi Cochin on 31 Jan 2014
Latest activity Commented on by Syed Mobashir
on 12 Mar 2015

i had a .mha file, i used the below two lines to display the image and i get the first full image as in the link below....

 V = mha_read_volume('BRATS_HG0001_truth.mha');
 imshow(squeeze(V(:,:,round(end/2))),[]);

please can someone help me how to save that image to a jpg or bmp or tiff file....

i tried

 imwrite(squeeze(V(:,:,round(end/2))),'filename.bmp')

but i'm not getting the image... i get the outline of the image as shown in link (image(b))... what should i do to save as image(a)

http://imageshack.com/a/img838/8308/yc91.png

  0 Comments

Products

No products are associated with this question.

1 Answer

Answer by Walter Roberson
on 31 Jan 2014
 Accepted answer

Notice that when you call imshow you are providing the [] second parameter. That tells imshow() to effectively shift and scale the data so that it runs between 0 and 1. You can do the same tranformation:

newimage = squeeze(V(:,:,round(end/2)));
minimage = min(newimage(:));
maximage = max(newimage(:));
scaledimage = (newimage - minimage) ./ (maximage - minimage);
imwrite(scaledimage, 'filename.bmp');

  4 Comments

Try casting everything to double to do the math, then cast back to uint8 inside the call to imwrite().

now it worked... thank you Walter Roberson and Image Analyst for your help....

i am also getting the same black image. can you tell me this code? plzzz i need this urgent


Join the 15-year community celebration.

Play games and win prizes!

Learn more
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!