matlab将图形对象渲染到内存中的位图 [英] matlab render graphical objects to a bitmap in memory

查看:124
本文介绍了matlab将图形对象渲染到内存中的位图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这应该是非常简单的我认为但我无法正确...

This is supposed to be very simple I think but I can't get it right...

我在图中绘制了几个图形对象,现在我想要图中的位图,用于维护对象上的位置和图形的尺寸。

I plot several graphical objects in a figure and now I want a bitmap of the figure, that maintains the position on the objects and the dimensions of the figure.

举一个非常简单的例子,如果我在坐标中绘制2个点( 0,0)和(200,200)我希望渲染输出一个大小为(200,200)的矩阵,其中像素(0,0)和(200,200)的灰度级为255,其余像素为零(这是每像素8位灰度的情况虽然3我更喜欢颜色位图,它将反映对象的颜色,如原始图中所示)

To give a very simple example, if I plot 2 points in coordinates (0,0) and (200,200) I expect the rendering to output a matrix of size (200,200) where pixels (0,0) and (200,200) have a gray level of 255 and the rest of the pixels are zeroed (this is in case of a 8-bit per pixel grayscale though 3I prefer a color bitmap that will reflect the colors of the objects as appear in the original figure)

谢谢

推荐答案

为了回答我自己的问题,这就是我用图形对象将图形渲染到内存中的位图并保持比例的方法:我使用 getFrame ,然后将结果调整为轴的大小。这里是:

To answer my own question, this is what I did to render a figure with graphical objects to a bitmap in memory and keep it in scale: I used getFrame and then resized the result to the size of the axes. Here goes:

% plot stuff on the current axes, then...

set(gca, 'ydir', 'reverse');
xLim = get(gca, 'XLim');
yLim = get(gca, 'YLim');
rendered = getframe(gca);
imageMat = imresize(rendered.cdata, [floor(yLim(2)), floor(xLim(2))]);

此处图像被采样两次,这在处理时间方面效率低,并且图像质量稍差。为了我的目的,它还可以,但单样本解决方案仍然很好......

Here the image is sampled twice which is both inefficient in terms of processing time and gives a somewhat degraded image. For my purposes it's ok but still a single-sample solution would be nice...

这篇关于matlab将图形对象渲染到内存中的位图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆