Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Save exact image output from imagesc in matlab

Rainbow

Hi , I want to save this image produced from imagesc(magic(3)), the exact rainbow representation, is it possible?

Thanks.

This question might look like a duplicate , but it is not . I looked at the solution to the similar question at this site , but it did not satisfy me . I have looked into the Matlab help center and the close answer that I got was this one , at the bottom of http://goo.gl/p907wR

like image 389
motiur Avatar asked Aug 16 '13 04:08

motiur


3 Answers

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')

Figure without the white border

like image 162
Werner Avatar answered Oct 17 '22 16:10

Werner


You can use:

print -djpeg99 'foo.jpg'

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

like image 29
ntg Avatar answered Oct 17 '22 16:10

ntg


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.

like image 30
Abirami Anbalagan Avatar answered Oct 17 '22 18:10

Abirami Anbalagan