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)

 채택된 답변

Walter Roberson
Walter Roberson 2014년 1월 31일

1 개 추천

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

sir when i did so i got the below error
??? Error using ==> writebmp at 16
Class of X must be logical, uint8, single, or double.
Error in ==> imwrite at 431
feval(fmt_s.write, data, map, filename, paramPairs{:});
Error in ==> Demo at 10
imwrite(scaledimage, 'filename.bmp');
so i edited the line to
scaledimage = uint8((newimage - minimage) ./ (maximage - minimage));
but that time when i write i get a fully black image and nothing else....
how to correct the above error....
Image Analyst
Image Analyst 2014년 1월 31일
Try casting everything to double to do the math, then cast back to uint8 inside the call to imwrite().
Elysi Cochin
Elysi Cochin 2014년 1월 31일
now it worked... thank you Walter Roberson and Image Analyst for your help....
Syed Mobashir
Syed Mobashir 2015년 3월 12일
i am also getting the same black image. can you tell me this code? plzzz i need this urgent

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Creating, Deleting, and Querying Graphics Objects에 대해 자세히 알아보기

질문:

2014년 1월 31일

댓글:

2015년 3월 12일

Community Treasure Hunt

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

Start Hunting!

Translated by