From 304eca7d96c0f5ee06d5fc3f33c82f2386253525 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Gonz=C3=A1lez=20Figueroa?= Date: Tue, 17 Jan 2023 17:09:56 -0300 Subject: [PATCH] Add files via upload --- starsalign/__init__.py | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/starsalign/__init__.py b/starsalign/__init__.py index 8345d9c..5d7fece 100644 --- a/starsalign/__init__.py +++ b/starsalign/__init__.py @@ -27,7 +27,7 @@ Warning: Using the align() and diff() functions on high-density information and high-resolution images may result in prolonged waiting times. """ -__version__ = "1.0.13" +__version__ = "1.1.0" import os import cv2 as cv @@ -40,6 +40,8 @@ def fast_align(ref_image: np.ndarray, science_image: np.ndarray) -> np.ndarray: === Aligns the science_image to the reference image by finding keypoints and matching them using SIFT algorithm, then finds the homography between the two images, and applies a perspective warp to align the science_image. + The function takes in two input images, a reference image and a science image, and aligns the science image to the reference image. + Parameters: ref_image (np.ndarray): The reference image, to which the science_image will be aligned. science_image (np.ndarray): The science image that will be aligned to the reference image. @@ -93,6 +95,8 @@ def align(ref_image: np.ndarray, science_image: np.ndarray) -> np.ndarray: === A more advanced version of the fast_align() function that holds more information to perform the calculations, which results in a more precise alignment. + The function takes in two input images, a reference image and a science image, and aligns the science image to the reference image. + Parameters: ref_image (np.ndarray): The reference image, to which the science_image will be aligned. science_image (np.ndarray): The science image that will be aligned to the reference image. @@ -107,7 +111,7 @@ def align(ref_image: np.ndarray, science_image: np.ndarray) -> np.ndarray: """ with tempfile.NamedTemporaryFile(suffix='.png', delete=False) as ref_buffer: cv.imwrite(ref_buffer.name, ref_image) - ref_image_uint8 = cv.imread(ref_buffer.name) + ref_image_uint8 = cv.imread(ref_buffer.name) with tempfile.NamedTemporaryFile(suffix='.png', delete=False) as science_buffer: cv.imwrite(science_buffer.name, science_image) @@ -202,4 +206,30 @@ def diff(ref_image, science_image): return diff_image +def normalize(image: np.ndarray) -> np.ndarray: + """ + This function that takes in a single input argument image. + + The function calculates the mean and standard deviation of the pixel values in the image using the np.mean() and np.std() functions, respectively. + + It then normalize the image by subtracting the mean from all pixels of the image and then dividing by the standard deviation. + + This can be useful in cases where the images have different brightness levels. + + Parameters: + image (np.ndarray): The input image. + + Returns: + np.ndarray: The normalized image. + + Example: + === + >>> import starsalign as sa + >>> normalized_image = sa.normalize(image) + """ + mean = np.mean(image) + std = np.std(image) + normalized_image = (image - mean) / std + return normalized_image + # https://github.com/nagonzalezf/starsalign \ No newline at end of file