Re: [Image-SIG] Converting from "CMYK" to "RGB"

2013-07-05 Thread Kevin Cazabon
Convert does not modify the image in place : it returns a new converted image. 

Use newim = origim.convert("RGB")

Kevin

On Jun 30, 2013, at 18:29, Matti Viljamaa  wrote:

> I'm trying to handle CMYK images by converting them to RGB. I'm using the 
> following code snippet:
> 
> import sys
> from PIL import Image
> 
> def loadImage(self, imageFileName):
>imageFile = open(imageFileName)
>image = Image.open(imageFile)
> 
>if(image.mode == 'CMYK' ):
>image.convert('RGB')
> 
> However the image is not converted to RGB, although its mode is recognized as 
> CMYK.
> 
> Later when loading this image into a QImage (of the Qt GUI library), the 
> compiler produces an error indicating that the mode is still CMYK:
>ValueError: unsupported image mode 'CMYK'
> 
> So how can CMYK images be handled?
> 
> My PIL is of version 1.1.6.
> 
> ___
> Image-SIG maillist  -  Image-SIG@python.org
> http://mail.python.org/mailman/listinfo/image-sig
___
Image-SIG maillist  -  Image-SIG@python.org
http://mail.python.org/mailman/listinfo/image-sig


Re: [Image-SIG] What is the best way to anti-alias a very large resolution image in PIL

2011-09-14 Thread Kevin Cazabon
I just found an article that Fredrik wrote based on a discussion we had on 
memory limits back in 1999.  Using the .tile attribute and doing your work in 
chunks is one sure-fire way of getting there, although it'll take some effort.  
I hope this helps!

http://effbot.org/zone/pil-large-images.htm


Kevin.



On Sep 8, 2011, at 7:07 AM, Craig Coleman (C) wrote:

> Hi,
> 
> I have a really thorny problem.
> 
> I need to downsample a raster map that is 23622x23622 pixels to 7874x7874 
> pixels using the ANTIALIAS filter.
> 
> I have the following Python code:
> 
> >>> import Image 
> >>> img = Image.open(r"C:\temp\24bit_nd.tif") 
> >>> nimg = img.resize((7874,7874),Image.ANTIALIAS)
> 
> As soon as the resize method is called, python crashes instantly.  I presume 
> this is a memory allocation issue.
> 
> Is there another way of performing anti-aliasing on such a large image (its 
> 2.7GB uncompressed although I'm using LZW for storage).
> 
> I have tried converting the file to 8bit with a palette and this successfully 
> downsamples but the ANTIALIAS is not performed.  What am I doing wrong?
> 
> Craig Coleman 
> Technical Lead
> Information Systems, Ordnance Survey
> L0F2, Adanac Drive, SOUTHAMPTON, United Kingdom, SO16 0AS
> Phone: +44 (0) 2380 054641
> www.ordnancesurvey.co.uk | craig.cole...@ordnancesurvey.co.uk 
> Please consider your environmental responsibility before printing this email.
> 
> This email is only intended for the person to whom it is addressed and may 
> contain confidential information. If you have received this email in error, 
> please notify the sender and delete this email which must not be copied, 
> distributed or disclosed to any other person.
> 
> Unless stated otherwise, the contents of this email are personal to the 
> writer and do not represent the official view of Ordnance Survey. Nor can any 
> contract be formed on Ordnance Survey's behalf via email. We reserve the 
> right to monitor emails and attachments without prior notice.
> 
> Thank you for your cooperation.
> 
> Ordnance Survey
> Adanac Drive
> Southampton SO16 0AS
> Tel: 08456 050505
> http://www.ordnancesurvey.co.uk
> 
> ___
> Image-SIG maillist  -  Image-SIG@python.org
> http://mail.python.org/mailman/listinfo/image-sig

___
Image-SIG maillist  -  Image-SIG@python.org
http://mail.python.org/mailman/listinfo/image-sig


Re: [Image-SIG] What is the best way to anti-alias a very large resolution image in PIL

2011-09-14 Thread Kevin Cazabon
If its a memory issue like people have suggested, then it's still possible to do.  You could break the image into chunks, resize those, then re-assemble them.  The .tile attribute will help you.  I've personally worked with files up to about 1.5GB with PIL successfully - even on a 600mHz computer with only 2GB of RAM (back in about 2000), but I'm not sure where the limit actually is, if any.I'm looking for a good code sample to show you how to use the .tile attribute for this, but can't find any yet… the attached is pretty cryptic and horrible coding (from my "early" years :) with little useful documentation.  Fredrik really helped me understand it back then, so if you search the newsgroup archives for ".tile" you should probably find something useful.You'd have to do something like:1)  open the image2)  modify the .tile attribute so that you're only working with a portion of the image (that you can handle in memory)3)  resize the image4)  save that portion of the image5)  repeat the above for all sections of the image6)  load them all and paste the resized ones back into one smaller imageI'd suggest that you have a bit of overlap in the files though, or you'll have artifacts where you paste them together.  This is due to the resampling errors right at the edge of an image.# Build Image module by Kevin Cazabon
# Version 1.0
# Copyright 1999.  kc...@cymbolic.com

print 'Build Image version 1.0 by Kevin Cazabon.  Copyright 1999'



def build_image(imagename, crop_coords, outsize, outmode):

""" Method for 'building' an image in memory from a cropped portion of a larger file.
The advantage of this method is that the original image does NOT have to be loaded
entirely into memory at once.  Only the cropped portion, plus ONE line is held in mem.
For now, outsize MUST be the same as the total area defined by crop_coords.
    This will only work with UNCOMPRESSED image formats (BMP, TIF, etc.) 

by Kevin Cazabon kc...@cymbolic.com June/99 """

import Image

im = Image.open(imagename)
im_size = im.size
im_mode = im.mode
im_tile = im.tile

del(im)

if im_tile[0][0] == 'raw':

if outmode == 'RGB':
channels = 3
elif outmode == 'CMYK':
channels = 4
else:
channels = 3

# check if cropping is outside of real image area

pad_l = 0
pad_t = 0
pad_r = 0
pad_b = 0

if crop_coords[0] < 0:
pad_l= pad_l - crop_coords[0]
crop_coords[0] = 0
if crop_coords[1] < 0:
pad_t = pad_t - crop_coords[1]
crop_coords[1] = 0
if crop_coords[2] > im_size[0]:
pad_r = crop_coords[2] - im_size[0]
crop_coords[2] = im_size[0]
if crop_coords[3] > im_size[0]:
pad_b = crop_coords[3] - im_size[1]
crop_coords[3] = im_size[1]

# create background image at outsize

panel = Image.new(outmode, outsize)

# loop through reading image line-by-line and pasting into background

paste = 'yes'
line_num = 0

while paste == 'yes':

this_line = Image.open(imagename)
file_offset = this_line.tile[0][2] + ((crop_coords[1] + line_num)*channels*this_line.size[0]) + (crop_coords[0] * channels)
args = this_line.tile[0][3]

this_line.size = (crop_coords[2] - crop_coords[0], 1)
this_line.tile = [('raw', (0,0,this_line.size[0],1), file_offset, args)]

try:
this_line.load()
except IOError:
paste = 'no'

#this_line = this_line.crop((crop_coords[0], 0, crop_coords[2], 1))

if this_line.mode != outmode:
this_line = this_line.convert(outmode)

panel.paste(this_line, (pad_l, pad_t + line_num))

del(this_line)

line_num = line_num + 1

if line_num > panel.size[1]:
paste = 'no'

else:
print 'Image is compressed, cannot build cropped image in memory.'
return None

return panel
Title: What is the best way to anti-alias a very large resolution image in PIL
Good luck!Kevin.On Sep 8, 2011, at 7:07 AM, Craig Coleman (C) wrote:







Hi,
I have a really thorny problem.
I need to downsample a raster map that is 23622x23622 pixels to 7874x7874 pixels using the ANTIALIAS filter.
I have the following Python code:
>>> import Image

>>> im

Re: [Image-SIG] Create a 'disabled' image effect (similar to how Windows shows disabled images)

2010-12-01 Thread Kevin Cazabon
I do this in some of my work too - 

Making it black and white is one thing, but normally I'd suggest you also map 
the levels to a much narrower range (make black mid-gray, and white 
light-gray).  I simple "point" can do that:




# make the image appear "deleted"
map = []
for q in range(3):
for i in range(256):
map.append(params.get("deletedMap")[0] + 
int(((params.get("deletedMap")[1] - params.get("deletedMap")[0]) * (i/256.0)) + 
0.5))
image = image.point(map)


In my case I leave it as a color image, and the params.get simply pulls from a 
parameter class where I store my preferences for the darkest and lightest I 
want to map to.  You can always replace that line with something simple like:

map.append(int(100 + (i * 0.25) + 0.5))

which will map it down to levels 100 to 164


Kevin.




On Dec 1, 2010, at 1:45 PM, Edward Cannon wrote:

> try using the Image.convert("L") method on you image. That will make
> it greyscale
> Edward Cannon
> 
> On Wed, Dec 1, 2010 at 6:38 AM,   wrote:
>> Any suggestions on a PIL receipe that will allow me to take a color image
>> and create a grayscale version of this image that gives the image a disabled
>> appearance similar to the effect that Windows applies to show disabled
>> icons?
>> 
>> My use case is to dynamically create disabled versions of my application's
>> graphics when a specific feature is disabled or unavailable.
>> 
>> Thank you,
>> Malcolm
>> ___
>> Image-SIG maillist  -  Image-SIG@python.org
>> http://mail.python.org/mailman/listinfo/image-sig
>> 
>> 
> ___
> Image-SIG maillist  -  Image-SIG@python.org
> http://mail.python.org/mailman/listinfo/image-sig

___
Image-SIG maillist  -  Image-SIG@python.org
http://mail.python.org/mailman/listinfo/image-sig


Re: [Image-SIG] feature detection/location in images

2009-07-23 Thread Kevin Cazabon
Thanks for the input everyone - I'll check it out.  Hopefully it's  
easy to get set up and working.


Kevin.


On 14 Jul 2009, at 13:05, Chris Ps wrote:



-- Forwarded message ------
From: Kevin Cazabon 
To: image-sig@python.org
Date: Mon, 13 Jul 2009 23:31:14 -0400
Subject: [Image-SIG] feature detection/location in images
Hey everyone - does anyone have good experience in locating features  
in an image?  PilPlus used to have a "ImageCrackCode" module, but  
I've never used it or even seen it (it says no longer available).


I don't need to find _specific_ features, but need to find a small  
set of distinct features consistently in similar images (for  
aligning them together).  I can brute-force this with min/max values/ 
etc, but was hoping for some help on something more elegant and  
efficient.  Any pointers would be appreciated, thanks!


Kevin.



-- Forwarded message --
From: "Guy K. Kloss" 
To: image-sig@python.org
Date: Tue, 14 Jul 2009 16:37:21 +1200
Subject: Re: [Image-SIG] feature detection/location in images
On Tue, 14 Jul 2009 15:31:14 Kevin Cazabon wrote:
> I don't need to find specific features, but need to find a small set
> of distinct features consistently in similar images (for aligning  
them

> together).  I can brute-force this with min/max values/etc, but was
> hoping for some help on something more elegant and efficient.  Any
> pointers would be appreciated, thanks!

I've accomplished something similar using OpenCV functions that  
correlate a
template to an area and return a matrix of correlation ratings. Then  
finding
in the matrix the extreme value (max or min depending on the  
function) you can

find your "best match".

Currently I'd advise the ctypes-opencv bindings by Minh-Tri Pham to  
use the
code from Python. It's quite speedy and works well, just need to  
play a bit

with the functions to find out which works best for your case.

HTH,

Guy

--
Guy K. Kloss
Institute of Information and Mathematical Sciences
Te Kura Pūtaiao o Mōhiohio me Pāngarau
Massey University, Albany (North Shore City, Auckland)
473 State Highway 17, Gate 1, Mailroom, Quad B Building
voice: +64 9 414-0800 ext. 9585   fax: +64 9 441-8181
g.kl...@massey.ac.nz http://www.massey.ac.nz/~gkloss

I would also recommend OpenCV. I'm not familiar with the bindings by  
Minh-Tri Pham, I'm using the Python(x,y) distribution which includes  
python bindings from the original c library. Some of the functions  
are buggy and the API is rather clumsy (very c like), but I don't  
think you will have a problem. In case the functions you are looking  
for don't exist in OpenCV a solution would be to export your PIL  
image as a nd array to numpy and work with that. Dealing with numpy  
makes repetitive window based operations faster than PIL.


Christos
___
Image-SIG maillist  -  Image-SIG@python.org
http://mail.python.org/mailman/listinfo/image-sig


___
Image-SIG maillist  -  Image-SIG@python.org
http://mail.python.org/mailman/listinfo/image-sig


[Image-SIG] feature detection/location in images

2009-07-13 Thread Kevin Cazabon
Hey everyone - does anyone have good experience in locating features  
in an image?  PilPlus used to have a "ImageCrackCode" module, but I've  
never used it or even seen it (it says no longer available).


I don't need to find _specific_ features, but need to find a small set  
of distinct features consistently in similar images (for aligning them  
together).  I can brute-force this with min/max values/etc, but was  
hoping for some help on something more elegant and efficient.  Any  
pointers would be appreciated, thanks!


Kevin.
___
Image-SIG maillist  -  Image-SIG@python.org
http://mail.python.org/mailman/listinfo/image-sig


Re: [Image-SIG] Workarounds for MemoryErrors

2009-06-22 Thread Kevin Cazabon
Quite a number of years back I processed a 1.5GB image on a machine  
with 256MB of RAM (the rest virtual memory - 48x96" poster at 304  
pixels/inch).  It took days, but it worked.  The software actually was  
pretty inefficient too, so I was probably using well over 2GB of  
memory space at a time.


I think your image is about 19GB (at 24bits/pixel)... not that  
different of a ratio than what I did.  Have you tried it?  Besides  
ensuring you have lots of VM available, it might just work as-is.   
Memory is cheap these days too... probably cheaper than the hours of  
programming a work-around.


Kevin

On 22 Jun 2009, at 12:52, B. Bogart wrote:


Hello all,

I want to create a very large RGBA image (96000x72000 pixels).

I have 4GB of RAM.

Is there an easy way of getting around this error by having PIL only
allocate one section of the image at a time?

If PIL does not have any internal trick to work with large images then
I'll have to make 4+ smaller images one at a time, but then I'm not  
sure
how I could combine them without needing to allocate a memory chunk  
for

the whole image.

Otherwise I suppose I'll have to try with some other language, perhaps
C/SDL, though a quick calculation seems to show that such a large RGBA
image is just unworkable. Is there some way of using disk space rather
than memory? Does not matter if it is slow, just that it is possible!

Any advice?

Thanks,
B.
___
Image-SIG maillist  -  Image-SIG@python.org
http://mail.python.org/mailman/listinfo/image-sig


___
Image-SIG maillist  -  Image-SIG@python.org
http://mail.python.org/mailman/listinfo/image-sig


Re: [Image-SIG] [raclette] PyCMS now part of PIL

2009-03-09 Thread Kevin Cazabon
Thanks for the hard work on upgrading and integrating this Fredrik -  
I've been following your changes and it seems like quite a significant  
amount of work on your end to clean it up and streamline things.  I'm  
looking forward to playing with the in-memory profile reading, along  
with the embedded profile reading that other SIG members have been  
working on.  Having CMS in PIL will be yet another formidable tool for  
PIL and adoption in high-end applications.


In any case, I'm proud to contribute pyCMS - although it's really just  
a wrapper around Marti Maria's harder work on the LittleCMS library  
itself.


Kevin.


On 09 Mar 2009, at 13:23, Fredrik Lundh wrote:


Kevin Cazabon has graciously donated his PyCMS library to PIL, and it
landed in the "raclette" tree yesterday.  The library will
automatically be built if you have LittleCMS on the machine
(www.littlecms.com).  The Python binding is now in PIL.ImageCms.

I'm still working on a tighter integration, but the module provides
the procedural PyCMS API (with a few enhancements; you can e.g. read
profiles from memory by passing in file objects instead of filenames).
In other words, code written for pyCMS "should" still work if you
just change "import pyCMS" to

   import PIL.ImageCms as pyCMS

The internals are reworked, though, so code that rely on
implementation details, the exact phrasing of error messages (the PIL
version is less informative), or access to the pyCMSdll layer won't
work.

If you want to help out testing the integration, you can pull the
current snapshot from

   http://bitbucket.org/effbot/pil-2009-raclette/overview/

(either as a zip/tarball via the download link, or using "hg clone").

Cheers /F
___
Image-SIG maillist  -  Image-SIG@python.org
http://mail.python.org/mailman/listinfo/image-sig


___
Image-SIG maillist  -  Image-SIG@python.org
http://mail.python.org/mailman/listinfo/image-sig


Re: [Image-SIG] playing with CMYK images

2009-03-02 Thread Kevin Cazabon
The jpeg plugin doesn't handle CMYK properly - I've posted patches in  
the past... trivial to fix.


Kevin.


On 02 Mar 2009, at 14:04, Charlie Clark wrote:



Am 27.02.2009 um 19:09 schrieb Ask Holme:


Hey list

i have just tried using PIL to crop and resize CMYK images (with  
CMYK as end result, no color mode conversion). I must say i was  
surprised how awfull the result look. Even though PIL is not  
supposed to touch the color mode, colors is totally fucked up in  
the modified image.


Is that because i'm doing something wrong or is the only solution  
simply to switch to imagemagick if i want better CMYK support


wow! As someone who normally appreciates informality on mailing  
lists and relishes in the triumph of the vernacular I found this a  
rude first post.


Can you please provide some details as to what's gone so horribly  
wrong. I would be surprised if the problem is actually with PIL per  
se and not with one of the underlying C libraries.


Charlie
--
Charlie Clark
Helmholtzstr. 20
Düsseldorf
D- 40215
Tel: +49-211-938-5360
GSM: +49-178-782-6226



___
Image-SIG maillist  -  Image-SIG@python.org
http://mail.python.org/mailman/listinfo/image-sig


___
Image-SIG maillist  -  Image-SIG@python.org
http://mail.python.org/mailman/listinfo/image-sig


[Image-SIG] Fwd: PIL 1.1.6 and convert cmyk jpegs to rgb and writing png files

2008-12-12 Thread Kevin Cazabon




A couple years ago, a few of us worked on adding multi-threading  
support to key routines in PIL - focusing on the ones that would  
most likely be CPU intensive or long duration operations.  It's a  
simple fix to release the GIL before starting the op, and re-acquire  
before returning - look at the C code for resize, for example.   We  
didn't get it implemented everywhere, but many of the "expensive"  
operations are now covered.  I'm sure Fred would gladly accept  
patches to add support elsewhere.


Kevin.


On 12 Dec 2008, at 11:34, Michael van Tellingen wrote:


Hello,

I'm currently writing a webapplication which processes images  
uploaded

by users and i'm running into two problems:
- Converting a CMYK jpeg image to RGB results in the wrong colors
used, i've solved this by patching PIL with the
 file attached to
http://mail.python.org/pipermail/image-sig/2006-April/003871.html

- It seems that writing a PNG image requires the GIL. I convert all
uploaded images in a separate thread to PNG
 images and while doing so my complete python application becomes
really slow, I don't have this problem when
 I convert it to JPEG or TIFF. Is this correct? And if so, how hard
would it be to solve this problem?

Thanks,
Michael van Tellingen
___
Image-SIG maillist  -  Image-SIG@python.org
http://mail.python.org/mailman/listinfo/image-sig




___
Image-SIG maillist  -  Image-SIG@python.org
http://mail.python.org/mailman/listinfo/image-sig


Re: [Image-SIG] PIL 1.1.6 and convert cmyk jpegs to rgb and writing png files

2008-12-12 Thread Kevin Cazabon
A couple years ago, a few of us worked on adding multi-threading  
support to key routines in PIL - focusing on the ones that would most  
likely be CPU intensive or long duration operations.  It's a simple  
fix to release the GIL before starting the op, and re-acquire before  
returning - look at the C code for resize, for example.   We didn't  
get it implemented everywhere, but many of the "expensive" operations  
are now covered.  I'm sure Fred would gladly accept patches to add  
support elsewhere.


Kevin.


On 12 Dec 2008, at 11:34, Michael van Tellingen wrote:


Hello,

I'm currently writing a webapplication which processes images uploaded
by users and i'm running into two problems:
- Converting a CMYK jpeg image to RGB results in the wrong colors
used, i've solved this by patching PIL with the
  file attached to
http://mail.python.org/pipermail/image-sig/2006-April/003871.html

- It seems that writing a PNG image requires the GIL. I convert all
uploaded images in a separate thread to PNG
  images and while doing so my complete python application becomes
really slow, I don't have this problem when
  I convert it to JPEG or TIFF. Is this correct? And if so, how hard
would it be to solve this problem?

Thanks,
Michael van Tellingen
___
Image-SIG maillist  -  Image-SIG@python.org
http://mail.python.org/mailman/listinfo/image-sig


___
Image-SIG maillist  -  Image-SIG@python.org
http://mail.python.org/mailman/listinfo/image-sig


Re: [Image-SIG] Multi-threading and PIL

2008-08-06 Thread Kevin Cazabon
A couple years ago I did some work on enabling multi-threading in the  
PIL core library, with the help of Fredrik and others.  We  
successfully implemented it by releasing the GIL prior to starting  
many of the larger routines/functions in the C library, and re- 
acquiring it before handing back to the wrappers.  I can't remember  
exactly which functions we did this to in total, but it definitely  
included the Image.resize code and so forth.  On my dual-processor  
machine, I saw almost double performance on multi-threaded resizing  
operations - proving it worked.  However, we never touched the pixel  
access sections.


You could look at the resize code in the C module and use the same  
method to try it with the functions you use most.  The trick is just  
figuring out the right places to release and recapture the GIL.


Kevin.


On 06 Aug 2008, at 21:01, Sebastian Haase wrote:

For pixel-by-pixel stuff you would probably be much (!) faster using  
numpy.


- Sebastian Haase


On Wed, Aug 6, 2008 at 7:49 PM, Stani <[EMAIL PROTECTED]> wrote:
Op woensdag 06-08-2008 om 09:45 uur [tijdzone -0600], schreef  
Kristofor

Amundson:


My problem is that I see little to no improvement in my performance
with the threading, even when I process the images on a machine  
with 8

CPU's. In fact, it only seems to utilize one CPU. Is this due to the
GIL?

Probably so.


I am wondering if there is a way for me to properly thread this to
improve my performance.
I use mostly subprocess pools to increase multi-core performance,  
but of
course this might be not evident to implement depending on the  
specifics
of your software. That is the only way to take advantage of multi- 
core

CPU (or of course stackless python).

To speed up your existing code, you might also give psyco a try  
(which

is again in active development), profile your code and rewrite some
parts in cython or wait for PyPy to mature.

Stani

___
Image-SIG maillist  -  Image-SIG@python.org
http://mail.python.org/mailman/listinfo/image-sig


___
Image-SIG maillist  -  Image-SIG@python.org
http://mail.python.org/mailman/listinfo/image-sig


___
Image-SIG maillist  -  Image-SIG@python.org
http://mail.python.org/mailman/listinfo/image-sig


Re: [Image-SIG] Unsharp mask?

2008-05-16 Thread Kevin Cazabon
I wrote a module for that, but you'll have to compile it for your  
distribution.  Attached (sorry!).


I've asked Fredrik to consider adding these functions to the core PIL  
code in the past, but for some reason he's never discussed it  
further... maybe there are IP issues, I don't know.


Kevin.

# PILusm.py
# by Kevin Cazabon ([EMAIL PROTECTED], [EMAIL PROTECTED])
# copyright 2003

#This library is free software; you can redistribute it and/or
#modify it under the terms of the GNU Lesser General Public
#License as published by the Free Software Foundation; either
#version 2.1 of the License, or (at your option) any later version.
#
#This library is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
#Lesser General Public License for more details.
#
#You should have received a copy of the GNU Lesser General Public
#License along with this library; if not, write to the Free Software
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

try:
from PIL import Image
except ImportError:
import Image

import PILusm

def gblur(im, radius = None):
""" PIL_usm.gblur(im, [radius])"""

if radius == None:
radius = 5.0

if not im.mode in ["RGB", "RGBX", "RGBA", "CMYK", "L"]:
raise TypeError, "Only RGB, RGBX, RGBA, CMYK, and L mode images supported."

im.load()
imOut = Image.new(im.mode, im.size)

result = PILusm.gblur(im.im.id, imOut.im.id, float(radius))

if result[0] != 0:
raise Exception, result[1]

return imOut

def usm(im, radius = None, percent = None, threshold = None):
""" PIL_usm.usm(im, [radius, percent, threshold])"""

if radius == None:
radius = 5.0
if percent == None:
percent = 150
if threshold == None:
threshold = 3

if not im.mode in ["RGB", "RGBX", "RGBA", "CMYK", "L"]:
raise TypeError, "Only RGB, RGBX, RGBA, CMYK, and L mode images supported."

im.load()
imOut = Image.new(im.mode, im.size)

result = PILusm.usm(im.im.id, imOut.im.id, float(radius), int(percent), int(threshold))

if result[0] != 0:
raise Exception, result[1]

return imOut


if __name__ == "__main__":
im = Image.open("c:\\temp\\test.tif")

import time

start = time.time()

im1 = gblur(im, 2.0)
print "gblur done in %s seconds" %(time.time() - start)
im1.save("c:\\temp\\test_blur.tif")

start = time.time()
im2 = usm(im, 2.0, 125, 8)
print "usm done in %s seconds" %(time.time() - start)
im2.save("c:\\temp\\test_usm.tif")

#start = time.time()
#im2 = antiNoise(im, 6, 6)
#print "antiNoise done in %s seconds" %(time.time() - start)
#im2.save("c:\\temp\\test_antiNoise_c.png")








PILusm.cpp
Description: Binary data


On 16 May 2008, at 10:22, Johannes Strömberg wrote:


Hello,

Is there an unsharp mask filter in PIL (I can not find any) or can I
create it by combining other filters (that would require Gaussian blur
but I can not find that either)?

/Johannes
___
Image-SIG maillist  -  Image-SIG@python.org
http://mail.python.org/mailman/listinfo/image-sig


___
Image-SIG maillist  -  Image-SIG@python.org
http://mail.python.org/mailman/listinfo/image-sig


Re: [Image-SIG] text justification

2007-11-26 Thread Kevin Cazabon
There's nothing built into the library, but I've hacked some code in  
the past to do this - unfortunately I can't find any code which can be  
neatly extracted for you.

It's pretty straight forward though - the PIL text rendering functions  
include the ability to tell you exactly what size the finished text  
will be.  You can simply use that, then calculate how far left/right  
to move your starting point.

i.e. - if your text area is 300 pixels wide, and the text will be only  
223 pixels, to right-justify you just offset by the difference (77  
pixels).  For center justified, just offset by half that (38 or 39  
pixels).



Kevin.




On 26 Nov 2007, at 05:15, Scott Frankel wrote:

>
> I'm using PIL to render text.  Is there a way to specify left,
> center, or right justification?
>
> After setting X and Y coordinate positions, the text string, and the
> font, my text drawing line of code is this:
>
>   draw.text((xpos, ypos), text, font=font)
>
>
> Thanks in advance
> Scott
> ___
> Image-SIG maillist  -  Image-SIG@python.org
> http://mail.python.org/mailman/listinfo/image-sig

___
Image-SIG maillist  -  Image-SIG@python.org
http://mail.python.org/mailman/listinfo/image-sig