5

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?

Matthew Simoneau
  • 6,199
  • 6
  • 35
  • 46
Framester
  • 33,341
  • 51
  • 130
  • 192
  • I know, I made the example too simple / trivial. But with the answer I marked, one can rasterize even arbitrary plots easily. – Framester Dec 17 '09 at 09:00

2 Answers2

8

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);
yuk
  • 19,098
  • 13
  • 68
  • 99
0

What are the desired characteristics of your target matrix ? And what sort of images do you want to rasterise ?

You see, for the only example you have given us it's almost trivial to define a matrix representing your image ...

1. figmat = ones(10,10,3) % create a 10x10 raster where each entry is a triple for RGB, setting them all to 1 colours the whole raster white
2. figmat(2:5,2:5,1:2) = 0 % sets RG components in the coloured area to 0, leaving only blue

Your matrix is a raster to start with. Now, you can use the built-in function image to visualise your matrix. Have a look at the documentation for that function. And note that my suggestion does not meet the spec for use with image() and colormap().

user229044
  • 232,980
  • 40
  • 330
  • 338
High Performance Mark
  • 77,191
  • 7
  • 105
  • 161