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

Chris Mitchell chris.mit7 at gmail.com
Sat Jan 8 20:41:01 CET 2011


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
<narendra at narendrasisodiya.com> wrote:
>
>
> On Sat, Jan 8, 2011 at 1:44 AM, Christopher Barker <Chris.Barker at noaa.gov>
> 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 2-3 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 opencv-python. How we can compare
> python PIL with OpenCV ? My guess that PIL will is faster then opencv
> library ?
>
>
> _______________________________________________
> Image-SIG maillist  -  Image-SIG at python.org
> http://mail.python.org/mailman/listinfo/image-sig
>
>


More information about the Image-SIG mailing list