user1707621
user1707621

Reputation: 95

matlab render graphical objects to a bitmap in memory

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.

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)

Thanks

Upvotes: 0

Views: 100

Answers (1)

user1707621
user1707621

Reputation: 95

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

Upvotes: 1

Related Questions