Discussion:
PIL and antialiasing problem
(too old to reply)
Laszlo Zsolt Nagy
2004-12-02 11:03:57 UTC
Permalink
Hi all,

I have a little problem with PIL. I need to display images in a
browser (thumbnails) (this is the selector window).
I also need the original version of the image to be displayed in a
Java applet.

One example:

thumbnail: Loading Image...
original: Loading Image...

I made the thumbnail from the original image using PIL this way:


im = Image.open(fullpath)
try:
im.thumbnail(THUMBSIZE,Image.ANTIALIAS)
im.save(thumbpath)
finally:
del im


If I do not use ANTIALIAS, then I get this:

Loading Image...

With the ANTIALIAS-ed version, the problem is that you cannot see the
lines - they are very light gray, almost invisible. I have many cliparts
with thin lines. However, I also have many cliparts like this:

Loading Image...

I tried to posterize or darken the images but I could not find a good
solution. (I also tried to count the number of colors in the image and
use this info.) Can you suggest an image filter and/or method that creates
darker black lines from the original thin lines? Also it would be
great to have it working with those colorful smudged images. It will
be terribly slow to separate them by hand. There are almost 15000 of
them...
--
Thanks,
Laszlo

mailto:***@geochemsource.com
web: http://designasign.biz
Will McGugan
2004-12-02 11:25:35 UTC
Permalink
Post by Laszlo Zsolt Nagy
I tried to posterize or darken the images but I could not find a good
solution. (I also tried to count the number of colors in the image and
use this info.) Can you suggest an image filter and/or method that creates
darker black lines from the original thin lines? Also it would be
great to have it working with those colorful smudged images. It will
be terribly slow to separate them by hand. There are almost 15000 of
them...
Try running ImageFilter.MinFilter on the image before you thumbnail it.
This should make dark lines thicker.

HTH,

Will McGugan
Laszlo Zsolt Nagy
2004-12-02 12:04:55 UTC
Permalink
Post by Will McGugan
Try running ImageFilter.MinFilter on the image before you thumbnail it.
This should make dark lines thicker.
HTH,
Will McGugan
You are my man! It worked perfectly!

Statement: Sometimes PIL is better than Adobe Photoshop. :-)

I also found these with the aid of the wonderful dir() function:

MinFilter, MaxFilter, MedianFilter, ModeFilter, RankFilter, BuiltInFilter

They do not have a docstring and they are not documented in the
handbook. I'm curious what they do exactly. The others (like BLUR, EMBOSS,
CONTOUR etc.) are documented very well. I wonder why is that.


Python forever,

Laszlo

mailto:***@geochemsource.com
web:http://designasign.biz
Will McGugan
2004-12-02 12:33:57 UTC
Permalink
Post by Laszlo Zsolt Nagy
Post by Will McGugan
Try running ImageFilter.MinFilter on the image before you thumbnail it.
This should make dark lines thicker.
HTH,
Will McGugan
You are my man! It worked perfectly!
Statement: Sometimes PIL is better than Adobe Photoshop. :-)
Happy to help :)
Post by Laszlo Zsolt Nagy
MinFilter, MaxFilter, MedianFilter, ModeFilter, RankFilter, BuiltInFilter
MinFilter replaces each pixel with the darkest pixel within the filter
area. MaxFilter replaces each pixel with the brightest of the
surrounding pixels. MedianFilter sorts the surrounding pixels by
brightness and selects the middle value. I think ModeFilter selects the
most common pixel if occurs more than a certain threshhold. RankFilter
is like Median, but it selects the colour at a specific point within the
ordered list. Not sure about BuiltInFilter, my guess is its an
implementation detail of some kind..


Regards,

Will McGugan
Fredrik Lundh
2004-12-06 17:49:35 UTC
Permalink
Post by Laszlo Zsolt Nagy
Statement: Sometimes PIL is better than Adobe Photoshop. :-)
MinFilter, MaxFilter, MedianFilter, ModeFilter, RankFilter, BuiltInFilter
They do not have a docstring and they are not documented in the
handbook. I'm curious what they do exactly. The others (like BLUR, EMBOSS,
CONTOUR etc.) are documented very well. I wonder why is that.
they were experimental (and some of them were slightly broken, iirc)
in 1.1.4. they're all officially supported in 1.1.5:

http://www.pythonware.com/library/pil/handbook/imagefilter.htm

</F>

Belyh G.P.
2004-12-02 11:37:24 UTC
Permalink
Post by Laszlo Zsolt Nagy
Hi all,
I have a little problem with PIL. I need to display images in a
browser (thumbnails) (this is the selector window).
I also need the original version of the image to be displayed in a
Java applet.
thumbnail: http://designasign.biz/applet/GIF_Small/AIRCRAFT/a10per.png
original: http://designasign.biz/applet/GIF/AIRCRAFT/a10per.png
im = Image.open(fullpath)
im.thumbnail(THUMBSIZE,Image.ANTIALIAS)
im.save(thumbpath)
del im
http://designasign.biz/tmp/a10per.png
With the ANTIALIAS-ed version, the problem is that you cannot see the
lines - they are very light gray, almost invisible. I have many cliparts
http://designasign.biz/applet/GIF/AFRICA/angel03.png
I tried to posterize or darken the images but I could not find a good
solution. (I also tried to count the number of colors in the image and
use this info.) Can you suggest an image filter and/or method that creates
darker black lines from the original thin lines? Also it would be
great to have it working with those colorful smudged images. It will
be terribly slow to separate them by hand. There are almost 15000 of
them...
Photoshop cann't normaly resize
http://designasign.biz/applet/GIF/AIRCRAFT/a10per.png
too.
But when I resize this image with bgcolor=white all done well.
Maybe PIL needed image with bgcolor for normal resize.
Loading...