From meyer at mesw.de Tue Mar 1 20:22:15 2005 From: meyer at mesw.de (Markus Meyer) Date: Tue Mar 1 20:16:34 2005 Subject: [Image-SIG] Aspect ratio in PIL In-Reply-To: <42203464.4261.537D813@localhost> References: <42203464.4261.537D813@localhost> Message-ID: <4224C0E7.7090600@mesw.de> There are two ways to achieve this: 1. Calculate the aspect ratio yourself, then resize the picture accordingly, e.g. (not tested) aspect_ratio = float(im.height) / im.width im.resize(target_width, target_width * aspect_ratio) 2. Use the thumbnail function. It creates an image with the given size, while padding the edges to preserve aspect ratio, when needed. Markus export@hope.cz schrieb: >Is KEEP ASPECT RATIO available when I resize a picture? >Thanks for help >Lad. >_______________________________________________ >Image-SIG maillist - Image-SIG@python.org >http://mail.python.org/mailman/listinfo/image-sig > > > From meyer at mesw.de Tue Mar 1 21:06:47 2005 From: meyer at mesw.de (Markus Meyer) Date: Tue Mar 1 21:01:05 2005 Subject: [Image-SIG] Watermark feature in PIL In-Reply-To: <421F1A75.2430.EA89A0@localhost> References: <421F1A75.2430.EA89A0@localhost> Message-ID: <4224CB57.9030500@mesw.de> export@hope.cz schrieb: >Is watermark feature supported in PIL ? > > Google is your friend: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/362879 From kevin at cazabon.com Tue Mar 8 22:34:40 2005 From: kevin at cazabon.com (kevin@cazabon.com) Date: Tue Mar 8 22:35:36 2005 Subject: [Image-SIG] ImageFont - loading issue (bug) Message-ID: <027d01c52426$a4321530$640aa8c0@duallie> Hi everyone - just a minor problem to report: I had a script that used the ImageFont.load() function a whole bunch of times quickly in succession (same font file... within a commonly used function), and it would randomly have problems loading the font. This resulted in a garbage image when used. Unfortunately I could never catch the actual error message. I solved the problem by caching the font instead of reloading it each time, but I'm really not sure why it would have problems being loaded successively. It's not an issue for me - just thought I'd let you know. Kevin. From steve at holdenweb.com Wed Mar 9 03:30:28 2005 From: steve at holdenweb.com (Steve Holden) Date: Wed Mar 9 03:30:32 2005 Subject: [Image-SIG] Cygwin font rendering problems Message-ID: <422E5FC4.5060301@holdenweb.com> Is anyone else running PIL under Cygwin? I've been doing so with great satisfaction for quite a while, but suddenly it seems that I've done something (sigh, again) to the font rendering. I suspect this is a local installation fault given that everything worked so well for so long, and that the 1.1.5c1 release works perfectly under Windows. Now in Cygwin fonts opened using ImageFont.truetype() don't render - I just get the background. Both 1.1.5b2 and 1.1.5c1 exhibit the same behavior, but I'm pretty sure that 1.1.5b2 was working a few days ago. No errors reported by selftest.py, and the build summary says everything looks good. Anyone got any ideas what I may have done wrong? regards Steve -- Steve Holden +1 703 861 4237 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/ From mvirkkil at cc.hut.fi Wed Mar 9 13:29:09 2005 From: mvirkkil at cc.hut.fi (Mikko =?ISO-8859-1?Q?Virkkil=E4?=) Date: Wed Mar 9 13:29:07 2005 Subject: [Image-SIG] Discovering inactive options in SANE Message-ID: <1110371349.22653.23.camel@localhost.localdomain> The scanner.get_options() blurts out a lot of options, but some of these are inactive and can't be changed/used. How do I know which ones are inactive? I'm working on a python project (my first ever) called WebSANE that makes it possible to control a scanner on the LAN using a browser. This way there would be no need to install any additional software on the client (besides a web browser) to access the scanner. I would like to be able to adjust the brightness and contrast using the web interface if the scanner supports it. Because of this I need to figure out if the scanner supports those options. I would also like to use custom gamma tables for implementing brightness and contrast on the scanners that don't support bightness/contrast directly. xsane and some SANE backends already do this. Any pointers on how to generate and upload these in python would be greatly appreciated. Yours, Mikko From viniciuscb at gmail.com Wed Mar 9 14:00:59 2005 From: viniciuscb at gmail.com (Vinicius Cubas Brand) Date: Wed Mar 9 14:01:02 2005 Subject: [Image-SIG] conversion of a full image from RGB<->HSI Message-ID: Hi all Can you help me in a doubt? Is there some efficient way to do a conversion between an image in the RGB format in an image and the HSI format (aka, HLS or HSV), in python (PIL or others)? Thank you for attention, Vinicius -- .----------------------. | Vinicius Cubas Brand | | viniciuscb gmail.com | '----------------------' "A human being is part of a whole, called by us the Universe, a part limited in time and space. He experiences himself, his thoughts and feelings, as something separated from the rest--a kind of optical delusion of his consciousness. This delusion is a kind of prison for us, restricting us to our personal desires and to affection for a few persons nearest us. Our task must be to free ourselves from this prison by widening our circles of compassion to embrace all living creatures and the whole of nature in its beauty." - Albert Einstein From giovanniangeli at iquattrocastelli.it Wed Mar 9 17:50:25 2005 From: giovanniangeli at iquattrocastelli.it (giovanniangeli@iquattrocastelli.it) Date: Wed Mar 9 18:26:36 2005 Subject: [Image-SIG] conversion of a full image from RGB<->HSI In-Reply-To: References: Message-ID: <28680.82.88.14.108.1110387025.squirrel@www.iquattrocastelli.it> > Hi all > > Can you help me in a doubt? Is there some efficient way to do a > conversion between an image in the RGB format in an image and the HSI > format (aka, HLS or HSV), in python (PIL or others)? yes, PIL gives that. look at the page http://www.pythonware.com/library/pil/handbook/image.htm in particular at the method of image Object in PIL.Image module. Enjoy. P.S. In general I have found in PIL an efficient and complete image processing library to be use from Python. Giovanni Angeli. From pascor at hotpop.com Thu Mar 10 05:30:47 2005 From: pascor at hotpop.com (Ray Pasco) Date: Thu Mar 10 05:30:08 2005 Subject: [Image-SIG] RGB conversion to CMKY gives strange results Message-ID: <422FCD77.7000306@hotpop.com> I'm using the im.convert() from RGB to CMYK and am getting very strange results. First, the K value is stuck at zero no matter what the RGB values are. Next, the C, M and Y values are integers and not in the value range 0.0 - 1.0. I have no idea what they mean. They seem to bear no relationship at all to the proper CMYK values. I coded an RGB to CMY to CMYK algorithm derived from the formulas found at http://www.easyrgb.com/math.php?MATH=M2#text2 , which seem to be correct. Is im.convert ('CMYK') broken ? I'd like to use it since this is the only colorspace conversion available in PIL. Is there any particular reason why conversions to HSV and/or HSL don't exist ? It would really useful to work with brightness or luminosity directly. (1.1.5b1 on XP) From jepler at unpythonic.net Thu Mar 10 14:16:21 2005 From: jepler at unpythonic.net (Jeff Epler) Date: Thu Mar 10 14:16:26 2005 Subject: [Image-SIG] RGB conversion to CMKY gives strange results In-Reply-To: <422FCD77.7000306@hotpop.com> References: <422FCD77.7000306@hotpop.com> Message-ID: <20050310131618.GC6694@unpythonic.net> The algorithm that im.convert("CMYK") uses is this: (C code) static void rgb2cmyk(UINT8* out, const UINT8* in, int xsize) { int x; for (x = 0; x < xsize; x++) { /* Note: no undercolour removal */ *out++ = ~(*in++); *out++ = ~(*in++); *out++ = ~(*in++); *out++ = 0; in++; } } All numbers are in the inclusive range [0, 255] in this case. If "in" was 0, then out is 255, so it's like the algorithm on the page you mentouned for RGB->CMY, where the value 255 corresponds to 1.0, and K is simply set to 0 all the time. Using numeric or numarray, it is probably possible to do the CMY->CMYK conversion step described on the page you mentioned, and have the resulting code run fairly quickly. As for conversions from RGB to other 3-component color systems, you can use the "im.convert(mode, matrix)" function with the right matrix. An example is in the documentation for converting to the XYZ colorspace. This block of code, common to many of the conversion functions on that web page you mentioned, has to do with doing gamma conversion: if ( var_R > 0.0031308 ) var_R = 1.055 * ( var_R ^ ( 1 / 2.4 ) ) - 0.055 else var_R = 12.92 * var_R if ( var_G > 0.0031308 ) var_G = 1.055 * ( var_G ^ ( 1 / 2.4 ) ) - 0.055 else var_G = 12.92 * var_G if ( var_B > 0.0031308 ) var_B = 1.055 * ( var_B ^ ( 1 / 2.4 ) ) - 0.055 else var_B = 12.92 * var_B To perform this step in PIL, you would use the im.point method with a properly initialized table. Jeff -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: not available Url : http://mail.python.org/pipermail/image-sig/attachments/20050310/7714ff56/attachment.pgp From jepler at unpythonic.net Thu Mar 10 18:48:48 2005 From: jepler at unpythonic.net (Jeff Epler) Date: Thu Mar 10 18:49:41 2005 Subject: [Image-SIG] RGB conversion to CMKY gives strange results In-Reply-To: <423069B2.9060802@hotpop.com> References: <422FCD77.7000306@hotpop.com> <20050310131618.GC6694@unpythonic.net> <423069B2.9060802@hotpop.com> Message-ID: <20050310174848.GE8702@unpythonic.net> (Please copy the list with these posts. Maybe others will benefit from this discussion someday) Here's some code that inverts the red channel of an RGB image using im.point: import Image inverter = [255-i for i in range(256)] unchanged = range(256) i = Image.open("input.jpg") j = i.point(inverter + unchanged + unchanged) j.save("output.jpg") In this usage, i.point takes a 768-entry list of integers. The first 256 entries are used to map red values, the second 256 entries to map green values, and the last 256 entries to map blue values. You could change brightness and contrast across all channels by using a ramp functnction of your choice. Something like [untested] contrast = 1.1 # Increase contrast to 110% of original brightness = 16 # Increase brightness by 16/255 ~= 6.25% c = [int(min(255, max(0, i * contrast + brightness))) for i in range(255)] ... j = i.point(c+c+c) I didn't immediately get the 'im.convert' to XYZ colorspace to work as documented. Jeff -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: not available Url : http://mail.python.org/pipermail/image-sig/attachments/20050310/ea181b23/attachment.pgp From kevin at cazabon.com Thu Mar 10 22:03:20 2005 From: kevin at cazabon.com (kevin@cazabon.com) Date: Thu Mar 10 22:04:05 2005 Subject: [Image-SIG] RGB conversion to CMKY gives strange results References: <422FCD77.7000306@hotpop.com> Message-ID: <02a901c525b4$975af9f0$640aa8c0@duallie> FYI, you can also do color space conversions using ICC profiles - in the end the best method, assuming you have good profiles for the specific application. I wrote an ICC module for PIL called pyCMS. See: http://www.cazabon.com/pyCMS/ Fredrik - there's still a standing offer if you're interested in incorporating the usm / gausian blur, or even pyCMS into the standard library. However it sounds like you're hands are full these days too! (My little one has limited my spare time significantly, otherwise I'd just send you diffs) Kevin. ----- Original Message ----- From: "Ray Pasco" To: "image-sig PIL" Sent: Thursday, March 10, 2005 5:30 AM Subject: [Image-SIG] RGB conversion to CMKY gives strange results > I'm using the im.convert() from RGB to CMYK and am getting very strange > results. > First, the K value is stuck at zero no matter what the RGB values are. > Next, the C, M and Y values are integers and not in the value range 0.0 > - 1.0. > I have no idea what they mean. They seem to bear no relationship at all > to the > proper CMYK values. > > I coded an RGB to CMY to CMYK algorithm derived from the formulas > found at http://www.easyrgb.com/math.php?MATH=M2#text2 , which > seem to be correct. > > Is im.convert ('CMYK') broken ? I'd like to use it since this is the only > colorspace conversion available in PIL. > > Is there any particular reason why conversions to HSV and/or HSL don't > exist ? > It would really useful to work with brightness or luminosity directly. > > (1.1.5b1 on XP) > > > _______________________________________________ > Image-SIG maillist - Image-SIG@python.org > http://mail.python.org/mailman/listinfo/image-sig > > > From pascor at hotpop.com Fri Mar 11 00:46:39 2005 From: pascor at hotpop.com (Ray Pasco) Date: Fri Mar 11 00:46:10 2005 Subject: [Image-SIG] RGB conversion to CMKY gives strange results In-Reply-To: <20050310174848.GE8702@unpythonic.net> References: <422FCD77.7000306@hotpop.com> <20050310131618.GC6694@unpythonic.net> <423069B2.9060802@hotpop.com> <20050310174848.GE8702@unpythonic.net> Message-ID: <4230DC5F.2010809@hotpop.com> Jeff - Thanks for the tips. The documentation specifically says that im.point() can only be used to convert mode L and P images to mode 1 images, and that the mode string must be specified as the second parameter. If not so, the present handbook is very wrong and misleading. Is the proper documentation for im.point() available anywhere ? The doc for im.convert is obviously wrong, too ! It says that the coefficient matrix must be either a 4-tuple or a 16-tuple, yet its own example uses a 12-tuple ! Egads ! What is going on ? Ray Jeff Epler wrote: >(Please copy the list with these posts. Maybe others will benefit from >this discussion someday) > >Here's some code that inverts the red channel of an RGB image using >im.point: > import Image > > inverter = [255-i for i in range(256)] > unchanged = range(256) > i = Image.open("input.jpg") > j = i.point(inverter + unchanged + unchanged) > j.save("output.jpg") >In this usage, i.point takes a 768-entry list of integers. The first >256 entries are used to map red values, the second 256 entries to map >green values, and the last 256 entries to map blue values. You could >change brightness and contrast across all channels by using a ramp >functnction of your choice. Something like [untested] > contrast = 1.1 # Increase contrast to 110% of original > brightness = 16 # Increase brightness by 16/255 ~= 6.25% > c = [int(min(255, max(0, i * contrast + brightness))) for i in range(255)] > ... > j = i.point(c+c+c) > >I didn't immediately get the 'im.convert' to XYZ colorspace to work as >documented. > >Jeff > > From jepler at unpythonic.net Fri Mar 11 04:45:03 2005 From: jepler at unpythonic.net (Jeff Epler) Date: Fri Mar 11 04:45:06 2005 Subject: [Image-SIG] RGB conversion to CMKY gives strange results In-Reply-To: <4230DC5F.2010809@hotpop.com> References: <422FCD77.7000306@hotpop.com> <20050310131618.GC6694@unpythonic.net> <423069B2.9060802@hotpop.com> <20050310174848.GE8702@unpythonic.net> <4230DC5F.2010809@hotpop.com> Message-ID: <20050311034503.GA28246@unpythonic.net> On Thu, Mar 10, 2005 at 06:46:39PM -0500, Ray Pasco wrote: > Jeff - > > Thanks for the tips. The documentation specifically says that > im.point() can only be used to convert mode L and P images to mode 1 > images, and that the mode string must be specified as the second > parameter. If not so, the present handbook is very wrong and > misleading. I read the documentation here: http://www.pythonware.com/library/pil/handbook/image.htm The part I read was this: im.point(table) => image im.point(function) => image Returns a copy of the image where each pixel has been mapped through the given table. The table should contains 256 values per band in the image. If a function is used instead, it should take a single argument. The function is called once for each possible pixel value, and the resulting table is applied to all bands of the image. If the image has mode "I" (integer) or "F" (floating point), you must use a function, and it must have the following format: argument * scale + offset Map floating point images out = im.point(lambda i: i * 1.2 + 10) You can leave out either the scale or the offset. Just below that is the documentation for the form of im.point you're mentioning. Jeff -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: not available Url : http://mail.python.org/pipermail/image-sig/attachments/20050310/f1d76ff5/attachment.pgp From schutte at fel.tno.nl Fri Mar 11 15:08:56 2005 From: schutte at fel.tno.nl (K Schutte) Date: Fri Mar 11 15:09:11 2005 Subject: [Image-SIG] ANN: PIL 1.1.5 release candidate 1 (february 20, 2005) References: Message-ID: <4231A678.EDE31808@fel.tno.nl> Fredrik, Compiling this for mingw 3.1.0-1, using gcc 3.4.2,and Windows XP-home-NL-sp2: - there is a double definition of INT64, both in C:/msys/1.0/mingw/bin/../lib/gcc/mingw32/3.4.2/../../../../include/basetsd.h:110 (as typedef) and libImaging/ImPlatform.h:61 (as #define) gcc.exe -mno-cygwin -mdll -O -Wall -IlibImaging -I/c/prog/Python22/include - c map.c In file included from C:/msys/1.0/mingw/bin/../lib/gcc/mingw32/3.4.2/../../../../include/winnt.h:164, from C:/msys/1.0/mingw/bin/../lib/gcc/mingw32/3.4.2/../../../../include/windef.h:246, from C:/msys/1.0/mingw/bin/../lib/gcc/mingw32/3.4.2/../../../../include/windows.h:48, from map.c:36: C:/msys/1.0/mingw/bin/../lib/gcc/mingw32/3.4.2/../../../../include/basetsd.h:110: error: syntax error before ',' token building '_imaging' extension In file included from C:/msys/1.0/mingw/bin/../lib/gcc/mingw32/3.4.2/../../../../include/winnt.h:164, from C:/msys/1.0/mingw/bin/../lib/gcc/mingw32/3.4.2/../../../../include/windef.h:246, from C:/msys/1.0/mingw/bin/../lib/gcc/mingw32/3.4.2/../../../../include/windows.h:48, from libImaging/ImDib.h:21, from display.c:39: C:/msys/1.0/mingw/bin/../lib/gcc/mingw32/3.4.2/../../../../include/basetsd.h:110: error: syntax error before ',' token In file included from C:/msys/1.0/mingw/bin/../lib/gcc/mingw32/3.4.2/../../../../include/winnt.h:164, from C:/msys/1.0/mingw/bin/../lib/gcc/mingw32/3.4.2/../../../../include/windef.h:246, from C:/msys/1.0/mingw/bin/../lib/gcc/mingw32/3.4.2/../../../../include/windows.h:48, from libImaging\/ImDib.h:21, from libImaging\Dib.c:27: C:/msys/1.0/mingw/bin/../lib/gcc/mingw32/3.4.2/../../../../include/basetsd.h:110: error: syntax error before ',' token - A use of an undefined local variable in setup.py: Traceback (most recent call last): File "setup.py", line 436, in ? version=VERSION, File "c:\prog\Python22\lib\distutils\core.py", line 138, in setup dist.run_commands() File "c:\prog\Python22\lib\distutils\dist.py", line 893, in run_commands self.run_command(cmd) File "c:\prog\Python22\lib\distutils\dist.py", line 913, in run_command cmd_obj.run() File "c:\prog\Python22\lib\distutils\command\build.py", line 107, in run self.run_command(cmd_name) File "c:\prog\Python22\lib\distutils\cmd.py", line 330, in run_command self.distribution.run_command(command) File "c:\prog\Python22\lib\distutils\dist.py", line 913, in run_command cmd_obj.run() File "c:\prog\Python22\lib\distutils\command\build_ext.py", line 256, in run self.build_extensions() File "setup.py", line 331, in build_extensions self.summary_report(feature, unsafe_zlib) UnboundLocalError: local variable 'unsafe_zlib' referenced before assignment Both problems mentioned above are fixed in attached diff file. This results in: /c/prog/Python22/python setup.py build_ext -i -cmingw32 << output of build process deleted >> -------------------------------------------------------------------- PIL 1.1.5c1 BUILD SUMMARY -------------------------------------------------------------------- version 1.1.5c1 platform win32 2.2.2 (#37, Oct 14 2002, 17:02:34) [MSC 32 bit (Intel)] -------------------------------------------------------------------- *** TKINTER support not available (Tcl/Tk 8.3 libraries needed) *** JPEG support not available *** ZLIB (PNG/ZIP) support not available *** FREETYPE2 support not available -------------------------------------------------------------------- /c/prog/Python22/python selftest.py ***************************************************************** Failure in example: _info(Image.open("Images/lena.jpg")) from line #24 of selftest.testimage Exception raised: Traceback (most recent call last): File ".\doctest.py", line 499, in _run_examples_inner exec compile(source, "", "single") in globs File "", line 1, in ? File ".\selftest.py", line 21, in _info im.load() File "PIL\ImageFile.py", line 180, in load d = Image._getdecoder(self.mode, d, a, self.decoderconfig) File "PIL\Image.py", line 338, in _getdecoder raise IOError("decoder %s not available" % decoder_name) IOError: decoder jpeg not available 1 items had failures: 1 of 55 in selftest.testimage ***Test Failed*** 1 failures. *** 1 tests of 55 failed. Regards, Klamer Fredrik Lundh wrote: > PIL 1.1.5 release candidate 1 (aka rc1 revision 2) is now available > from effbot.org: > > http://effbot.org/downloads#imaging > > (look for Imaging-1.1.5c1.tar.gz for source, and PIL-115c1*.exe > for windows binaries). > > For a list of changes, see this page: > > http://effbot.org/zone/pil-changes-115.htm > > Report bugs to this list or directly to me, as usual. > > enjoy /F > > _______________________________________________ > Image-SIG maillist - Image-SIG@python.org > http://mail.python.org/mailman/listinfo/image-sig -- ------------------------------------------------------------------------------ The disclaimer that applies to e-mail from TNO can be found on: http://www.tno.nl/disclaimer/email.html ------------------------------------------------------------------------------ -------------- next part -------------- diff -rub Imaging-1.1.5c1/display.c Imaging-1.1.5c1-ks/display.c --- Imaging-1.1.5c1/display.c Sat Jun 5 16:14:57 2004 +++ Imaging-1.1.5c1-ks/display.c Fri Mar 11 13:48:48 2005 @@ -36,6 +36,10 @@ #ifdef WIN32 +#ifdef __GNUC__ +#undef INT64 +#endif + #include "ImDib.h" typedef struct { diff -rub Imaging-1.1.5c1/libImaging/Dib.c Imaging-1.1.5c1-ks/libImaging/Dib.c --- Imaging-1.1.5c1/libImaging/Dib.c Wed Oct 6 08:55:33 2004 +++ Imaging-1.1.5c1-ks/libImaging/Dib.c Fri Mar 11 13:50:17 2005 @@ -24,6 +24,10 @@ #ifdef WIN32 +#ifdef __GNUC__ +#undef INT64 +#endif + #include "ImDib.h" diff -rub Imaging-1.1.5c1/map.c Imaging-1.1.5c1-ks/map.c --- Imaging-1.1.5c1/map.c Sat Jun 5 16:15:02 2004 +++ Imaging-1.1.5c1-ks/map.c Fri Mar 11 13:46:22 2005 @@ -32,6 +32,7 @@ #ifdef __GNUC__ #undef INT32 #undef UINT32 +#undef INT64 #endif #include "windows.h" #endif diff -rub Imaging-1.1.5c1/setup.py Imaging-1.1.5c1-ks/setup.py --- Imaging-1.1.5c1/setup.py Sun Feb 20 19:48:33 2005 +++ Imaging-1.1.5c1-ks/setup.py Fri Mar 11 13:55:36 2005 @@ -327,6 +327,8 @@ if feature.zlib: unsafe_zlib = self.check_zlib_version(include_dirs) + else: + unsafe_zlib = None self.summary_report(feature, unsafe_zlib) From fredrik at pythonware.com Fri Mar 11 17:49:04 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Fri Mar 11 17:56:07 2005 Subject: [Image-SIG] Re: RGB conversion to CMKY gives strange results References: <422FCD77.7000306@hotpop.com><20050310131618.GC6694@unpythonic.net><423069B2.9060802@hotpop.com><20050310174848.GE8702@unpythonic.net> <4230DC5F.2010809@hotpop.com> Message-ID: Ray Pasco wrote: > The doc for im.convert is obviously wrong, too ! It says that the > coefficient matrix must be either a 4-tuple or a 16-tuple, yet its own > example uses a 12-tuple ! it's a typo: the matrix should be either a 4-tuple (for an L target) or a 12-tuple (for an RGB target). From fredrik at pythonware.com Fri Mar 11 19:20:59 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Fri Mar 11 19:29:54 2005 Subject: [Image-SIG] Re: RGB conversion to CMKY gives strange results References: <422FCD77.7000306@hotpop.com> Message-ID: (repost) Ray Pasco wrote: > I'm using the im.convert() from RGB to CMYK and am getting very strange results. > First, the K value is stuck at zero no matter what the RGB values are. PIL doesn't do gray component removal and undercolor removal, since they're both device dependent. for some background, see: http://mail.python.org/pipermail/image-sig/2002-July/001908.html for device-aware conversions, you need device profiles and color management software, such as: http://www.cazabon.com/pyCMS/ > Next, the C, M and Y values are integers and not in the value range 0.0 - 1.0. I have no idea > what they mean. They seem to bear no relationship at all to the proper CMYK values. there's no absolute connection between a color model and the value ranges you use to represent a color component in that model. PIL uses 32-bit CMYK, where each channel is stored in an 8-bit integer (0-255). if you want another range, multiply or divide as necessary (to get 0.0 to 1.0, just divide the PIL value by 255.0). > I coded an RGB to CMY to CMYK algorithm derived from the formulas > found at http://www.easyrgb.com/math.php?MATH=M2#text2 , which > seem to be correct. the CMY(K) <=> RGB conversions on those page looks pretty similar to the PIL versions. > Is im.convert ('CMYK') broken? no. > Is there any particular reason why conversions to HSV and/or HSL don't exist ? for individual pixels, use the colorsys module in the standard Python library (but make sure to scale the values on the way in and out). for entire images, there's no good way to represent HSV/HSL/HSI/HSB etc in a 3*8-bit image memory (you usually want more resolution, especially for the H component). From fredrik at pythonware.com Fri Mar 11 17:31:05 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Fri Mar 11 21:59:07 2005 Subject: [Image-SIG] Re: RGB conversion to CMKY gives strange results References: <422FCD77.7000306@hotpop.com> Message-ID: Ray Pasco wrote: > I'm using the im.convert() from RGB to CMYK and am getting very strange results. First, the K > value is stuck at zero no matter what the RGB values are. PIL doesn't do gray component removal and undercolor removal, since they're both device dependent. for some background, see: http://mail.python.org/pipermail/image-sig/2002-July/001908.html for device-aware conversions, you need device profiles and color management software, such as: http://www.cazabon.com/pyCMS/ > Next, the C, M and Y values are integers and not in the value range 0.0 - 1.0. I have no idea > what they mean. They seem to bear no relationship > at all to the proper CMYK values. there's no absolute connection between a color model and the value ranges you use to represent a color in that model. PIL uses 32-bit CMYK, where each channel is stored in an 8-bit integer (0-255). if you want another range, use multiplication or division as necessary (to get 0.0 to 1.0, just divide the PIL value with 255.0). > I coded an RGB to CMY to CMYK algorithm derived from the formulas > found at http://www.easyrgb.com/math.php?MATH=M2#text2 , which > seem to be correct. the CMY(K) <=> RGB conversions on those page looks pretty similar to the PIL versions. > Is im.convert ('CMYK') broken? no. > Is there any particular reason why conversions to HSV and/or HSL don't exist ? for individual pixels, use the colorsys module in the standard Python library (but make sure to scale the values on the way in and out). for entire images, there's no good way to represent HSV/HSL/HSI/HSB etc in a 3*8-bit image memory (you usually want more resolution, especially for the H component). From klimek at grc.nasa.gov Fri Mar 11 23:44:04 2005 From: klimek at grc.nasa.gov (Bob Klimek) Date: Fri Mar 11 23:42:30 2005 Subject: [Image-SIG] Re: RGB conversion to CMKY gives strange results In-Reply-To: References: <422FCD77.7000306@hotpop.com> Message-ID: <42321F34.50407@grc.nasa.gov> Fredrik Lundh wrote: >>is there any particular reason why conversions to HSV and/or HSL don't exist ? >> >> >for individual pixels, use the colorsys module in the standard Python library >(but make sure to scale the values on the way in and out). > >for entire images, there's no good way to represent HSV/HSL/HSI/HSB etc >in a 3*8-bit image memory (you usually want more resolution, especially for >the H component). > > One way that would get around the resolution loss would be to have the result of HSI conversion go into a float image. And then if somebody wants to cut down on the resolution and convert it to an 8-bit image that would be their option. Bob From fredrik at pythonware.com Sat Mar 12 10:20:59 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sat Mar 12 10:21:09 2005 Subject: [Image-SIG] Re: Re: RGB conversion to CMKY gives strange results References: <422FCD77.7000306@hotpop.com> <42321F34.50407@grc.nasa.gov> Message-ID: Bob Klimek wrote: >>for entire images, there's no good way to represent HSV/HSL/HSI/HSB etc >>in a 3*8-bit image memory (you usually want more resolution, especially for >>the H component). > > One way that would get around the resolution loss would be to have the result of HSI conversion go > into a float image. And then if somebody wants to cut down on the resolution and convert it to an > 8-bit image that would be their option. yup, but PIL doesn't (yet) support multilayer floating point images... From ndemir at demir.web.tr Sun Mar 13 05:23:32 2005 From: ndemir at demir.web.tr (Necati DEMiR) Date: Sun Mar 13 01:22:33 2005 Subject: [Image-SIG] true colors in gd Message-ID: <4233C044.60801@demir.web.tr> Hello, how can i use true colors by using gd library. for example, the following code must copy the image but it doesn't #!/usr/bin/python import gd inp = gd.image("input.jpg") gd.gdMaxColors = 256 print inp.getClip()[1][0]+1,inp.getClip()[1][1]+1 output = gd.image((inp.getClip()[1][0]+1,inp.getClip()[1][1]+1)) for i in range(0, inp.getClip()[1][0]+1): for j in range(0, inp.getClip()[1][1]+1): red = inp.red(inp.getPixel((i,j))) green = inp.green(inp.getPixel((i,j))) blue = inp.blue(inp.getPixel((i,j))) color = output.colorAllocate((red, green, blue)) output.setPixel((i,j),color) f=open("out.png","w") output.writePng(f) f.close() -- ------------------------------------------------ Necati DEMiR ndemir@demir.web.tr http://demir.web.tr My Public Key => http://demir.web.tr/ndemir.asc ------------------------------------------------- From jwt at OnJapan.net Sun Mar 13 03:22:55 2005 From: jwt at OnJapan.net (Jim Tittsler) Date: Sun Mar 13 03:21:54 2005 Subject: [Image-SIG] true colors in gd In-Reply-To: <4233C044.60801@demir.web.tr> References: <4233C044.60801@demir.web.tr> Message-ID: <20050313022255.GC5115@server.onjapan.net> On Sun, Mar 13, 2005 at 02:23:32AM -0200, Necati DEMiR wrote: > how can i use true colors by using gd library. > for example, the following code must copy the image but it doesn't > > #!/usr/bin/python > > import gd > inp = gd.image("input.jpg") > gd.gdMaxColors = 256 > print inp.getClip()[1][0]+1,inp.getClip()[1][1]+1 > output = gd.image((inp.getClip()[1][0]+1,inp.getClip()[1][1]+1)) output = gd.image((inp.getClip()[1][0]+1,inp.getClip()[1][1]+1), True) Add a third argument, which when True makes it create TrueColor image. > for i in range(0, inp.getClip()[1][0]+1): > for j in range(0, inp.getClip()[1][1]+1): > red = inp.red(inp.getPixel((i,j))) > green = inp.green(inp.getPixel((i,j))) > blue = inp.blue(inp.getPixel((i,j))) > color = output.colorAllocate((red, green, blue)) You may want to use colorResolve() instead, which is smart enough to reuse palette entries or pick the closest entry if there are no more palette entries available. (And it degrades to always succeeding for TrueColor images.) > output.setPixel((i,j),color) > > f=open("out.png","w") > output.writePng(f) > f.close() -- Jim Tittsler, Tokyo http://www.OnJapan.net/ GPG: 0x01159DB6 Python Starship http://Starship.Python.net/ Ringo MUG Tokyo http://www.ringo.net/rss.html From viniciuscb at gmail.com Tue Mar 15 21:02:31 2005 From: viniciuscb at gmail.com (Vinicius Cubas Brand) Date: Tue Mar 15 21:02:41 2005 Subject: [Image-SIG] conversion of a full image from RGB<->HSI In-Reply-To: <28680.82.88.14.108.1110387025.squirrel@www.iquattrocastelli.it> References: <28680.82.88.14.108.1110387025.squirrel@www.iquattrocastelli.it> Message-ID: Hi. Unfortunately I think that this transformation can not be done with Image.convert: you can only do transformations between equivalent color spaces (i.e. reach the destination colorspace by doing a multiplication with a matrix with the source colorspace). The HSI colorspace, instead, is not an equivalent colorspace of RGB. To get the HSI equivalent of a RGB pixel one must do these transformations: I = 1/3 * (R+G+B) S = 1 - (3/(R+G+B))*(min(R,G,B)) H = cos^-1 ( (((R-G)+(R-B))/2)/ (sqrt((R-G)^2 + (R-B)*(G-B) ))) Some references: 1: http://www.cs.rit.edu/~ncs/color/t_convert.html 2: http://answers.google.com/answers/threadview?id=68502 There is a lot of efficient ways to do these transformations and also efficient algorithms in C/C++ . But to do it in python pil i would have to do a pixel by pixel operation with Image.getpixel and Image.putpixel, with every image pixel, what seemed a very slow way to do. I already thought in making an extension to PIL to do this colorspace transformation, but only asking to be sure there is not one already. Vinicius On Wed, 9 Mar 2005 17:50:25 +0100 (CET), giovanniangeli@iquattrocastelli.it wrote: > > Hi all > > > > Can you help me in a doubt? Is there some efficient way to do a > > conversion between an image in the RGB format in an image and the HSI > > format (aka, HLS or HSV), in python (PIL or others)? > > yes, PIL gives that. > > look at the page > > http://www.pythonware.com/library/pil/handbook/image.htm > > in particular at the method of image Object in PIL.Image module. > Enjoy. > > P.S. In general I have found in PIL an efficient and complete image > processing library to be use from Python. > > Giovanni Angeli. > > > -- .----------------------. | Vinicius Cubas Brand | | viniciuscb gmail.com | '----------------------' "A human being is part of a whole, called by us the Universe, a part limited in time and space. He experiences himself, his thoughts and feelings, as something separated from the rest--a kind of optical delusion of his consciousness. This delusion is a kind of prison for us, restricting us to our personal desires and to affection for a few persons nearest us. Our task must be to free ourselves from this prison by widening our circles of compassion to embrace all living creatures and the whole of nature in its beauty." - Albert Einstein From christian at cheimes.de Sun Mar 20 02:42:14 2005 From: christian at cheimes.de (Christian Heimes) Date: Sun Mar 20 02:52:25 2005 Subject: [Image-SIG] SystemError: tile cannot extend outside image Message-ID: I've an issue with GIF and maybe other images with extrem ratio. The attached gif file has a ration of 300x15 pixels and file resizing. exception: ... Module PIL.Image, line 1136, in save Module PIL.PngImagePlugin, line 510, in _save Module PIL.ImageFile, line 474, in _save SystemError: tile cannot extend outside image PIL version: 1.1.4 and 1.1.5rc1 with python 2.3.5 target size: 16 x 16 method: def scale(self, data, w, h): """ scale image (with material from ImageTag_Hotfix)""" # make sure we have valid int's size = int(w), int(h) pilfilter = PIL.Image.NEAREST # check for the pil version and enable antialias if > 1.1.3 if PIL.Image.VERSION >= "1.1.3": pilfilter = PIL.Image.ANTIALIAS original_file=StringIO(data) image = PIL.Image.open(original_file) # consider image mode when scaling # source images can be mode '1','L,','P','RGB(A)' # convert to greyscale or RGBA before scaling # preserve palletted mode (but not pallette) # for palletted-only image formats, e.g. GIF # PNG compression is OK for RGBA thumbnails original_mode = image.mode if original_mode == '1': image = image.convert('L') elif original_mode == 'P': image = image.convert('RGBA') image.thumbnail(size, pilfilter) format = image.format and image.format or 'PNG' # decided to only preserve palletted mode # for GIF, could also use image.format in ('GIF','PNG') if original_mode == 'P' and format == 'GIF': image = image.convert('P') thumbnail_file = StringIO() # quality parameter doesn't affect lossless formats image.save(thumbnail_file, format, quality=88) thumbnail_file.seek(0) return thumbnail_file, format.lower() Christian -------------- next part -------------- A non-text attachment was scrubbed... Name: test.gif Type: image/gif Size: 905 bytes Desc: not available Url : http://mail.python.org/pipermail/image-sig/attachments/20050320/0a70a804/test.gif From jwt at OnJapan.net Sun Mar 20 04:13:07 2005 From: jwt at OnJapan.net (Jim Tittsler) Date: Sun Mar 20 04:11:57 2005 Subject: [Image-SIG] SystemError: tile cannot extend outside image In-Reply-To: References: Message-ID: <20050320031307.GC7882@server.onjapan.net> On Sun, Mar 20, 2005 at 02:42:14AM +0100, Christian Heimes wrote: > I've an issue with GIF and maybe other images with extrem ratio. The > attached gif file has a ration of 300x15 pixels and file resizing. [...] > target size: > 16 x 16 Since image.thumbnail tries to preserve aspect ratio and uses integer division, your thumbnail ends up being 16x0. You could modify PIL to stay away from this degenerate condition by adding y=max(1,y) and x=max(1,y) rules to the aspect ratio calculation in Image.py. But I'd think you might be better served using image.transform and *not* attempting to maintain the aspect ratio in cases like this. Is a 1 pixel high thumbnail useful? -- Jim Tittsler, Mitaka, Tokyo http://www.OnJapan.net/ GPG: 0x01159DB6 Python Starship http://Starship.Python.net/crew/jwt/ Ringo MUG Tokyo http://www.ringo.net/rss.html From magoldfish at gmail.com Tue Mar 22 06:40:45 2005 From: magoldfish at gmail.com (Marcus Goldfish) Date: Tue Mar 22 06:40:48 2005 Subject: [Image-SIG] copying an image to the Clipboard Message-ID: <5e183f3d05032121402ce1c809@mail.gmail.com> Is there a method for copying an Image to the Clipboard on Win32 systems? Marcus From fredrik at pythonware.com Tue Mar 22 07:06:18 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue Mar 22 07:06:21 2005 Subject: [Image-SIG] Re: SystemError: tile cannot extend outside image References: <20050320031307.GC7882@server.onjapan.net> Message-ID: Jim Tittsler wrote: > You could modify PIL to stay away from this degenerate > condition by adding y=max(1,y) and x=max(1,y) rules to the > aspect ratio calculation in Image.py. this was fixed in a recent 1.1.5 beta. > But I'd think you might be better served using image.transform or just a plain im.resize() > and *not* attempting to maintain the aspect ratio in cases like this. > Is a 1 pixel high thumbnail useful? From fredrik at pythonware.com Tue Mar 22 14:35:23 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue Mar 22 14:43:11 2005 Subject: [Image-SIG] Re: copying an image to the Clipboard References: <5e183f3d05032121402ce1c809@mail.gmail.com> Message-ID: Marcus Goldfish wrote: > Is there a method for copying an Image to the Clipboard on Win32 systems? you can use the ImageGrab module to copy *from* a clipboard, but there's no built-in support for copying *to* a clipboard. (contributions are welcome!) From fredrik at pythonware.com Wed Mar 23 22:04:56 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed Mar 23 22:40:04 2005 Subject: [Image-SIG] ANN: PIL 1.1.5 release candidate 2 (march 23, 2005) Message-ID: PIL 1.1.5 release candidate 2 is now available from effbot.org: http://effbot.org/downloads#imaging (look for Imaging-1.1.5c2.tar.gz for source, and PIL-115c2*.exe for windows binaries). For a list of changes, see this page: http://effbot.org/zone/pil-changes-115.htm Report bugs to this list or directly to me, as usual. enjoy /F From pascor at hotpop.com Thu Mar 24 23:26:16 2005 From: pascor at hotpop.com (Ray Pasco) Date: Thu Mar 24 23:26:18 2005 Subject: [Image-SIG] How to tell whether/what is the alpha color in an indexed image file ? Message-ID: <42433E88.7070603@hotpop.com> If a PNG image with an alpha layer is opened, the im.mode will be "RGBA". However, if an indexed PNG or GIF is opened with an alpha color set, the mode is simply "P" (no "A" as in "PA"). 1) How can I get PIL to tell me if and what is the "alpha" color index ? 2) When an RGBA image is converted to an indexed image, does PIL record the occurance in some manner that any pixels had alpha values set to less than 255 ? Thanks, Ray Pasco From fredrik at pythonware.com Fri Mar 25 08:27:06 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Fri Mar 25 08:26:53 2005 Subject: [Image-SIG] Re: How to tell whether/what is the alpha color in an indexed image file ? References: <42433E88.7070603@hotpop.com> Message-ID: Ray Pasco wrote: > If a PNG image with an alpha layer is opened, the im.mode will be "RGBA". > However, if an indexed PNG or GIF is opened with an alpha color set, > the mode is simply "P" (no "A" as in "PA"). > > 1) How can I get PIL to tell me if and what is the "alpha" color index ? crop out the interesting pixel(s) and convert to RGBA, and use getpixel on the resulting image. > 2) When an RGBA image is converted to an indexed image, does PIL record > the occurance in some manner that any pixels had alpha values set to less than 255 ? RGBA->P is equivalent to RGBA->RGB->P, so the answer is no. From fredrik at pythonware.com Mon Mar 28 10:03:59 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Mon Mar 28 10:03:53 2005 Subject: [Image-SIG] ANN: Python Imaging Library 1.1.5 final (march 28, 2005) Message-ID: PIL 1.1.5 final is now available from effbot.org: http://effbot.org/downloads#imaging (look for Imaging-1.1.5.tar.gz for source, and PIL-115*.exe for windows binaries). For a list of changes, see this page: http://effbot.org/zone/pil-changes-115.htm Thanks to everyone involved! enjoy /F From pascor at hotpop.com Wed Mar 30 00:41:01 2005 From: pascor at hotpop.com (Ray Pasco) Date: Wed Mar 30 00:41:07 2005 Subject: [Image-SIG] Strange error - Please help !! Message-ID: <4249D97D.2090407@hotpop.com> (Python 2.3.4, PIL 1.1.5b1) All of a sudden, after developing with PIL yesterday, I get this error today: Traceback (most recent call last): File "try.py", line 4, in ? imPil = Image.open ('GOLDENS.JPG') File "C:\Python23\Lib\site-packages\PIL\Image.py", line 1725, in open preinit() File "C:\Python23\Lib\site-packages\PIL\Image.py", line 271, in preinit __import__("%sImagePlugin" % m, globals(), locals(), []) File "C:\Python23\Lib\site-packages\PIL\BmpImagePlugin.py", line 61, in ? class BmpImageFile(ImageFile.ImageFile): AttributeError: 'module' object has no attribute 'ImageFile' Why is it trying to use the BMP plugin on a JPG file ? Is this merely the first decoder used to try to resolve the image file type ? I completely un-installed and reinstalled Python, PIL, etc. to no avail. If I can't resolve this I will have to reinstall the OS ! Thanks, Ray Pasco From bob at redivi.com Wed Mar 30 01:12:18 2005 From: bob at redivi.com (Bob Ippolito) Date: Wed Mar 30 01:12:23 2005 Subject: [Image-SIG] Strange error - Please help !! In-Reply-To: <4249D97D.2090407@hotpop.com> References: <4249D97D.2090407@hotpop.com> Message-ID: On Mar 29, 2005, at 5:41 PM, Ray Pasco wrote: > (Python 2.3.4, PIL 1.1.5b1) > > All of a sudden, after developing with PIL yesterday, I get this error > today: > > File "C:\Python23\Lib\site-packages\PIL\BmpImagePlugin.py", line 61, > in ? > class BmpImageFile(ImageFile.ImageFile): > AttributeError: 'module' object has no attribute 'ImageFile' Since PIL does not use a proper package, it is particularly sensitive to the other files on your sys.path. It's likely that you have created or installed some other ImageFile.py that BmpImagePlugin is using instead of the intended one from PIL. Try this: >>> import ImageFile >>> print ImageFile.__file__ This will let you know which ImageFile is being imported. If it is not in the PIL directory, then that explains it. -bob From aperezn at yahoo.com Thu Mar 31 15:49:20 2005 From: aperezn at yahoo.com (Alejandra Pérez) Date: Thu Mar 31 15:49:23 2005 Subject: [Image-SIG] how to install pil locally Message-ID: <20050331134920.85941.qmail@web60005.mail.yahoo.com> hello everyone, I'm trying to install PIL in my server space where I don't have root access. I am not succeeding and the error I got is that permission is denied. I've spoken to my system admin and he says the problem is that I cannot tell python where to install the libraries and that I should be able to specify a local path... but I don't know where... Does this problem have a solution?. Thanks a lot in advance and hope not to bother with silly questions. Alejandra __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com From bob at redivi.com Thu Mar 31 17:18:58 2005 From: bob at redivi.com (Bob Ippolito) Date: Thu Mar 31 17:19:03 2005 Subject: [Image-SIG] how to install pil locally In-Reply-To: <20050331134920.85941.qmail@web60005.mail.yahoo.com> References: <20050331134920.85941.qmail@web60005.mail.yahoo.com> Message-ID: <289b863345dd861fa9a2677478351e7b@redivi.com> On Mar 31, 2005, at 8:49 AM, Alejandra P?rez wrote: > I'm trying to install PIL in my server space where I > don't have root access. I am not succeeding and the > error I got is that permission is denied. I've spoken > to my system admin and he says the problem is that I > cannot tell python where to install the libraries and > that I should be able to specify a local path... but I > don't know where... Does this problem have a > solution?. > Thanks a lot in advance and hope not to bother with > silly questions. The options that the distutils install command accepts can be listed like this: % python setup.py --help install Everything else you'd need to know about distutils (as a user/admin) is available here, in the documentation: http://docs.python.org/inst/inst.html -bob From mani_plus at yahoo.com Sat Mar 12 20:53:17 2005 From: mani_plus at yahoo.com (Online Support) Date: Sat Apr 9 10:52:53 2005 Subject: [Image-SIG] Installation Guide Message-ID: <20050312195315.45930.qmail@web20922.mail.yahoo.com> Hello, I'm in critical need to install Python Imaging Library on my linux/cpanel server. I'm not very experienced and I almost always have to use instalation guides. I have downloaded the software, unzipped it, and now I think I just need to install it somehow. Are there files that need to be modified first? I think there is a file called setup.py but I'm not sure how I can run that file. I would really appreciate your reply, or if you could point me to an installation giude online for PIL Best Regards, - Kevin --------------------------------- Do you Yahoo!? Yahoo! Small Business - Try our new resources site! -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/image-sig/attachments/20050312/7e798e05/attachment.htm From ndemir at demir.web.tr Thu Mar 17 23:32:44 2005 From: ndemir at demir.web.tr (Necati DEMiR) Date: Sat Apr 9 10:53:36 2005 Subject: [Image-SIG] c code to python using gd Message-ID: <423A3DB0.9080706@demir.web.tr> Hi, i converted a c code to python. two of them uses gd, but they dont have the sama output :( this is the c code; #include #include int main(){ gdImagePtr in, out; FILE *inf, *outf; int c; int i, j; int color; int red, green, blue; int p1 = (255/3); int p2 = 2 * (255/3); inf = fopen("input.png","rb"); in = gdImageCreateFromPng(inf); out = gdImageCreateTrueColor(gdImageSX(in), gdImageSY(in)); gdImageColorAllocate(out, 255, 255, 255); for (i=0;i < gdImageSX(in); i++ ){ for (j = 0; j< gdImageSY(in); j++){ c = gdImageGetPixel(in, i, j); red = gdImageRed(in, c); green = gdImageGreen(in, c); blue = gdImageBlue(in, c); if (p1 < red && red <= p2) red = 255 - red; else red = 0; if (p1< green && green <= p2) green = 255 - green; else green = 0; if (p1< blue && blue <= p2) blue = 255 - blue; else blue = 0; color = gdImageColorAllocate(out, red, green, blue); gdImageSetPixel(out, i, j, color); } } outf = fopen("output_c.png", "wb"); gdImagePng(out, outf); gdImageDestroy(in); gdImageDestroy(out); } and this is the python code; #!/usr/bin/python import gd inp = gd.image("input.png") gd.gdMaxColors = 256 * 256 * 256 print inp.getClip()[1][0]+1,inp.getClip()[1][1]+1 output = gd.image((inp.getClip()[1][0]+1,inp.getClip()[1][1]+1),True) p1 = 255+1 / 3 p2 = 2 * (255+1 / 3) for i in range(0, inp.getClip()[1][0]+1): for j in range(0, inp.getClip()[1][1]+1): red = inp.red(inp.getPixel((i,j))) green = inp.green(inp.getPixel((i,j))) blue = inp.blue(inp.getPixel((i,j))) if (red > p1 and red <= p2): red = 255 - red else: red = 0 if (green > p1 and green <= p2): green = 255 - green else: green = 0 if (blue > p1 and blue <= p2): blue = 255 - blue else: blue = 0 color = output.colorAllocate((red, green, blue)) output.setPixel((i,j),color) f=open("output_python.png","w") output.writePng(f) f.close() and i am sending the input.png, output_c.png and output_python.png. i couldn't find the problem. -- ------------------------------------------------------------- Necati DEMiR http://demir.web.tr ndemir at demir.web.tr 0xAF7F745F 8525 9E78 F4EB 1DC6 51F3 1913 BB0D 7D9A AF7F 745F ------------------------------------------------------------- -------------- next part -------------- A non-text attachment was scrubbed... Name: input.png Type: image/png Size: 314966 bytes Desc: not available Url : http://mail.python.org/pipermail/image-sig/attachments/20050317/609c34f9/input.png -------------- next part -------------- A non-text attachment was scrubbed... Name: output_c.png Type: image/png Size: 167747 bytes Desc: not available Url : http://mail.python.org/pipermail/image-sig/attachments/20050317/609c34f9/output_c.png -------------- next part -------------- A non-text attachment was scrubbed... Name: output_python.png Type: image/png Size: 521 bytes Desc: not available Url : http://mail.python.org/pipermail/image-sig/attachments/20050317/609c34f9/output_python.png From pascor at hotpop.com Thu Mar 10 17:53:10 2005 From: pascor at hotpop.com (Ray Pasco) Date: Sat Apr 9 10:54:25 2005 Subject: [Image-SIG] Re: Re: RGB conversion to CMKY gives strange results] Message-ID: <42307B61.9060200@hotpop.com> -------- Original Message -------- Subject: Re: [Image-SIG] RGB conversion to CMKY gives strange results Date: Thu, 10 Mar 2005 10:37:22 -0500 From: Ray Pasco To: Jeff Epler References: <422FCD77.7000306@hotpop.com> <20050310131618.GC6694@unpythonic.net> Jeff - Thanks for the explainations. My goal is to manipulate only the brightness or luminosity as effeciently as possible. I'm not very familiar with non-RGB colorspaces, but I can find out. Since conversions to HSV and HSL do not exist in PIL, I was hoping to manipulate the K values in the CMYK colorspace and then convert back to RGB. I know know that this is not possible since this conversion is not done correctly. I could convert to another colorspace using numeric or numarray, but this would be slow. How can the im.point() function be used for an algorithm that requires "If" statements ? The "im.point (table)" variation is undocumented and the "im.point (function) image" is variation is limited to producing only binary mode "1" images. What is that token "image" doing at the end there ? Not only that, but the existing documentation must be wrong, since both variations call for a "mode" parameter that is not used at all in the documentation's own example ! Do you know what's really going on ? Thanks, Ray Pasco Jeff Epler wrote: >The algorithm that im.convert("CMYK") uses is this: (C code) > static void > rgb2cmyk(UINT8* out, const UINT8* in, int xsize) > { > int x; > for (x = 0; x < xsize; x++) { > /* Note: no undercolour removal */ > *out++ = ~(*in++); > *out++ = ~(*in++); > *out++ = ~(*in++); > *out++ = 0; in++; > } > } >All numbers are in the inclusive range [0, 255] in this case. If "in" >was 0, then out is 255, so it's like the algorithm on the page you >mentouned for RGB->CMY, where the value 255 corresponds to 1.0, and K is >simply set to 0 all the time. > >Using numeric or numarray, it is probably possible to do the CMY->CMYK >conversion step described on the page you mentioned, and have the >resulting code run fairly quickly. > >As for conversions from RGB to other 3-component color systems, you can >use the "im.convert(mode, matrix)" function with the right matrix. An >example is in the documentation for converting to the XYZ colorspace. > >This block of code, common to many of the conversion functions on that >web page you mentioned, has to do with doing gamma conversion: > if ( var_R > 0.0031308 ) var_R = 1.055 * ( var_R ^ ( 1 / 2.4 ) ) - 0.055 > else var_R = 12.92 * var_R > if ( var_G > 0.0031308 ) var_G = 1.055 * ( var_G ^ ( 1 / 2.4 ) ) - 0.055 > else var_G = 12.92 * var_G > if ( var_B > 0.0031308 ) var_B = 1.055 * ( var_B ^ ( 1 / 2.4 ) ) - 0.055 > else var_B = 12.92 * var_B >To perform this step in PIL, you would use the im.point method with a >properly initialized table. > >Jeff > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/image-sig/attachments/20050310/3d71300b/attachment-0001.htm From Sigmund.Lahn at utdanningsdirektoratet.no Mon Mar 21 12:49:05 2005 From: Sigmund.Lahn at utdanningsdirektoratet.no (Sigmund Lahn) Date: Sat Apr 9 10:54:26 2005 Subject: [Image-SIG] Python 2.4? Message-ID: <3C80DCC2E816D94EA3D5DFA9D3B798D80512CC@OslHkBl0818.ls.no> The installer complains thet I do not have python 2.3 installed. Does this mean python 2.4 is not supported, or is the installer just outdated? Ie, should I tweak my register so that python 2.4 is also registered as 2.3? Sigmund -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/image-sig/attachments/20050321/498c14e0/attachment-0001.html From perrya at jps.net Wed Mar 30 19:38:15 2005 From: perrya at jps.net (Perry) Date: Sat Apr 9 10:54:27 2005 Subject: [Image-SIG] Re: RGB conversion to CMKY gives strange results Message-ID: <008401c5354f$414d7150$0201a8c0@Perryscomputer> Hi, I am researching the following: Is there a standard for converting a 18 bit RGB value to 24 Bit value monitor? I am trying to create graphics in pre-windows screen. Mapping RGB (0-255, 0-255,0-255) to rRGB (0-63, 0-63,0-63) is unresolved. If you know of any websites or formulas to do this, please send them, thanks! Perry -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/image-sig/attachments/20050330/e616af02/attachment-0001.htm