

Dear All, the given image has only two level. Pixel are either black or white. See this image  http://www.flickr.com/photos/nsisodiya/5333747510/
Now, I want to locate the center of whitedot. This can be done by locating the bounding box of white dot. I have used following algorithm https://gist.github.com/769847
This Code Look for bounding box which I am calculating by scanning each row and column one by one. If I am finding any white pixel, I am including it into my bounding box. After this, I can calculating mid of box. Now, Here is the problem with the code.
1) there may a change that 2 or more WhiteDOT may present. One is Big whiedot and other are very smaller whitedot(just 23 pixel) near to this Big whitedot. So, I am getting bigger bounding box. I want to get center based on density of whitepixel. basically center where white pixel density is very high. Also, I am applying this algorithm on every frame taken from camera at 2fps. So I want a high speed algorithm. PIL must be having some function or trick to do it.
 ┌─────────────────────────┐ │ Narendra Sisodiya │ http://narendrasisodiya.com└─────────────────────────┘
_______________________________________________
ImageSIG maillist  [hidden email]
http://mail.python.org/mailman/listinfo/imagesig


On 1/7/11 10:14 AM, Narendra Sisodiya wrote:
> This Code Look for bounding box which I am calculating by scanning each
> row and column one by one. If I am finding any white pixel, I am
> including it into my bounding box.
> 1) there may a change that 2 or more WhiteDOT may present. One is Big
> whiedot and other are very smaller whitedot(just 23 pixel) near to this
> Big whitedot.
Not sure about this one off the top of myhead, but I"d suspect some
smoothing may take care of it.
> I am applying this
> algorithm on every frame taken from camera at 2fps. So I want a high
> speed algorithm. PIL must be having some function or trick to do it.
The Image..getbbox() method should do it.
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())
Chris

Christopher Barker, Ph.D.
Oceanographer
Emergency Response Division
NOAA/NOS/OR&R (206) 5266959 voice
7600 Sand Point Way NE (206) 5266329 fax
Seattle, WA 98115 (206) 5266317 main reception
[hidden email]
_______________________________________________
ImageSIG maillist  [hidden email]
http://mail.python.org/mailman/listinfo/imagesig


Narendra Sisodiya wrote:
> Now, I want to locate the center of whitedot.
> I want to get center based on density of whitepixel. basically
center where white pixel density is very high.
> Also, I am applying this algorithm on every frame taken from
camera at 2fps. So I want a high speed algorithm.
I would recommend using the getbbox() method, as Christopher Barker
has already pointed out, along with one of these two techniques:
a) shrinking the size of the image to, say, 16x16, so that the
smaller 'noise' dots disappear or turn into small grey dots, and then
apply, or reapply, the 'point' method discussed in an earlier thread
to erase them;
b) using a 'centroid' algorithm to determine a 'center of mass' which
would not be affected much by small amounts of 'noise'.
Fred Lundh had kindly provided this list with such an algorithm, here:
http://mail.python.org/pipermail/imagesig/2008August/005149.htmlI use both methods in my application  detection of cars on a
racetrack for timing and scoring purposes  with good results, and
with no performance problems when processing larger images at 10 frames/second.
Garrett Davis
_______________________________________________
ImageSIG maillist  [hidden email]
http://mail.python.org/mailman/listinfo/imagesig


use numpy. This is taken from a data analysis program I wrote for
analyzing single molecule fluorescent events. So should be similar to
what you want, a white spot of a given intensity surrounded by noise.
array being your image stored as a numpy array, threshhold is your
value to be greater then
self.thresharray = np.where(array>threshhold,array, 0)
for i,v in np.ndenumerate(self.thresharray):
# print i,v
if v > 0:
#find the outside to draw our box around, look
around and color the outside of it green
for k in xrange(2,2):
for j in xrange(2,2):
try:
if self.thresharray[i[0]k,i[1]j] == 0:
picture.SetRGB(i[1]j,i[0]k,0,255,0)
except wx._core.PyAssertionError:
pass
except IndexError:
pass
On Fri, Jan 7, 2011 at 6:41 PM, Garrett Davis < [hidden email]> wrote:
> Narendra Sisodiya wrote:
>
>> Now, I want to locate the center of whitedot.
>> I want to get center based on density of whitepixel. basically center
>> where white pixel density is very high.
>> Also, I am applying this algorithm on every frame taken from camera at
>> 2fps. So I want a high speed algorithm.
>
> I would recommend using the getbbox() method, as Christopher Barker has
> already pointed out, along with one of these two techniques:
>
> a) shrinking the size of the image to, say, 16x16, so that the smaller
> 'noise' dots disappear or turn into small grey dots, and then apply, or
> reapply, the 'point' method discussed in an earlier thread to erase them;
>
> b) using a 'centroid' algorithm to determine a 'center of mass' which would
> not be affected much by small amounts of 'noise'.
>
> Fred Lundh had kindly provided this list with such an algorithm, here:
> http://mail.python.org/pipermail/imagesig/2008August/005149.html>
> I use both methods in my application  detection of cars on a racetrack for
> timing and scoring purposes  with good results, and with no performance
> problems when processing larger images at 10 frames/second.
>
> Garrett Davis
>
>
> _______________________________________________
> ImageSIG maillist  [hidden email]
> http://mail.python.org/mailman/listinfo/imagesig>
_______________________________________________
ImageSIG maillist  [hidden email]
http://mail.python.org/mailman/listinfo/imagesig


On Sat, Jan 8, 2011 at 1:44 AM, Christopher Barker <[hidden email]> wrote:
On 1/7/11 10:14 AM, Narendra Sisodiya wrote:
This Code Look for bounding box which I am calculating by scanning each
row and column one by one. If I am finding any white pixel, I am
including it into my bounding box.
1) there may a change that 2 or more WhiteDOT may present. One is Big
whiedot and other are very smaller whitedot(just 23 pixel) near to this
Big whitedot.
Not sure about this one off the top of myhead, but I"d suspect some smoothing may take care of it.
I am applying this
algorithm on every frame taken from camera at 2fps. So I want a high
speed algorithm. PIL must be having some function or trick to do it.
The Image..getbbox() method should do it.
Thanks, I tried getbbox on wrong image. Now I am using getbbox and I am getting proper result that too very fast.
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 ? IF yes, then which will be the faster ?
PS: I have looked at centroid algorithm, It is again going at pixel level and that will be slow. My application will become better with faster centroid algorithm. Also I have another question ! I am grabbing image from camera using opencvpython. How we can compare python PIL with OpenCV ? My guess that PIL will is faster then opencv library ?
_______________________________________________
ImageSIG maillist  [hidden email]
http://mail.python.org/mailman/listinfo/imagesig


This uses numpy, for a centroid algorithm you can do this:
data is your array of values within the box
ul means upper left of your box
xind = ul[1]+np.indices(np.shape(data))[1]
yind = ul[0]+np.indices(np.shape(data))[0]
x = (xind*data).sum()/float(data.sum())
y = (yind*data).sum()/float(data.sum())
On Fri, Jan 7, 2011 at 11:26 PM, Narendra Sisodiya
< [hidden email]> wrote:
>
>
> On Sat, Jan 8, 2011 at 1:44 AM, Christopher Barker < [hidden email]>
> wrote:
>>
>> On 1/7/11 10:14 AM, Narendra Sisodiya wrote:
>>>
>>> This Code Look for bounding box which I am calculating by scanning each
>>> row and column one by one. If I am finding any white pixel, I am
>>> including it into my bounding box.
>>
>>> 1) there may a change that 2 or more WhiteDOT may present. One is Big
>>> whiedot and other are very smaller whitedot(just 23 pixel) near to this
>>> Big whitedot.
>>
>> Not sure about this one off the top of myhead, but I"d suspect some
>> smoothing may take care of it.
>>
>>> I am applying this
>>> algorithm on every frame taken from camera at 2fps. So I want a high
>>> speed algorithm. PIL must be having some function or trick to do it.
>>
>> The Image..getbbox() method should do it.
>>
>
> Thanks, I tried getbbox on wrong image. Now I am using getbbox and I am
> getting proper result that too very fast.
>
>>
>> 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 ?
> IF yes, then which will be the faster ?
>
> PS: I have looked at centroid algorithm, It is again going at pixel level
> and that will be slow. My application will become better with faster
> centroid algorithm.
>
>
> Also I have another question !
> I am grabbing image from camera using opencvpython. How we can compare
> python PIL with OpenCV ? My guess that PIL will is faster then opencv
> library ?
>
>
> _______________________________________________
> ImageSIG maillist  [hidden email]
> http://mail.python.org/mailman/listinfo/imagesig>
>
_______________________________________________
ImageSIG maillist  [hidden email]
http://mail.python.org/mailman/listinfo/imagesig


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/Ndimagethough perhaps you've solved you problem.
Chris

Christopher Barker, Ph.D.
Oceanographer
Emergency Response Division
NOAA/NOS/OR&R (206) 5266959 voice
7600 Sand Point Way NE (206) 5266329 fax
Seattle, WA 98115 (206) 5266317 main reception
[hidden email]
_______________________________________________
ImageSIG maillist  [hidden email]
http://mail.python.org/mailman/listinfo/imagesig


I need to do this too. Could you possibly keep the list updated with your findings? On Fri, Jan 7, 2011 at 8:26 PM, Narendra Sisodiya <[hidden email]> wrote:
On Sat, Jan 8, 2011 at 1:44 AM, Christopher Barker <[hidden email]> wrote:
On 1/7/11 10:14 AM, Narendra Sisodiya wrote:
This Code Look for bounding box which I am calculating by scanning each
row and column one by one. If I am finding any white pixel, I am
including it into my bounding box.
1) there may a change that 2 or more WhiteDOT may present. One is Big
whiedot and other are very smaller whitedot(just 23 pixel) near to this
Big whitedot.
Not sure about this one off the top of myhead, but I"d suspect some smoothing may take care of it.
I am applying this
algorithm on every frame taken from camera at 2fps. So I want a high
speed algorithm. PIL must be having some function or trick to do it.
The Image..getbbox() method should do it.
Thanks, I tried getbbox on wrong image. Now I am using getbbox and I am getting proper result that too very fast.
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 ? IF yes, then which will be the faster ?
PS: I have looked at centroid algorithm, It is again going at pixel level and that will be slow. My application will become better with faster centroid algorithm.
Also I have another question ! I am grabbing image from camera using opencvpython. How we can compare python PIL with OpenCV ? My guess that PIL will is faster then opencv library ?
_______________________________________________
ImageSIG maillist  [hidden email]
http://mail.python.org/mailman/listinfo/imagesig
_______________________________________________
ImageSIG maillist  [hidden email]
http://mail.python.org/mailman/listinfo/imagesig


2011/1/8 Narendra Sisodiya < [hidden email]>:
> PS: I have looked at centroid algorithm, It is again going at pixel level
> and that will be slow. My application will become better with faster
> centroid algorithm.
Well, you only have to process the part of the image that contains
your dot. If it occupies 10% of the image, it'll run 100 times faster
than an algorithm that processes the entire image.
> Also I have another question !
> I am grabbing image from camera using opencvpython. How we can compare
> python PIL with OpenCV ? My guess that PIL will is faster then opencv
> library ?
OpenCV is a machine vision library, so I assume that you'll find a lot
of useful vision algorithms in there. PIL is more of a general
purpose library; lots of people use it in conjunction with more
specialized libraries.
</F>
_______________________________________________
ImageSIG maillist  [hidden email]
http://mail.python.org/mailman/listinfo/imagesig

