How can I specify the size of image I want to save?
1 次查看(过去 30 天)
显示 更早的评论
Hi I am trying to save the image of my axes with this code :
F = getframe(handles.axes3);
image=frame2im(F);
imwrite(image, fullfile(add,name));
But my result image size is difference from original image! How can I save it in it's original size?
0 个评论
回答(1 个)
Image Analyst
2014-12-28
编辑:Image Analyst
2014-12-28
Use getimage() instead of getframe(). getimage() gets the actual image wheras getframe gets more like a screenshot of the image as it's displayed, which can be a different size and have graphics/annotation on it. Here's a demo:
grayImage = imread('concordorthophoto.png');
imshow(grayImage);
[rows, columns, numberOfColorChannels] = size(grayImage)
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
% Extract the image back out
extractedImage = getimage(gca);
[rows2, columns2, numberOfColorChannels2] = size(extractedImage)
% Extract the frame
frameStructure = getframe(gca);
frameImage = frameStructure.cdata;
[rows3, columns3, numberOfColorChannels3] = size(frameImage)
In the command window is the proof:
Warning: Image is too big to fit on screen; displaying at 33%
> In initSize at 71
In imshow at 309
In test1 at 10
rows =
2215
columns =
2956
numberOfColorChannels =
1
rows2 =
2215
columns2 =
2956
numberOfColorChannels2 =
1
rows3 =
881
columns3 =
1627
numberOfColorChannels3 =
3
You see that getimage() is getting the full sized image even though the displayed image was shrunk down to fit on the display. And you can see that getframe() gets you the screenshot sized image.
Not only that, but getframe() converts a grayscale image into color in case it needs to capture color graphics/text/annotation that's displayed in the overlay. You might not want your image converted to color.
1 个评论
Image Analyst
2014-12-30
reza, did that answer your question? If so, mark it as Accepted. If not, let me know what's still confusing.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!