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 15, 2023
1 parent 0c8e8ae commit ebcb5cd
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 0 deletions.
39 changes: 39 additions & 0 deletions examples/example_1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
"""
This example shows how to use the STARSALIGN package to align two single channel astronomical images.
It loads two images 'ref_image.npy' and 'science_image.npy', then it uses the functions 'align()'
and 'diff()' from the STARSALIGN package to get the aligned and difference images.
Finally, it saves all the images in .png format using opencv.
https://github.com/nagonzalezf/starsalign/
"""
# Imports
import os
import cv2 as cv
import numpy as np
import starsalign as stal

# Load images
ref_image = np.load('ref_image.npy')
science_image = np.load('science_image.npy')

# Get the raw difference image
raw_diff_image = ref_image - science_image

# Use the starsalign align() function to get the aligned image
aligned_image = stal.align(ref_image, science_image)

# Use the starsalign diff() function to get the difference image
diff_image = stal.diff(ref_image, science_image)

# Create outputs folder
if not os.path.exists("example_1_outputs"):
os.makedirs("example_1_outputs")

# Write stored variables as simple .png images to visualize in explorer
cv.imwrite('example_1_outputs/001_ref_image.png', ref_image)
cv.imwrite('example_1_outputs/002_science_image.png', science_image)
cv.imwrite('example_1_outputs/003_raw_diff_image.png', raw_diff_image)
cv.imwrite('example_1_outputs/004_aligned_image.png', aligned_image)
cv.imwrite('example_1_outputs/005_diff_image.png', diff_image)
39 changes: 39 additions & 0 deletions examples/example_2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
"""
This example shows how to use the STARSALIGN package to align two single channel astronomical images.
It loads two images 'ref_image.npy' and 'science_image.npy', then it uses the functions 'ultra_align()'
and 'ultra_diff()' from the STARSALIGN package to get the aligned and difference images.
Finally, it saves all the images in .png format using opencv.
https://github.com/nagonzalezf/starsalign/
"""
# Imports
import os
import cv2 as cv
import numpy as np
import starsalign as stal

# Load images and extract small 500x500 patches for each image
ref_image = np.load('ref_image.npy')[1800:2300, 250:750]
science_image = np.load('science_image.npy')[1800:2300, 250:750]

# Get the raw difference image
raw_diff_image = ref_image - science_image

# Use the starsalign ultra_align() function to get the aligned image
aligned_image = stal.ultra_align(ref_image, science_image)

# Use the starsalign ultra_diff() function to get the difference image
diff_image = stal.ultra_diff(ref_image, science_image)

# Create outputs folder
if not os.path.exists("example_2_outputs"):
os.makedirs("example_2_outputs")

# Write stored variables as simple .png images to visualize in explorer
cv.imwrite('example_2_outputs/001_ref_image.png', ref_image)
cv.imwrite('example_2_outputs/002_science_image.png', science_image)
cv.imwrite('example_2_outputs/003_raw_diff_image.png', raw_diff_image)
cv.imwrite('example_2_outputs/004_aligned_image.png', aligned_image)
cv.imwrite('example_2_outputs/005_diff_image.png', diff_image)
Binary file added examples/ref_image.npy
Binary file not shown.
Binary file added examples/science_image.npy
Binary file not shown.

0 comments on commit ebcb5cd

Please sign in to comment.