weighted average for label_region [message #56389] |
Wed, 24 October 2007 08:17  |
rpertaub@gmail.com
Messages: 43 Registered: January 2007
|
Member |
|
|
Hi,
I need to perfect a working algorithm to make it more accurate. I have
an image that consists of many spots. I need to find where the center
of each spot is. This is the algorithm I am using:
ncol=image_size[0]
regions = label_region(SpotsMask, /All_NEIGHBORS)
n_spots=max(regions)
print,"There are",n_spots," spots on image"
window,4,xsize=image_size[0],ysize=image_size[1], title="Positions of
Spots on Image"
tvscl,final_image
temp=0
spotscoord = make_array(2,n_spots)
for j = 1, n_spots DO BEGIN
ind = where(regions eq j, count)
spotscoord[0,temp]=(mean(ind) mod nCol)
spotscoord[1,temp]=(mean(ind) / nCol)
temp=temp+1
endfor
This leaves me with my spotscoord array with x,y coordinates. However,
I need to find the center of each spot with some weighted
average...i.e. if the cluster of pixels (for one spot) is more bright
on one side, then the center will be skewed there...is there a way for
me to do that?
Thanks,
RP
|
|
|
Re: weighted average for label_region [message #56529 is a reply to message #56389] |
Wed, 24 October 2007 14:01  |
ben.bighair
Messages: 221 Registered: April 2007
|
Senior Member |
|
|
On Oct 24, 11:17 am, "rpert...@gmail.com" <rpert...@gmail.com> wrote:
> Hi,
> I need to perfect a working algorithm to make it more accurate. I have
> an image that consists of many spots. I need to find where the center
> of each spot is. This is the algorithm I am using:
>
> ncol=image_size[0]
> regions = label_region(SpotsMask, /All_NEIGHBORS)
> n_spots=max(regions)
> print,"There are",n_spots," spots on image"
> window,4,xsize=image_size[0],ysize=image_size[1], title="Positions of
> Spots on Image"
> tvscl,final_image
>
> temp=0
> spotscoord = make_array(2,n_spots)
>
> for j = 1, n_spots DO BEGIN
> ind = where(regions eq j, count)
> spotscoord[0,temp]=(mean(ind) mod nCol)
> spotscoord[1,temp]=(mean(ind) / nCol)
> temp=temp+1
> endfor
>
> This leaves me with my spotscoord array with x,y coordinates. However,
> I need to find the center of each spot with some weighted
> average...i.e. if the cluster of pixels (for one spot) is more bright
> on one side, then the center will be skewed there...is there a way for
> me to do that?
>
> Thanks,
> RP
Hi,
I think you want to weight in your sportscoord calculation by the
(presumably) grayscale value of the original image pixels for that
blob. Brighter pixels will carry more weight. I don't know if it is
the correct term, but I call this "center of mass" as opposed to the
unweighted "centroid". Thus you would change
spotscoord[0,temp]=(mean(ind) mod nCol)
to
spotscoord[0,temp]=mean((ind mod nCol) * origImage[ind])
Cheers,
Ben
|
|
|