Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Turn a MATLAB plot into image

I have generated a plot like

figure; hold;
axis([0 10 0 10]);
fill([ 1 1 5 5], [5 1 1 5],'b')

and now I want to have this plot as an matrix so that I can i.e. filter the blog with a gaussian. Googleing I found this thread Rasterizing Plot to Image at MATLAB Central. I tried it, but I could only get it to work for line or function plots.

Do you have any ideas?

like image 507
Framester Avatar asked Dec 16 '09 16:12

Framester


People also ask

Can you save a MATLAB plot as a JPEG image?

Save Plots InteractivelyThe export button supports three image formats (PNG, JPEG, and TIFF), as well as PDF files, which can contain images or vector graphics, depending on the content in the axes.

How do I convert a matrix to an image in MATLAB?

I = mat2gray( A , [amin amax] ) converts the matrix A to a grayscale image I that contains values in the range 0 (black) to 1 (white). amin and amax are the values in A that correspond to 0 and 1 in I . Values less than amin are clipped to 0, and values greater than amax are clipped to 1.

How do I export a figure in MATLAB?

Use the File > Export Setup dialog. Use Edit > Copy Figure to copy the figure's content to the system clipboard. For details, see Customize Figure Before Saving and Copy Figure to Clipboard from Edit Menu.


1 Answers

You can use GETFRAME function. It returns movie frame structure, which is actually rasterized figure. Field cdata will contain your matrix.

F=getframe;
figure(2)
imagesc(F.cdata);
like image 79
yuk Avatar answered Sep 24 '22 04:09

yuk