From 535287a23248de10deb1f6da9bd3e009301266a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Al=C3=A1n=20Mu=C3=B1oz?= <alan.munoz@ed.ac.uk> Date: Tue, 14 Feb 2023 13:04:09 +0000 Subject: [PATCH] refactor/docs(utils): move and autodoc stretch_img --- src/aliby/tile/traps.py | 15 --------------- src/aliby/utils/imageViewer.py | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 15 deletions(-) diff --git a/src/aliby/tile/traps.py b/src/aliby/tile/traps.py index 65b21b9c..49b07a9b 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 67490812..af82ad96 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 -- GitLab