diff --git a/imgcorrect/corrections.py b/imgcorrect/corrections.py index 1140acc..554ada1 100644 --- a/imgcorrect/corrections.py +++ b/imgcorrect/corrections.py @@ -176,6 +176,7 @@ def compute_reflectance_correction( else: band_df["ils_scaling_factor"] = 1 + band_df.to_csv("D:\\Stitching\\Datasets\\CS-25318\\band_df.csv", index=False) band_df["slope_coefficient"] = ( band_df.apply(lambda row: _get_band_coeff(row), axis=1) / (band_df.mean_reflectance / band_df.autoexposure) diff --git a/imgcorrect/detect_panel.py b/imgcorrect/detect_panel.py index ea3ce93..2731ac5 100644 --- a/imgcorrect/detect_panel.py +++ b/imgcorrect/detect_panel.py @@ -64,6 +64,46 @@ def extract_panel_bounds(image): dictionary = cv.aruco.Dictionary_get(cv.aruco.DICT_6X6_250) corners, ids, rejected_img_points = cv.aruco.detectMarkers(image, dictionary) + # --- CORE CORRECTION FOR NIR DETECTION --- + # 1. Ensure we are working with a clean, single-channel grayscale copy + if len(image.shape) == 3: + gray = cv.cvtColor(image, cv.COLOR_BGR2GRAY) + else: + gray = image.copy() + + # 2. Fix Sentera's dynamic range squash bug across ALL bands + if gray.max() > gray.min(): + gray = cv.normalize(gray, None, 0, 255, cv.NORM_MINMAX) + + # 3. Setup ArUco dictionary and standard parameters + try: + dictionary = cv.aruco.Dictionary_get(cv.aruco.DICT_6X6_250) + parameters = cv.aruco.DetectorParameters_create() + except AttributeError: + dictionary = cv.aruco.getPredefinedDictionary(cv.aruco.DICT_6X6_250) + parameters = cv.aruco.DetectorParameters() + + # --- ATTEMPT 1: Standard Search (Optimized for Red Edge, Red, Green, Blue) --- + corners, ids, rejected_img_points = cv.aruco.detectMarkers( + gray, dictionary, parameters=parameters + ) + + # --- ATTEMPT 2: Aggressive Search Fallback (Only triggers if Attempt 1 fails, e.g., NIR) --- + if ids is None: + # Fine-tune thresholds to look for faint, low-contrast ink borders + parameters.adaptiveThreshConstant = 4 + parameters.adaptiveThreshWinSizeMax = 33 + parameters.adaptiveThreshWinSizeStep = 5 + + # Apply CLAHE local enhancement to pop out the invisible NIR lines + clahe = cv.createCLAHE(clipLimit=3.0, tileGridSize=(8, 8)) + enhanced_gray = clahe.apply(gray) + + corners, ids, rejected_img_points = cv.aruco.detectMarkers( + enhanced_gray, dictionary, parameters=parameters + ) + # --- END OF CORRECTION CODE --- + # if at least one marker detected if ids is not None and ( ids[0][0] == 23 or ids[0][0] == 63 or ids[0][0] == 217 or ids[0][0] == 220 diff --git a/pyproject.toml b/pyproject.toml index c5305c7..c513a0a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "imgcorrect" -version = "2.1.4" +version = "2.1.5" description = "Library to perform various corrections on imagery from supported sensors" authors = ["Samuel Williams ", "Joseph Franck "]