Ask Your Question

Image processing

asked 2013-03-14 14:39:31 +0200

beginner gravatar image

updated 2013-03-14 14:47:55 +0200

kcrisman gravatar image

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?

Thank you in advance

edit retag flag offensive close merge delete

4 Answers

Sort by ยป oldest newest most voted

answered 2013-03-14 15:00:00 +0200

kcrisman gravatar image

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.

edit flag offensive delete link more

answered 2013-05-13 01:59:15 +0200

updated 2013-11-10 22:18:22 +0200

ppurka gravatar image

remove spam

edit flag offensive delete link more

answered 2013-11-10 22:13:39 +0200

aclink gravatar image

updated 2013-11-10 22:18:04 +0200

ppurka gravatar image

remove spam

edit flag offensive delete link more

answered 2013-03-14 15:59:08 +0200

beginner gravatar image

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?

Thank you in advance!

edit flag offensive delete link more


I suggest looking at 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).

kcrisman gravatar imagekcrisman ( 2013-03-15 08:42:59 +0200 )edit

Thank you so much!!!

beginner gravatar imagebeginner ( 2013-03-15 18:05:06 +0200 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2013-03-14 14:39:31 +0200

Seen: 2,036 times

Last updated: Nov 10 '13