# Image processing

Dear all, I have question about manipulating image in Sage. Here is some example.

import pylab


Img is now array with float elements. But I want to add some shapes on this image like circle, rectangle, polygon etc, but c=Circle, b=Rectangle and a=Polygon are object of some clases so if I want to do something like this show(img+c) or show(img+b) it is not allowed. Another question is: How I can put circle on my position (position is corner of image) because Img is array so I don't know where new row start.

Is there some simple way to do this?

edit retag close merge delete

Sort by ยป oldest newest most voted

remove spam

more

remove spam

more

Thank you this example works, but what about if my image is not Lena.png (I put that like example). If I put something like this:

I=misc.imread(DATA+'myexample.png') and put the rest of Your code I got "TypeError: mat must be a Matrix or a two dimensional array".

My image is color image so it's 3D. How I can easy convert to 2D?

more

I suggest looking at http://matplotlib.org/users/image_tutorial.html In principle it shouldn't matter that it's color, as long as you use the right syntax (I note you have scipy.misc.imread, not pylab.imread).

( 2013-03-15 02:42:59 -0500 )edit

Thank you so much!!!

( 2013-03-15 12:05:06 -0500 )edit

I'd suggest using matrix_plot.

sage: import pylab
sage: from scipy import misc
sage: I = misc.lena()
sage: (matrix_plot(I)+circle((5,3),100)).show(ymax=500)


If you try this, you'll see that there are a couple bugs (?) that this unveils in how we compute limits; apparently no one has ever wanted to put a circle on an image before!

It's also possible to export images as matplotlib objects.

sage: C = circle((5,3),100)
sage: C.matplotlib()
sage: pylab.imshow(misc.lena())
<matplotlib.image.AxesImage at 0x1121f0310>


But someone else will have to answer how to combine those in native matplotlib, though it certainly isn't hard for anyone who uses mpl regularly.

more