save image with plotings

조회 수: 1 (최근 30일)
Yanqin
Yanqin 2012년 10월 18일
Dear Sir/Madam,
How could I save an image with plotting labels on it and keep the same size of the image?
For example, the image size wiht labels:1024x768, once I save it by using "saveas" or "print", the saved image size becomes:1200x900.
What cause the change of the image size?
Best regards,

답변 (2개)

Azzi Abdelmalek
Azzi Abdelmalek 2012년 10월 18일
set(gcf, 'PaperUnits', 'points','PaperPosition', [0 0 768 1024]);
saveas(gcf,'fig1.jpg')
  댓글 수: 3
Azzi Abdelmalek
Azzi Abdelmalek 2012년 10월 19일
how did you check the size
Image Analyst
Image Analyst 2012년 10월 19일
I imagine he read the image back in with imread().

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


Image Analyst
Image Analyst 2012년 10월 18일
편집: Image Analyst 2012년 10월 19일
Use export_fig() as recommended in the FAQ: http://matlab.wikia.com/wiki/FAQ#How_do_I_save_my_figure.2C_axes.2C_or_image.3F_I.27m_having_trouble_with_the_built_in_MATLAB_functions. However, even export_fig apparently cannot guarantee exact final image sizes. But that doesn't really matter since anyplace where you are going to use it (MS Office apps, etc.) will let you resize it).
If you want to "burn" text into images, then use imtext() in the Computer Vision System Toolbox. Then you can save the image directly, instead of the figure, and you'll have the text and image in their original pixel sizes.
format compact;
close all;
plot(rand(10,1), 'bo-', 'LineWidth', 3);
grid on;
% set(gcf, 'PaperUnits', 'points','PaperPosition', [0 0 768 1024]);
filename = 'plot.png';
% Save image at whatever size MATLAB decided to make it.
export_fig(filename, '-native');
imageReadBackIn = imread(filename);
[rows columns numberOfColorChannels] = size(imageReadBackIn)
delete(filename);
message = sprintf('This image is %d rows by %d columns.\nNote the small sizes, and then\nclick OK to enlarge it.',...
rows, columns);
title(message);
uiwait(msgbox(message));
% Enlarge figure to full screen.
set(gcf, 'Units', 'Pixels','Menu', 'None');
width = 1000;
height = 800;
set(gcf, 'Position', [0 0 width height]);
% set(gcf, 'Units', 'Pixels', 'Position', [0 0 600 1000], 'Menu', 'None');
export_fig(filename, '-native');
imageReadBackIn = imread(filename);
[rows columns numberOfColorChannels] = size(imageReadBackIn)
% figure;
% imshow(imageReadBackIn);
% set(gcf, 'Units', 'Pixels','Menu', 'None');
delete(filename);
message = sprintf('Now, the image is %d rows by %d columns',...
rows, columns);
title(message);
uiwait(msgbox(message));
  댓글 수: 1
Yanqin
Yanqin 2012년 10월 24일
Thank you so much.
I tired your code, the size of image does change with the Width/Height settings. The key is how to choose the Width/Height in order to get the desired size, say 1024x768? Do you have any suggestion

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

카테고리

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