Save exact image output from imagesc in matlab

时光总嘲笑我的痴心妄想 提交于 2019-11-30 07:21:46

To save the figure as a file (don't matter how it was created), one should do:

saveas(figureHandle,'filename','format')

where figureHandle could be the gcf handle, which means: get current figure.

As pointed in the discussion, if someone doesn't want the ticks to be shown, the person can add:

set(gca,'XTick',[])
set(gca,'YTick',[])

where gca is the handle to the current axis, just as gcf. If you have more than one axis, don't forget to "handle the handles". They are returned to you when you create them, i.e.:

hFig = figure(pairValuedProperties); % Create and get the figure handle
hAxes1 = suplot(2,1,1,pairValuedProperties); % Create and get the upper axes handle
hAxes2 = suplot(2,1,2,pairValuedProperties); % Create and get the bottom axes handle

where the pair value are the figure or axes properties declared in the following syntax:

'PropertyName1',PropertyValue1,'PropertyName2',PropertyValue2,…

Here are the matlab documentation about the Figure and Axes Properties, and about the saveas method.


Example:

The image saved with the following code:

figure 
imagesc(magic(3))
set(gca,'XTick',[]) % Remove the ticks in the x axis!
set(gca,'YTick',[]) % Remove the ticks in the y axis
set(gca,'Position',[0 0 1 1]) % Make the axes occupy the hole figure
saveas(gcf,'Figure','png')

You can use:

print -djpeg99 'foo.jpg'

This will save it as 'foo.jpg' as you need.

You can use the following code

 imagesc(A);
 %%saving the image
 hgexport(gcf, 'figure1.jpg', hgexport('factorystyle'), 'Format', 'jpeg');
 set(gcf,'PaperUnits','inches','PaperPosition',[0 0 4 4]);
 print -djpeg filename.jpg -r10

Here A will be the matrix from which you will have an image. And the image will be saved as filename.jpg in the directory.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!