ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sun, 10 Nov 2013 15:13:39 -0600Image processinghttp://ask.sagemath.org/question/9911/image-processing/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
Thu, 14 Mar 2013 08:39:31 -0500http://ask.sagemath.org/question/9911/image-processing/Answer by beginner for <p>Dear all,
I have question about manipulating image in Sage. Here is some example.</p>
<pre><code>import pylab
img=pylab.imread(DATA+'lena.png')
</code></pre>
<p>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.</p>
<p>Is there some simple way to do this? </p>
<p>Thank you in advance</p>
http://ask.sagemath.org/question/9911/image-processing/?answer=14652#post-id-14652Thank 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!Thu, 14 Mar 2013 09:59:08 -0500http://ask.sagemath.org/question/9911/image-processing/?answer=14652#post-id-14652Comment by kcrisman for <p>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:</p>
<p>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".</p>
<p>My image is color image so it's 3D. How I can easy convert to 2D?</p>
<p>Thank you in advance!</p>
http://ask.sagemath.org/question/9911/image-processing/?comment=18066#post-id-18066I 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).Fri, 15 Mar 2013 02:42:59 -0500http://ask.sagemath.org/question/9911/image-processing/?comment=18066#post-id-18066Comment by beginner for <p>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:</p>
<p>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".</p>
<p>My image is color image so it's 3D. How I can easy convert to 2D?</p>
<p>Thank you in advance!</p>
http://ask.sagemath.org/question/9911/image-processing/?comment=18059#post-id-18059Thank you so much!!!Fri, 15 Mar 2013 12:05:06 -0500http://ask.sagemath.org/question/9911/image-processing/?comment=18059#post-id-18059Answer by aclink for <p>Dear all,
I have question about manipulating image in Sage. Here is some example.</p>
<pre><code>import pylab
img=pylab.imread(DATA+'lena.png')
</code></pre>
<p>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.</p>
<p>Is there some simple way to do this? </p>
<p>Thank you in advance</p>
http://ask.sagemath.org/question/9911/image-processing/?answer=15685#post-id-15685remove spamSun, 10 Nov 2013 15:13:39 -0600http://ask.sagemath.org/question/9911/image-processing/?answer=15685#post-id-15685Answer by jacaboo for <p>Dear all,
I have question about manipulating image in Sage. Here is some example.</p>
<pre><code>import pylab
img=pylab.imread(DATA+'lena.png')
</code></pre>
<p>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.</p>
<p>Is there some simple way to do this? </p>
<p>Thank you in advance</p>
http://ask.sagemath.org/question/9911/image-processing/?answer=15344#post-id-15344remove the spam.Tue, 20 Aug 2013 21:20:33 -0500http://ask.sagemath.org/question/9911/image-processing/?answer=15344#post-id-15344Answer by arronlee for <p>Dear all,
I have question about manipulating image in Sage. Here is some example.</p>
<pre><code>import pylab
img=pylab.imread(DATA+'lena.png')
</code></pre>
<p>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.</p>
<p>Is there some simple way to do this? </p>
<p>Thank you in advance</p>
http://ask.sagemath.org/question/9911/image-processing/?answer=15133#post-id-15133remove spamMon, 24 Jun 2013 17:27:14 -0500http://ask.sagemath.org/question/9911/image-processing/?answer=15133#post-id-15133Answer by blueimage for <p>Dear all,
I have question about manipulating image in Sage. Here is some example.</p>
<pre><code>import pylab
img=pylab.imread(DATA+'lena.png')
</code></pre>
<p>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.</p>
<p>Is there some simple way to do this? </p>
<p>Thank you in advance</p>
http://ask.sagemath.org/question/9911/image-processing/?answer=14916#post-id-14916remove spamSun, 12 May 2013 18:59:15 -0500http://ask.sagemath.org/question/9911/image-processing/?answer=14916#post-id-14916Answer by kcrisman for <p>Dear all,
I have question about manipulating image in Sage. Here is some example.</p>
<pre><code>import pylab
img=pylab.imread(DATA+'lena.png')
</code></pre>
<p>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.</p>
<p>Is there some simple way to do this? </p>
<p>Thank you in advance</p>
http://ask.sagemath.org/question/9911/image-processing/?answer=14651#post-id-14651I'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.Thu, 14 Mar 2013 09:00:00 -0500http://ask.sagemath.org/question/9911/image-processing/?answer=14651#post-id-14651