将 MATLAB 绘图转换为图像

发布于 2024-08-15 05:58:27 字数 358 浏览 2 评论 0原文

我已经生成了一个像这样的图

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

,现在我想将此图作为矩阵,以便我可以用高斯过滤博客。通过 Google 搜索,我在 MATLAB Central 找到了此线程 Rasterizing Plot to 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

最初的梦 2024-08-22 05:58:27

您可以使用 GETFRAME 函数。它返回电影帧结构,实际上是光栅化的图形。字段 cdata 将包含您的矩阵。

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

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);
舟遥客 2024-08-22 05:58:27

您的目标矩阵需要哪些特征?您想要栅格化什么样的图像?

您看,对于您给我们的唯一示例,定义表示图像的矩阵几乎是微不足道的......

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 来可视化您的矩阵。查看该函数的文档。请注意,我的建议不符合与 image() 和 colormap() 一起使用的规范。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文