Re: [Image-SIG] Locate The Center of WhiteDot from a Image

2011-01-10 Thread Chris Barker

On 1/7/2011 8:26 PM, Narendra Sisodiya wrote:

If you need more math, numpy can help. Somethign like:

a = np.asarray(PIL_image)
background_color = 0
rows, cols = np.where(a <> background_color) # background color a uint32
BB = (rows.min(), rows.max(), cols.min(), cols.max())

I am unable to get what that code means ?
May you explain how I can use above code with getbbox ? Or the above
code using NumPy is alternate of getbbox method ?


It's an alternative.


IF yes, then which will be the faster ?


The only way to know is to try it, but I suspect the PIL getbox() is a 
bit faster, as I image it does it all in one C loop. numpy is doing it 
in a couple loops.


The reason to use numpy is if you want to do something more complex that 
is not directly supported by PIL.


you might want to look at the scip ndimage toolbox it has some useful stuff:

http://www.scipy.org/SciPyPackages/Ndimage

though perhaps you've solved you problem.

-Chris


--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R(206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115   (206) 526-6317   main reception

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


Re: [Image-SIG] Putting a unicode string on an ImageDraw canvas

2011-01-10 Thread Fredrik Lundh
2011/1/10 Thomas Larsen Wessel :
> Thanks :)
>
> Here is an example that shows how both draw.text and draw.textsize works, as
> long as a unicode-supported font is supplied. It also shows how to get the
> text size directly from the font object.
>
> import ImageFont, Image, ImageDraw
>
> s = u'\u0623\u0636\u0641'
>
> font = ImageFont.truetype('/host/WINDOWS/Fonts/tahoma.ttf', 12,
> encoding='unic')
> print font.getsize(s) # no problem, works fine
>
> im = Image.new('RGB', (200,200))
> draw = ImageDraw.Draw(im)
> print draw.textsize(s, font=font) #fails

Hmm. That works for me in both 1.1.7 and trunk, and I don't really see
how it can fail for you given that it ends up calling the same method
in both cases:

def textsize(self, text, font=None):
if font is None:
font = self.getfont()
return font.getsize(text)

What's the exact error?


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


Re: [Image-SIG] Putting a unicode string on an ImageDraw canvas

2011-01-10 Thread Thomas Larsen Wessel
Thanks :)

Here is an example that shows how both draw.text and draw.textsize works, as
long as a unicode-supported font is supplied. It also shows how to get the
text size directly from the font object.

import ImageFont, Image, ImageDraw

s = u'\u0623\u0636\u0641'

font = ImageFont.truetype('/host/WINDOWS/Fonts/tahoma.ttf', 12,
encoding='unic')
print font.getsize(s) # no problem, works fine

im = Image.new('RGB', (200,200))
draw = ImageDraw.Draw(im)
print draw.textsize(s, font=font) #fails




Thomas





On Mon, Jan 10, 2011 at 2:27 PM, Fredrik Lundh wrote:

> 2011/1/10 Thomas Larsen Wessel :
> > People are telling me that PIL supports unicode strings, does it? And if
> > yes, why does the following not work:
> >
> > import ImageFont, Image, ImageDraw
> > s = u'\u0623\u0636\u0641'
> > im = Image.new('RGB', (200,200))
> > draw = ImageDraw.Draw(im)
> > draw.text((40,40), s) #fails
> >
> > It results in the following exception:
> >
> > Traceback (most recent call last):
> >   File "buffer.py", line 9, in 
> > draw.text((40,40), s) #fails
> >   File "/usr/lib/python2.6/dist-packages/PIL/ImageDraw.py", line 267, in
> > text
> > mask = font.getmask(text, self.fontmode)
> > UnicodeEncodeError: 'ascii' codec can't encode characters in position
> 0-2:
> > ordinal not in range(128)
> >
> > So how, do I put this unicode string on the canvas?
>
> You'll need a font that supports Unicode, which the crappy default
> bitmap font doesn't.  Use the ImageFont module to load a suitable
> TrueType font.
>
> 
>
___
Image-SIG maillist  -  Image-SIG@python.org
http://mail.python.org/mailman/listinfo/image-sig


Re: [Image-SIG] Putting a unicode string on an ImageDraw canvas

2011-01-10 Thread Fredrik Lundh
2011/1/10 Thomas Larsen Wessel :
> People are telling me that PIL supports unicode strings, does it? And if
> yes, why does the following not work:
>
> import ImageFont, Image, ImageDraw
> s = u'\u0623\u0636\u0641'
> im = Image.new('RGB', (200,200))
> draw = ImageDraw.Draw(im)
> draw.text((40,40), s) #fails
>
> It results in the following exception:
>
> Traceback (most recent call last):
>   File "buffer.py", line 9, in 
>     draw.text((40,40), s) #fails
>   File "/usr/lib/python2.6/dist-packages/PIL/ImageDraw.py", line 267, in
> text
>     mask = font.getmask(text, self.fontmode)
> UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-2:
> ordinal not in range(128)
>
> So how, do I put this unicode string on the canvas?

You'll need a font that supports Unicode, which the crappy default
bitmap font doesn't.  Use the ImageFont module to load a suitable
TrueType font.


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


[Image-SIG] Putting a unicode string on an ImageDraw canvas

2011-01-10 Thread Thomas Larsen Wessel
People are telling me that PIL supports unicode strings, does it? And if
yes, why does the following not work:

import ImageFont, Image, ImageDraw
s = u'\u0623\u0636\u0641'
im = Image.new('RGB', (200,200))
draw = ImageDraw.Draw(im)
draw.text((40,40), s) #fails

It results in the following exception:

Traceback (most recent call last):
  File "buffer.py", line 9, in 
draw.text((40,40), s) #fails
  File "/usr/lib/python2.6/dist-packages/PIL/ImageDraw.py", line 267, in
text
mask = font.getmask(text, self.fontmode)
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-2:
ordinal not in range(128)

So how, do I put this unicode string on the canvas?

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


Re: [Image-SIG] ANN: PIL 1.2 pre-alpha (January 8, 2011)

2011-01-10 Thread Fredrik Lundh
2011/1/9 Glenn Linderman :
> On 1/7/2011 5:41 PM, Fredrik Lundh wrote:
>
> It also builds under Python 3.1 and 3.2 beta, even if
> the functionality is currently *very* limited under Python 3.X.
>
> Is there any doc that describes what does or doesn't work under 3.X?

Beyond that transcript, not much works.  Not enough to motivate
putting together a document about it, at least :)  But we're working
on it.


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