[Tutor] 200 dollar questions!
Luke Paireepinart
rabidpoobear at gmail.com
Sun Jul 1 05:32:29 CEST 2007
elis aeris wrote:
> Yes, I am trying to write a OCR algorithm with neural network, but the
> theories of NN is of little importance, what I am trying to get ready
> for the project is run speed.
Yes, but what you're trying to do _is_ important.
Example code that just loops over a small part of an image doesn't give
us indication of what you're trying to do.
For example - consider your image is 1024x768 but you only want to
process 100x100 block of it.
Then a good solution might be to use the image.crop method to reduce the
image to only the part you care about,
and then doing a getdata() on it,
versus doing getpixel for every pixel in the 100x100 area.
>
>
> the problem comes in a number of ways:
>
>
> first, as you mentioned, image.getpixel is not very fast,
> according to PIL
> http://www.pythonware.com/products/pil/
>
> so an alternative should be searched for,
>
>
> also, I loop (x,y)
>
> x = 0 -1023
> y = 0- 768 through
>
> and currently i use this:
>
>
>
> x = 0
> y = 0
> for x in xrange(1, 1024, 1):
> for y in xrange(1, 768, 1):
> rgb = image.getpixel ((10, 12))
These loops don't go 0-1023 and 0-768
they go
1-1023 and 1-767
There is a function called getdata() that you can use to get all of the
pixel data of the image at once.
-Luke
More information about the Tutor
mailing list