From c45fa6fb5d70221f1682bda76081570b89f34b33 Mon Sep 17 00:00:00 2001 From: Gilles Orban de Xivry Date: Thu, 6 Dec 2018 12:19:37 +0100 Subject: [PATCH 1/4] correction centreOfGravity: subtraction of threshold level --- aotools/image_processing/centroiders.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aotools/image_processing/centroiders.py b/aotools/image_processing/centroiders.py index 5ada4de..ac8a4a1 100644 --- a/aotools/image_processing/centroiders.py +++ b/aotools/image_processing/centroiders.py @@ -68,7 +68,7 @@ def centreOfGravity(img, threshold=0, **kwargs): """ if threshold != 0: if len(img.shape) == 2: - img = numpy.where(img>threshold*img.max(), img, 0 ) + img = numpy.where(img > threshold*img.max(), img - threshold*img.max(), 0) else: img_temp = (img.T - threshold*img.max(-1).max(-1)).T zero_coords = numpy.where(img_temp < 0) From 3e8d06b871c3270af0b489a05d890106b0e0c561 Mon Sep 17 00:00:00 2001 From: Gilles Orban de Xivry Date: Fri, 7 Dec 2018 18:09:47 +0100 Subject: [PATCH 2/4] adding an optional minimum absolute threshold to the centreOfGravity method --- aotools/image_processing/centroiders.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/aotools/image_processing/centroiders.py b/aotools/image_processing/centroiders.py index ac8a4a1..ff939bb 100644 --- a/aotools/image_processing/centroiders.py +++ b/aotools/image_processing/centroiders.py @@ -51,7 +51,7 @@ 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. @@ -66,11 +66,16 @@ def centreOfGravity(img, threshold=0, **kwargs): ndarray: Array of centroid values (2[, n]) """ + if threshold != 0: if len(img.shape) == 2: - img = numpy.where(img > threshold*img.max(), img - threshold*img.max(), 0) + thres = numpy.max((threshold*img.max(), minThreshold)) + #img = numpy.where(img > threshold*img.max(), img - threshold*img.max(), 0) + 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 - threshold*img.max(-1).max(-1)).T + img_temp = (img.T - thres).T zero_coords = numpy.where(img_temp < 0) img[zero_coords] = 0 From 190e876303edc1db516669829b63a7bef15fe3fa Mon Sep 17 00:00:00 2001 From: Gilles Orban de Xivry Date: Thu, 5 Sep 2019 16:50:09 +0200 Subject: [PATCH 3/4] remove commented code lines --- aotools/image_processing/centroiders.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/aotools/image_processing/centroiders.py b/aotools/image_processing/centroiders.py index ff939bb..d6fe6f2 100644 --- a/aotools/image_processing/centroiders.py +++ b/aotools/image_processing/centroiders.py @@ -70,11 +70,9 @@ def centreOfGravity(img, threshold=0, minThreshold=0, **kwargs): if threshold != 0: if len(img.shape) == 2: thres = numpy.max((threshold*img.max(), minThreshold)) - #img = numpy.where(img > threshold*img.max(), img - threshold*img.max(), 0) img = numpy.where(img > thres, img - thres, 0) else: thres = numpy.maximum(threshold*img.max(-1).max(-1), [minThreshold]*img.shape[0]) - #img_temp = (img.T - threshold*img.max(-1).max(-1)).T img_temp = (img.T - thres).T zero_coords = numpy.where(img_temp < 0) img[zero_coords] = 0 From e0d5627fd534046d1d0c135f31db8a64f01921d5 Mon Sep 17 00:00:00 2001 From: Gilles Orban de Xivry Date: Thu, 5 Sep 2019 16:54:35 +0200 Subject: [PATCH 4/4] adding comments --- aotools/image_processing/centroiders.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/aotools/image_processing/centroiders.py b/aotools/image_processing/centroiders.py index d6fe6f2..035ba75 100644 --- a/aotools/image_processing/centroiders.py +++ b/aotools/image_processing/centroiders.py @@ -58,9 +58,13 @@ def centreOfGravity(img, threshold=0, minThreshold=0, **kwargs): 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])