Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
nagonzalezf authored Jan 17, 2023
1 parent 3789280 commit 304eca7
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions starsalign/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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.
Expand All @@ -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)
Expand Down Expand Up @@ -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

0 comments on commit 304eca7

Please sign in to comment.