diff --git a/setup.py b/setup.py index 8f998a5..10e365f 100644 --- a/setup.py +++ b/setup.py @@ -76,7 +76,7 @@ packages = result setup (name = 'vstarstack', - version = '0.3.4', + version = '0.3.6', author='Vladislav Tsendrovskii', description = 'Stacking astrophotos', package_dir = {'vstarstack': 'src/vstarstack'}, diff --git a/src/vstarstack/library/movement/move_image.py b/src/vstarstack/library/movement/move_image.py index 6c01b9d..468bcda 100644 --- a/src/vstarstack/library/movement/move_image.py +++ b/src/vstarstack/library/movement/move_image.py @@ -128,7 +128,7 @@ def move_dataframe(dataframe: DataFrame, else: weight = np.ones(image.shape) - if channel in dataframe.links["saturation"]: + if "saturation" in dataframe.links and channel in dataframe.links["saturation"]: saturation_channel = dataframe.links["saturation"][channel] saturation, _ = dataframe.get_channel(saturation_channel) else: diff --git a/src/vstarstack/library/stars/detect.py b/src/vstarstack/library/stars/detect.py index 353ad76..651b8ee 100644 --- a/src/vstarstack/library/stars/detect.py +++ b/src/vstarstack/library/stars/detect.py @@ -15,8 +15,10 @@ import math import numpy as np import cv2 +from scipy.ndimage import gaussian_filter import imutils import imutils.contours +import matplotlib.pyplot as plt from skimage import measure @@ -42,17 +44,17 @@ def calculate_brightness(image : np.ndarray, x : int, y : int, r : int): return brightness def _threshold(image, radius, ratio, safety_threshold): - filtered = cv2.GaussianBlur(image, (2*radius+1, 2*radius+1), 0) - mask = (image > filtered*ratio + safety_threshold).astype('uint8') + filtered = gaussian_filter(image, sigma=radius) + threshold = filtered*ratio + safety_threshold*np.amax(filtered) + mask = (image > threshold).astype('uint8') return mask def _find_stars(gray_image : np.ndarray): """Find stars on image""" shape = gray_image.shape - gray_image = (gray_image.astype(np.float32) / np.amax(gray_image) * 255).astype(np.uint8) gray_image = np.clip(gray_image, 0, None) - gray_image = cv2.GaussianBlur(gray_image, (3, 3), 0) + gray_image = gaussian_filter(gray_image, sigma=2) thresh = _threshold(gray_image, _detector_cfg["THRESHOLD_BLOCK_SIZE"], _detector_cfg["THRESHOLD_COEFF"], diff --git a/src/vstarstack/tool/stars/config.py b/src/vstarstack/tool/stars/config.py index f09c148..8a4d234 100644 --- a/src/vstarstack/tool/stars/config.py +++ b/src/vstarstack/tool/stars/config.py @@ -27,6 +27,7 @@ }, "use_angles": (bool, True), "brightness_over_neighbours": (float, 2.0), + "min_brightness" : (float, 0.01), "max_compares": (int, 0), } diff --git a/src/vstarstack/tool/stars/detect.py b/src/vstarstack/tool/stars/detect.py index 57fcb97..38553b9 100644 --- a/src/vstarstack/tool/stars/detect.py +++ b/src/vstarstack/tool/stars/detect.py @@ -97,7 +97,9 @@ def run(project: vstarstack.tool.cfg.Project, argv: list): mindist = project.config.stars.describe.mindist thr_coeff = project.config.stars.brightness_over_neighbours - detect.configure_detector(thresh_coeff=thr_coeff) + thr_safety = project.config.stars.min_brightness + logger.info(f"Threshold coefficient {thr_coeff}") + detect.configure_detector(thresh_coeff=thr_coeff, safety_threshold=thr_safety) if os.path.isdir(path): _process_dir(path, jsonpath, num_stars, mindist) else: