John Hunter wrote:
> Perhaps we should make this a friendly helper method of the agg backend
> canvas -- canvas.toarray() returns an rgba numpy array via
> canvas.buffer_rgba?
+1
-Chris
--
Christopher Barker, Ph.D.
Oceanographer
Emergency Response Division
NOAA/NOS/OR&R(206) 52
On Tue, Mar 24, 2009 at 10:46 AM, Jae-Joon Lee wrote:
> canvas = gcf().canvas
> buf = canvas.tostring_rgb()
>
> img = numpy.fromstring(buf, numpy.uint8)
> im_size = canvas.get_width_height()
> rgb = img.reshape(im_size[1], im_size[0], 3)
> r, g, b = rgb[:,:,0], rgb[:,:,1], rgb[:,:,2]
>
Perhaps
canvas = gcf().canvas
buf = canvas.tostring_rgb()
img = numpy.fromstring(buf, numpy.uint8)
im_size = canvas.get_width_height()
rgb = img.reshape(im_size[1], im_size[0], 3)
r, g, b = rgb[:,:,0], rgb[:,:,1], rgb[:,:,2]
Or if you're using PIL,
pil_image = PIL.Image.fromstring("RGB", im_size, buf)
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1
Hi,
I want to convert the current figure to a numpy array w/o saving the
image to disk. I need this to convert a matlab function to python, the
original code is:
F = getframe(gcf);
X = frame2im(F);
My current workaround is
h = gcf()
h.savefig('tmp.pn