8000 Adding option to centroider centerOfGravity by GillesOrban · Pull Request #49 · AOtools/aotools · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Adding option to centroider centerOfGravity #49

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 15, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions aotools/image_processing/centroiders.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,26 +51,33 @@ def correlation_centroid(im, ref, threshold=0., padding=1):
return centroids


def centreOfGravity(img, threshold=0, **kwargs):
def centreOfGravity(img, threshold=0, minThreshold=0, **kwargs):
"""
Centroids an image, or an array of images.
Centroids over the last 2 dimensions.
Sets all values under "threshold*max_value" to zero before centroiding
Origin at 0,0 index of img.

The value under which pixels are set to 0
is max(threshold*max_value, minThreshold)

Parameters:
img (ndarray): ([n, ]y, x) 2d or greater rank array of imgs to centroid
threshold (float): Percentage of max value under which pixels set to 0
minThreshold (float): Absolute max value under which pixels set to 0

Returns:
ndarray: Array of centroid values (2[, n])

"""

if threshold != 0:
if len(img.shape) == 2:
img = numpy.where(img>threshold*img.max(), img, 0 )
thres = numpy.max((threshold*img.max(), minThreshold))
img = numpy.where(img > thres, img - thres, 0)
else:
img_temp = (img.T - threshold*img.max(-1).max(-1)).T
thres = numpy.maximum(threshold*img.max(-1).max(-1), [minThreshold]*img.shape[0])
img_temp = (img.T - thres).T
zero_coords = numpy.where(img_temp < 0)
img[zero_coords] = 0

Expand Down
0