开发者

Turn a MATLAB plot into image

开发者 https://www.devze.com 2022-12-14 00:37 出处:网络
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. Goo

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 开发者_StackOverflowto 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?


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


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().

0

精彩评论

暂无评论...
验证码 换一张
取 消