Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > image reduction script

Reply
Thread Tools

image reduction script

 
 
Philippe Martin
Guest
Posts: n/a
 
      03-24-2006
Hi,

I need to write a script to reduce the resolution/color depth of an image
(ex: .jpg) based on a target size.

The point is for the target picture to still be "understandable" - yet I
target getting down to 5K.

Are there libraries out there that could help me start ?

Thanks

Philippe


 
Reply With Quote
 
 
 
 
Larry Bates
Guest
Posts: n/a
 
      03-24-2006
Philippe Martin wrote:
> Hi,
>
> I need to write a script to reduce the resolution/color depth of an image
> (ex: .jpg) based on a target size.
>
> The point is for the target picture to still be "understandable" - yet I
> target getting down to 5K.
>
> Are there libraries out there that could help me start ?
>
> Thanks
>
> Philippe
>
>

Python Imaging Library (PIL).

http://www.pythonware.com/products/pil/

-Larry Bates
 
Reply With Quote
 
 
 
 
Philippe Martin
Guest
Posts: n/a
 
      03-25-2006
Larry,

I actually did not find what I needed in PIL (missed it ?) but found this
package quite usefull: http://www.imagemagick.org/script/index.php

Philippe





Larry Bates wrote:

> Philippe Martin wrote:
>> Hi,
>>
>> I need to write a script to reduce the resolution/color depth of an image
>> (ex: .jpg) based on a target size.
>>
>> The point is for the target picture to still be "understandable" - yet I
>> target getting down to 5K.
>>
>> Are there libraries out there that could help me start ?
>>
>> Thanks
>>
>> Philippe
>>
>>

> Python Imaging Library (PIL).
>
> http://www.pythonware.com/products/pil/
>
> -Larry Bates


 
Reply With Quote
 
Kamilche
Guest
Posts: n/a
 
      03-26-2006

To reduce the color depth of an image in PIL:
im = im.convert(mode="P", palette=Image.ADAPTIVE)

 
Reply With Quote
 
Philippe Martin
Guest
Posts: n/a
 
      03-26-2006
Thanks,

I'll give it a shot.

Philippe



Kamilche wrote:

>
> To reduce the color depth of an image in PIL:
> im = im.convert(mode="P", palette=Image.ADAPTIVE)


 
Reply With Quote
 
Philippe Martin
Guest
Posts: n/a
 
      03-26-2006
Kamilche,

I am posting the code in another thread but am not certain that convert does
anything to the picture color depth ... still searching in the doc.

Philippe




Kamilche wrote:

>
> To reduce the color depth of an image in PIL:
> im = im.convert(mode="P", palette=Image.ADAPTIVE)


 
Reply With Quote
 
Kamilche
Guest
Posts: n/a
 
      03-26-2006
Be sure and use mode = P instead of RGB, like you have in your other
code. P is for palettized images. Don't palettize if you're storing as
JPG, only if you're storing as PNG or some other format that can handle
256 color images.

 
Reply With Quote
 
Philippe Martin
Guest
Posts: n/a
 
      03-26-2006
Kamilche wrote:

> Be sure and use mode = P instead of RGB, like you have in your other
> code. P is for palettized images. Don't palettize if you're storing as
> JPG, only if you're storing as PNG or some other format that can handle
> 256 color images.



My problem is this:

1) If I use a save to jpg after a convert('P') I get an exception (what you
are refering to I assume)
2) If I use a save to png (I start with a jpg), then the (X,Y) size of the
output is much smaller than convert('RGB') and save to jpg - (and I want to
opposit: as small as possible in byte size and as large as possible in
(X,Y) ):

*** SAME INPUT FILE.JPG ***
***********convert('P') save to PNG
/home/philippe/tmp/tmprpdfEO is a 65x87 Raw PPM image with 256 levels
Default gamma for ITRUE image is 1.00
Building XImage...done
Have adjusted image from 1.00 to display gamma of 2.20

Versus:
***********convert('RGB') save to JPG
/home/philippe/tmp/tmpYCLrQR is a 173x231 Raw PPM image with 256 levels
Default gamma for ITRUE image is 1.00
Building XImage...done
Have adjusted image from 1.00 to display gamma of 2.20


Philippe



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Noise Reduction By Image Averaging John Navas Digital Photography 6 01-23-2008 10:03 AM
Noise Reduction software (Neat Image, Noise Ninja, etc.) John Navas Digital Photography 0 10-19-2007 03:22 PM
PIL & image size reduction script Philippe Martin Python 5 03-27-2006 01:29 PM
Newbie Question: Processing RAWs (.NEFs) - Image Size Reduction Necessary? anonymous1 Digital Photography 7 05-15-2005 01:21 AM
Noise reduction - Neat Image - Olympus C-2500L John Navas Digital Photography 0 03-07-2004 04:09 PM



Advertisments