ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sun, 10 Nov 2013 22:13:39 +0100Image processinghttps://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 14:39:31 +0100https://ask.sagemath.org/question/9911/image-processing/Answer 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>
https://ask.sagemath.org/question/9911/image-processing/?answer=14916#post-id-14916remove spamMon, 13 May 2013 01:59:15 +0200https://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>
https://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 15:00:00 +0100https://ask.sagemath.org/question/9911/image-processing/?answer=14651#post-id-14651Answer 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>
https://ask.sagemath.org/question/9911/image-processing/?answer=15685#post-id-15685remove spamSun, 10 Nov 2013 22:13:39 +0100https://ask.sagemath.org/question/9911/image-processing/?answer=15685#post-id-15685Answer 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>
https://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 15:59:08 +0100https://ask.sagemath.org/question/9911/image-processing/?answer=14652#post-id-14652Comment 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>
https://ask.sagemath.org/question/9911/image-processing/?comment=18059#post-id-18059Thank you so much!!!Fri, 15 Mar 2013 18:05:06 +0100https://ask.sagemath.org/question/9911/image-processing/?comment=18059#post-id-18059Comment 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>
https://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 08:42:59 +0100https://ask.sagemath.org/question/9911/image-processing/?comment=18066#post-id-18066