PIL: problem to convert an image array to PIL format

Robert Franke franke.rob at googlemail.com
Thu Dec 17 07:45:59 EST 2009


Hi,

On Thu, Dec 17, 2009 at 1:14 PM, Sverre <sverreodegard at gmail.com> wrote:

> After converting a PIL image in memory to an array with numpy.asarray
> (), I make a adthreshold() with pymorph() with the result, that all
> pixels in the array are either false or true (boolean). But my try to
> convert this back into PIL format is failing
>
> img = Image.fromarray(rawimg, '1')
>
> because a true will be interpreted as integer 1 ), so that 7 pixels
> are black and one white. Has someone a solution, so that a  picture
> inly with "true" values doesn't look like this?
>
> http://img707.imageshack.us/img707/6051/p012.jpg
>
>
I am not 100% sure this is what you want, but this is how I apply a simple
threshold to a picture:


threshold = 145
img = Image.open("gray.jpg")
arr = numpy.asarray(img)
filtered = arr * (arr < threshold)
new_img = Image.fromarray(filtered,"L")


Cheers,

Robert
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20091217/bc5d85e2/attachment-0001.html>


More information about the Python-list mailing list