将MATLAB图转换为图像

时间:2009-12-16 16:33:53

标签: matlab filtering plot rasterizing

我已经生成了一个类似

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

现在我希望将这个图作为一个矩阵,以便我可以用高斯过滤博客。谷歌我在MATLAB Central找到了这个帖子Rasterizing Plot to Image。我试过了,但我只能让它适用于线条或功能图。

你有什么想法吗?

2 个答案:

答案 0 :(得分:8)

您可以使用GETFRAME功能。它返回电影帧结构,实际上是栅格化图形。 Field cdata将包含您的矩阵。

F=getframe;
figure(2)
imagesc(F.cdata);

答案 1 :(得分:0)

目标矩阵的期望特征是什么?你想要什么样的图像光栅化?

你知道,对于你给我们的唯一例子,定义代表你图像的矩阵几乎是微不足道的......

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

你的矩阵是一个开始的光栅。现在,您可以使用内置函数图像来显示矩阵。看一下该功能的文档。请注意,我的建议不符合使用image()和colormap()的规范。