save image with plotings
1 view (last 30 days)
Show older comments
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,
0 Comments
Answers (2)
Azzi Abdelmalek
on 18 Oct 2012
set(gcf, 'PaperUnits', 'points','PaperPosition', [0 0 768 1024]);
saveas(gcf,'fig1.jpg')
3 Comments
Image Analyst
on 18 Oct 2012
Edited: Image Analyst
on 19 Oct 2012
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));
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!