Ask Your Question
0

Image processing

asked 12 years ago

beginner gravatar image

updated 12 years ago

kcrisman gravatar image

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

import pylab
img=pylab.imread(DATA+'lena.png')

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

Preview: (hide)

4 Answers

Sort by » oldest newest most voted
1

answered 12 years ago

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.

Preview: (hide)
link
0

answered 11 years ago

updated 11 years ago

ppurka gravatar image

remove spam

Preview: (hide)
link
0

answered 11 years ago

aclink gravatar image

updated 11 years ago

ppurka gravatar image

remove spam

Preview: (hide)
link
0

answered 12 years ago

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!

Preview: (hide)
link

Comments

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

kcrisman gravatar imagekcrisman ( 12 years ago )

Thank you so much!!!

beginner gravatar imagebeginner ( 12 years ago )

Your Answer

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

Add Answer

Question Tools

Stats

Asked: 12 years ago

Seen: 2,638 times

Last updated: Nov 10 '13