Discussion:
How to save greyscale image
NewPy
2013-06-13 05:22:01 UTC
Permalink
# read in a grey scale image, imsave convert it to color image
s_file='Nuts.png'
img = mahotas.imread(s_file, as_grey=True)
mahotas.imsave('test.png', img)
exit()

# example 2, instead of getting a black and white image, I got red and blue
strips
import numpy as np
import mahotas
img = np.ones([10,10])
img[::2,:]=0
mahotas.imsave('test.png', img)

Thanks!
--
You received this message because you are subscribed to the Google Groups "pythonvision" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pythonvision+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.
Luis Pedro Coelho
2013-06-13 09:48:57 UTC
Permalink
Hello,

Are you sure that you are not just seeing the grayscale/bw image using
the default matplotlib colorschemes, which are false colour schemes?

What does it look like if you open the image on gimp or another image
software?

HTH
Luis
Post by NewPy
# read in a grey scale image, imsave convert it to color image
s_file='Nuts.png'
img = mahotas.imread(s_file, as_grey=True)
mahotas.imsave('test.png', img)
exit()
# example 2, instead of getting a black and white image, I got red and
blue strips
import numpy as np
import mahotas
img = np.ones([10,10])
img[::2,:]=0
mahotas.imsave('test.png', img)
Thanks!
--
You received this message because you are subscribed to the Google
Groups "pythonvision" group.
To unsubscribe from this group and stop receiving emails from it, send
For more options, visit https://groups.google.com/groups/opt_out.
--
Luis Pedro Coelho | EMBL | http://luispedro.org
--
You received this message because you are subscribed to the Google Groups "pythonvision" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pythonvision+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.
NewPy
2013-06-15 04:57:32 UTC
Permalink
Attached are the input and output files for the script below. I checked
with GIMP, it's colored. Thanks

#!/usr/bin/env python
import mahotas
s_file='Nuts.png'
img = mahotas.imread(s_file, as_grey=True)
mahotas.imsave('Nuts_saved.png', img)
exit()
Post by NewPy
# read in a grey scale image, imsave convert it to color image
s_file='Nuts.png'
img = mahotas.imread(s_file, as_grey=True)
mahotas.imsave('test.png', img)
exit()
# example 2, instead of getting a black and white image, I got red and
blue strips
import numpy as np
import mahotas
img = np.ones([10,10])
img[::2,:]=0
mahotas.imsave('test.png', img)
Thanks!
--
You received this message because you are subscribed to the Google Groups "pythonvision" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pythonvision+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.
Luis Pedro Coelho
2013-06-15 13:21:40 UTC
Permalink
Ah, you're right!

This is actually matplotlib.pyplot.imsave's implementation.

Mahotas does not implement IO, it always just exposes one of

1. imread (http://luispedro.org/software/imread)
2. freeimage
3. matplotlib

(It tries these in order 'til it finds one that works).

*

I have just committed a fix so that the imsave for matplotlib at leasts
works around this and tells the user what's happening.

Thanks
Luis
Post by NewPy
Attached are the input and output files for the script below. I checked
with GIMP, it's colored. Thanks
#!/usr/bin/env python
import mahotas
s_file='Nuts.png'
img = mahotas.imread(s_file, as_grey=True)
mahotas.imsave('Nuts_saved.png', img)
exit()
# read in a grey scale image, imsave convert it to color image
s_file='Nuts.png'
img = mahotas.imread(s_file, as_grey=True)
mahotas.imsave('test.png', img)
exit()
# example 2, instead of getting a black and white image, I got red
and blue strips
import numpy as np
import mahotas
img = np.ones([10,10])
img[::2,:]=0
mahotas.imsave('test.png', img)
Thanks!
--
You received this message because you are subscribed to the Google
Groups "pythonvision" group.
To unsubscribe from this group and stop receiving emails from it, send
For more options, visit https://groups.google.com/groups/opt_out.
--
Luis Pedro Coelho | EMBL | http://luispedro.org
--
You received this message because you are subscribed to the Google Groups "pythonvision" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pythonvision+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.
Thouis (Ray) Jones
2013-06-15 15:14:17 UTC
Permalink
You might add cmap=matplotlib.cm.gray (and maybe vmin=0, vmax=1, if the
incoming image is within [0,1]) to the matplotlib.imsave call, to better
approximate what freeimage would do.

Ray Jones
Post by Luis Pedro Coelho
Ah, you're right!
This is actually matplotlib.pyplot.imsave's implementation.
Mahotas does not implement IO, it always just exposes one of
1. imread (http://luispedro.org/**software/imread<http://luispedro.org/software/imread>
)
2. freeimage
3. matplotlib
(It tries these in order 'til it finds one that works).
*
I have just committed a fix so that the imsave for matplotlib at leasts
works around this and tells the user what's happening.
Thanks
Luis
Post by NewPy
Attached are the input and output files for the script below. I checked
with GIMP, it's colored. Thanks
#!/usr/bin/env python
import mahotas
s_file='Nuts.png'
img = mahotas.imread(s_file, as_grey=True)
mahotas.imsave('Nuts_saved.**png', img)
exit()
# read in a grey scale image, imsave convert it to color image
s_file='Nuts.png'
img = mahotas.imread(s_file, as_grey=True)
mahotas.imsave('test.png', img)
exit()
# example 2, instead of getting a black and white image, I got red
and blue strips
import numpy as np
import mahotas
img = np.ones([10,10])
img[::2,:]=0
mahotas.imsave('test.png', img)
Thanks!
--
You received this message because you are subscribed to the Google
Groups "pythonvision" group.
To unsubscribe from this group and stop receiving emails from it, send
.
For more options, visit https://groups.google.com/**groups/opt_out<https://groups.google.com/groups/opt_out>
.
--
Luis Pedro Coelho | EMBL | http://luispedro.org
--
You received this message because you are subscribed to the Google Groups
"pythonvision" group.
To unsubscribe from this group and stop receiving emails from it, send an
.
For more options, visit https://groups.google.com/**groups/opt_out<https://groups.google.com/groups/opt_out>
.
--
You received this message because you are subscribed to the Google Groups "pythonvision" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pythonvision+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.
NewPy
2013-06-16 03:45:04 UTC
Permalink
Thanks for the tips, it works for me now with matplotlib.

I also install FreeImage and add its .so to my LD_LIBRARY_PATH, but
mahotas.imsave still tries to use matplotlib. How do I use enable mahotas
to use freeimage to save greyscale image?
Thanks!
Post by Thouis (Ray) Jones
You might add cmap=matplotlib.cm.gray (and maybe vmin=0, vmax=1, if the
incoming image is within [0,1]) to the matplotlib.imsave call, to better
approximate what freeimage would do.
Ray Jones
Post by Luis Pedro Coelho
Ah, you're right!
This is actually matplotlib.pyplot.imsave's implementation.
Mahotas does not implement IO, it always just exposes one of
1. imread (http://luispedro.org/**software/imread<http://luispedro.org/software/imread>
)
2. freeimage
3. matplotlib
(It tries these in order 'til it finds one that works).
*
I have just committed a fix so that the imsave for matplotlib at leasts
works around this and tells the user what's happening.
Thanks
Luis
Post by NewPy
Attached are the input and output files for the script below. I checked
with GIMP, it's colored. Thanks
#!/usr/bin/env python
import mahotas
s_file='Nuts.png'
img = mahotas.imread(s_file, as_grey=True)
mahotas.imsave('Nuts_saved.**png', img)
exit()
# read in a grey scale image, imsave convert it to color image
s_file='Nuts.png'
img = mahotas.imread(s_file, as_grey=True)
mahotas.imsave('test.png', img)
exit()
# example 2, instead of getting a black and white image, I got red
and blue strips
import numpy as np
import mahotas
img = np.ones([10,10])
img[::2,:]=0
mahotas.imsave('test.png', img)
Thanks!
--
You received this message because you are subscribed to the Google
Groups "pythonvision" group.
To unsubscribe from this group and stop receiving emails from it, send
For more options, visit https://groups.google.com/**groups/opt_out<https://groups.google.com/groups/opt_out>
.
--
Luis Pedro Coelho | EMBL | http://luispedro.org
--
You received this message because you are subscribed to the Google Groups
"pythonvision" group.
To unsubscribe from this group and stop receiving emails from it, send an
For more options, visit https://groups.google.com/**groups/opt_out<https://groups.google.com/groups/opt_out>
.
--
You received this message because you are subscribed to the Google Groups "pythonvision" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pythonvision+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.
Luis Pedro Coelho
2013-06-16 14:34:11 UTC
Permalink
Try:

import mahotas.io.freeimage

This should give you a descriptive error message.

HTH,
Luis
Post by NewPy
Thanks for the tips, it works for me now with matplotlib.
I also install FreeImage and add its .so to my LD_LIBRARY_PATH, but
mahotas.imsave still tries to use matplotlib. How do I use enable
mahotas to use freeimage to save greyscale image?
Thanks!
You might add cmap=matplotlib.cm.gray (and maybe vmin=0, vmax=1, if
the incoming image is within [0,1]) to the matplotlib.imsave call,
to better approximate what freeimage would do.
Ray Jones
On Sat, Jun 15, 2013 at 9:21 AM, Luis Pedro Coelho
Ah, you're right!
This is actually matplotlib.pyplot.imsave's implementation.
Mahotas does not implement IO, it always just exposes one of
1. imread (http://luispedro.org/__software/imread
<http://luispedro.org/software/imread>)
2. freeimage
3. matplotlib
(It tries these in order 'til it finds one that works).
*
I have just committed a fix so that the imsave for matplotlib at
leasts works around this and tells the user what's happening.
Thanks
Luis
Attached are the input and output files for the script
below. I checked
with GIMP, it's colored. Thanks
#!/usr/bin/env python
import mahotas
s_file='Nuts.png'
img = mahotas.imread(s_file, as_grey=True)
mahotas.imsave('Nuts_saved.__png', img)
exit()
# read in a grey scale image, imsave convert it to color image
s_file='Nuts.png'
img = mahotas.imread(s_file, as_grey=True)
mahotas.imsave('test.png', img)
exit()
# example 2, instead of getting a black and white
image, I got red
and blue strips
import numpy as np
import mahotas
img = np.ones([10,10])
img[::2,:]=0
mahotas.imsave('test.png', img)
Thanks!
--
You received this message because you are subscribed to the Google
Groups "pythonvision" group.
To unsubscribe from this group and stop receiving emails
from it, send
For more options, visit
https://groups.google.com/__groups/opt_out
<https://groups.google.com/groups/opt_out>.
--
Luis Pedro Coelho | EMBL | http://luispedro.org
--
You received this message because you are subscribed to the
Google Groups "pythonvision" group.
To unsubscribe from this group and stop receiving emails from
<javascript:>.
For more options, visit
https://groups.google.com/__groups/opt_out
<https://groups.google.com/groups/opt_out>.
--
You received this message because you are subscribed to the Google
Groups "pythonvision" group.
To unsubscribe from this group and stop receiving emails from it, send
For more options, visit https://groups.google.com/groups/opt_out.
--
Luis Pedro Coelho | EMBL | http://luispedro.org
--
You received this message because you are subscribed to the Google Groups "pythonvision" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pythonvision+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.
Loading...