|
| 1 | +#!/usr/bin/env python3 |
| 2 | +""" |
| 3 | +# Author : Saif Aati |
| 4 | +# Contact: SAIF AATI <saif@caltech.edu> <saifaati@gmail.com> |
| 5 | +# Copyright (C) 2023 |
| 6 | +""" |
| 7 | +import argparse |
| 8 | + |
| 9 | +from geoCosiCorr3D.geoCore.constants import CORR_METHODS, SOFTWARE |
| 10 | +from geoCosiCorr3D.geoCosiCorr3dLogger import geoCosiCorr3DLog |
| 11 | +from geoCosiCorr3D.geoImageCorrelation.correlate import Correlate |
| 12 | + |
| 13 | + |
| 14 | +def main(): |
| 15 | + parser = argparse.ArgumentParser(description="Run image correlation.") |
| 16 | + parser.add_argument("--base_image", type=str, required=True, help="Path to the base image.") |
| 17 | + parser.add_argument("--target_image", type=str, required=True, help="Path to the target image.") |
| 18 | + parser.add_argument("--base_band", type=int, default=1, help="Base image band.") |
| 19 | + parser.add_argument("--target_band", type=int, default=1, help="Target image band.") |
| 20 | + parser.add_argument("--output_path", type=str, default=SOFTWARE.WKDIR, help="Output correlation path.") |
| 21 | + parser.add_argument("--method", type=str, |
| 22 | + choices=[CORR_METHODS.FREQUENCY_CORR.value, CORR_METHODS.SPATIAL_CORR.value], required=True, |
| 23 | + help="Correlation method to use.") |
| 24 | + parser.add_argument("--window_size", type=int, nargs=4, default=[64, 64, 64, 64], |
| 25 | + help="Window size. (Default [64])") |
| 26 | + parser.add_argument("--step", type=int, nargs=2, default=[8, 8], help="Step size. (Default [8,8])") |
| 27 | + parser.add_argument("--grid", action="store_true", help="Use grid.") |
| 28 | + parser.add_argument("--show", action="store_true", help="Show correlation. (Default False)") |
| 29 | + parser.add_argument("--pixel_based", action="store_true", help="Enable pixel-based correlation.") |
| 30 | + parser.add_argument("--vmin", type=float, default=-1, help="Minimum value for correlation plot. (Default -1)") |
| 31 | + parser.add_argument("--vmax", type=float, default=1, help="Maximum value for correlation plot.(Default 1)") |
| 32 | + |
| 33 | + # Specific arguments for frequency method |
| 34 | + freq_group = parser.add_argument_group("Frequency method arguments") |
| 35 | + freq_group.add_argument("--mask_th", type=float, default=0.95, help="Mask threshold (only for frequency method).") |
| 36 | + freq_group.add_argument("--nb_iters", type=int, default=4, help="Number of iterations (only for frequency method).") |
| 37 | + |
| 38 | + # Specific arguments for spatial method |
| 39 | + spatial_group = parser.add_argument_group("Spatial method arguments") |
| 40 | + spatial_group.add_argument("--search_range", type=int, nargs=2, help="Search range (only for spatial method).") |
| 41 | + |
| 42 | + args = parser.parse_args() |
| 43 | + |
| 44 | + corr_config = {} |
| 45 | + |
| 46 | + if args.method == CORR_METHODS.FREQUENCY_CORR.value: |
| 47 | + corr_config = { |
| 48 | + "correlator_name": CORR_METHODS.FREQUENCY_CORR.value, |
| 49 | + "correlator_params": { |
| 50 | + "window_size": args.window_size, |
| 51 | + "step": args.step, |
| 52 | + "grid": args.grid, |
| 53 | + "mask_th": args.mask_th, |
| 54 | + "nb_iters": args.nb_iters |
| 55 | + } |
| 56 | + } |
| 57 | + elif args.method == CORR_METHODS.SPATIAL_CORR.value: |
| 58 | + corr_config = { |
| 59 | + "correlator_name": CORR_METHODS.SPATIAL_CORR.value, |
| 60 | + "correlator_params": { |
| 61 | + "window_size": args.window_size, |
| 62 | + "step": args.step, |
| 63 | + "grid": args.grid, |
| 64 | + "search_range": args.search_range |
| 65 | + } |
| 66 | + } |
| 67 | + |
| 68 | + Correlate(base_image_path=args.base_image, |
| 69 | + target_image_path=args.target_image, |
| 70 | + base_band=args.base_band, |
| 71 | + target_band=args.target_band, |
| 72 | + output_corr_path=args.output_path, |
| 73 | + corr_config=corr_config, |
| 74 | + corr_show=args.show, |
| 75 | + pixel_based_correlation=args.pixel_based, |
| 76 | + vmin=args.vmin, |
| 77 | + vmax=args.vmax |
| 78 | + ) |
| 79 | + |
| 80 | + |
| 81 | +if __name__ == "__main__": |
| 82 | + geoCosiCorr3DLog("image_correlation") |
| 83 | + main() |
0 commit comments