diff --git a/src/aliby/tile/traps.py b/src/aliby/tile/traps.py index 65b21b9ce744d59bd87b2232b12b6971a05a8395..49b07a9bb696f8bad5d90daa1aecf485f1b16b9c 100644 --- a/src/aliby/tile/traps.py +++ b/src/aliby/tile/traps.py @@ -227,18 +227,3 @@ def identify_trap_locations( exclude_border=(trap_size // 3), ) return coordinates - - -############################################################### -# functions below here do not appear to be used any more -############################################################### - - -def stretch_image(image): - # FIXME Used in aliby.utils.imageViewer - image = ((image - image.min()) / (image.max() - image.min())) * 255 - minval = np.percentile(image, 2) - maxval = np.percentile(image, 98) - image = np.clip(image, minval, maxval) - image = (image - minval) / (maxval - minval) - return image diff --git a/src/aliby/utils/imageViewer.py b/src/aliby/utils/imageViewer.py index 674908128d1027fdc3ff9945a5e4f7e2c03ac388..af82ad96e8259c2d5903f06eb69b7fb25247eda9 100644 --- a/src/aliby/utils/imageViewer.py +++ b/src/aliby/utils/imageViewer.py @@ -405,3 +405,35 @@ def concat_pad(a: np.array, width, nrows): axis=1, ) ) + + +def stretch_image(image): + """ + Performs contrast stretching on an input image. + + This function takes an array-like input image and enhances its contrast by adjusting + the dynamic range of pixel values. It first scales the pixel values between 0 and 255, + then clips the values that are below the 2nd percentile or above the 98th percentile. + Finally, the pixel values are scaled to the range between 0 and 1. + + Parameters + ---------- + image : array-like + Input image. + + Returns + ------- + stretched : ndarray + Contrast-stretched version of the input image. + + Examples + -------- + FIXME: Add docs. + FIXME: GTP-generated. Confirm manually. + """ + image = ((image - image.min()) / (image.max() - image.min())) * 255 + minval = np.percentile(image, 2) + maxval = np.percentile(image, 98) + image = np.clip(image, minval, maxval) + image = (image - minval) / (maxval - minval) + return image