필터 지우기
필터 지우기

Write compared images not figures?!

조회 수: 4 (최근 30일)
Steven
Steven 2013년 12월 13일
편집: Steven 2013년 12월 13일
Hi. How can I write as images not figures?
I mean imagine I have image1, processed it and now it is image2. Now I want to show both of them in the same figure (or image). I use subplot or imshowpair to do so, but the problem is here:
If I want to save this final compared image, I have to use printf or saveas which both only save as JPEG and also changes the image size and info. What I want is saving it as an image (like the original ones.) I cannot use imwrite now! it gives empty figure!
Can anybody help me? Thanks so much! Steven

채택된 답변

Walter Roberson
Walter Roberson 2013년 12월 13일
You can specify the format in saveas(); see http://www.mathworks.com/help/matlab/ref/saveas.html
saveas(FigureNumber, 'Filename.bmp', 'bmp')
for example.
You can print() to a graphics file; see the list in http://www.mathworks.com/help/matlab/ref/print.html . For JPEG, TIFF and PNG, you can also use the -r flag to specify the resolution. For example,
print(FigureNumber, '-dpng', 'Filename.png', '-r0')
Also search down in the documentation for the section "Printing Figures at Screen Size"
In order to imwrite() you need a single data matrix to write. You could construct that matrix by using, for example,
[firstImage, SecondImage]
or
[h, w, p] = size(firstImage);
if isdouble(firstImage)
fillval = 1;
else
fillval = 255;
end
spacer = ones(h, 50, p) * fillval; %a buffer of 50 pixels whitespace between the two
NewMatrix = [firstImage, spacer, SecondImage];
imwrite(NewMatrix, 'filename.png', 'png');
  댓글 수: 1
Steven
Steven 2013년 12월 13일
편집: Steven 2013년 12월 13일
Thanks! Could you please answer my next question below? Thanks!

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

추가 답변 (1개)

Steven
Steven 2013년 12월 13일
편집: Steven 2013년 12월 13일
Thanks Walter! Clever idea!
That is great! May I ask:
  1. I do not understand the use o if condition? what does this isdouble do?
  2. If my images are all binary, shall I still use it?
  3. For me, MATLAB gives an error and says
Undefined function 'isdouble' for input arguments of type 'logical'.
what shall I do so?
Shall I always say use fillval=1 or fillval=255?
Thanks do mush again.
Steven
  댓글 수: 2
Walter Roberson
Walter Roberson 2013년 12월 13일
If your data is "logical" then the code can be simplified to
%a buffer of 50 pixels whitespace between the two
NewMatrix = [firstImage, true(size(firstImage,1), 50), SecondImage];
imwrite(NewMatrix, 'filename.png', 'png');
The code I had before should have used
if ~isinteger(firstImage)
fillval = 1;
else
fillval = 255;
end
This code is a bit of a simplification, but reflects the fact that for images that are of datatype single() or double() or logical(), the maximum ("brightest") value is 1, but for uint8 images, the maximum is 255. It is incomplete because it does not bother with uint16, which would use 65535.
Note: if you want the border between them to be dark instead of bright, use 0 as the fillval .
Steven
Steven 2013년 12월 13일
Thanks so much!

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

카테고리

Help CenterFile Exchange에서 Convert Image Type에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by