diff --git a/cli.py b/cli.py index 7d6bfb2..28c84f4 100644 --- a/cli.py +++ b/cli.py @@ -35,7 +35,8 @@ def process(self, masker: Masker): return masker.process(max_workers=self.max_workers, callback=lambda _: progress.update(), err_callback=self._err_callback) - def rgb(self, img_dir: str, out_dir: str, thresholds: List[float] = (1, 1, 0.875), pixel_buffer: int = 0) -> None: + def rgb_threshold(self, img_dir: str, out_dir: str, thresholds: List[float] = (1, 1, 0.875), + pixel_buffer: int = 0) -> None: """Generate masks for glint regions in RGB imagery using Tom Bell's binning algorithm. Parameters @@ -58,8 +59,8 @@ def rgb(self, img_dir: str, out_dir: str, thresholds: List[float] = (1, 1, 0.875 """ self.process(RGBThresholdMasker(img_dir, out_dir, thresholds, pixel_buffer)) - def dji_p4ms(self, img_dir: str, out_dir: str, thresholds: List[float] = (0.875, 1, 1, 1, 1), - pixel_buffer: int = 0) -> None: + def p4ms_threshold(self, img_dir: str, out_dir: str, thresholds: List[float] = (0.875, 1, 1, 1, 1), + pixel_buffer: int = 0) -> None: """Generate masks for glint regions in multispectral imagery from the DJI camera using Tom Bell's algorithm on the Blue image band. @@ -83,8 +84,8 @@ def dji_p4ms(self, img_dir: str, out_dir: str, thresholds: List[float] = (0.875, """ self.process(P4MSThresholdMasker(img_dir, out_dir, thresholds, pixel_buffer)) - def micasense_rededge(self, img_dir: str, out_dir: str, thresholds: List[float] = (0.875, 1, 1, 1, 1), - pixel_buffer: int = 0) -> None: + def micasense_threshold(self, img_dir: str, out_dir: str, thresholds: List[float] = (0.875, 1, 1, 1, 1), + pixel_buffer: int = 0) -> None: """Generate masks for glint regions in multispectral imagery from the Micasense camera using Tom Bell's algorithm on the blue image band. @@ -139,3 +140,14 @@ def rgb_ratio(self, img_dir: str, out_dir: str, percent_diffuse: float = 0.95, t if __name__ == '__main__': fire.Fire(CLI) + + # masker = MicasenseRedEdgeThresholdMasker("/media/taylor/Samsung_T5/Datasets/ExampleImages/MicasenseRededge", "/tmp", + # thresholds=(0.7, 0.7, 0.7, 0.7, 0.7)) + # masker.process(callback=lambda paths: print(paths)) + # + # masker = P4MSThresholdMasker("/media/taylor/Samsung_T5/Datasets/ExampleImages/P4MS", "/tmp", + # thresholds=(0.7, 0.7, 0.7, 0.7, 0.7)) + # masker.process(callback=lambda paths: print(paths)) + # + # masker = RGBThresholdMasker("/media/taylor/Samsung_T5/Datasets/ExampleImages/RGB", "/tmp") + # masker.process(callback=lambda paths: print(paths)) diff --git a/core/__init__.py b/core/__init__.py index 078f13c..698d8b1 100644 --- a/core/__init__.py +++ b/core/__init__.py @@ -4,3 +4,9 @@ Date: 2020-09-18 Description: """ + +from .maskers import Masker, MicasenseRedEdgeIntensityRatioMasker, MicasenseRedEdgeThresholdMasker, \ + P4MSIntensityRatioMasker, P4MSThresholdMasker, RGBIntensityRatioMasker, RGBThresholdMasker + +__all__ = ["Masker", "RGBThresholdMasker", "P4MSThresholdMasker", "MicasenseRedEdgeThresholdMasker", + "RGBIntensityRatioMasker", "P4MSIntensityRatioMasker", "MicasenseRedEdgeIntensityRatioMasker"] diff --git a/core/image_loaders.py b/core/image_loaders.py index b9928ca..1585708 100644 --- a/core/image_loaders.py +++ b/core/image_loaders.py @@ -13,7 +13,7 @@ import numpy as np from PIL import Image -from core.utils import list_images, normalize_img +from .utils import list_images, normalize_img Image.MAX_IMAGE_PIXELS = None diff --git a/core/maskers.py b/core/maskers.py index a27a679..dd2bf42 100644 --- a/core/maskers.py +++ b/core/maskers.py @@ -13,8 +13,8 @@ from PIL import Image from scipy.ndimage import convolve -from core.glint_algorithms import GlintAlgorithm, IntensityRatioAlgorithm, ThresholdAlgorithm -from core.image_loaders import ImageLoader, MicasenseRedEdgeLoader, P4MSLoader, RGB8BitLoader +from .glint_algorithms import GlintAlgorithm, IntensityRatioAlgorithm, ThresholdAlgorithm +from .image_loaders import ImageLoader, MicasenseRedEdgeLoader, P4MSLoader, RGB8BitLoader class Masker(object): @@ -199,16 +199,3 @@ def __init__(self, img_dir: str, mask_dir: str, super().__init__(algorithm=IntensityRatioAlgorithm(percent_diffuse, threshold), image_loader=MicasenseRedEdgeLoader(img_dir, mask_dir), pixel_buffer=pixel_buffer) - - -if __name__ == '__main__': - masker = MicasenseRedEdgeThresholdMasker("/media/taylor/Samsung_T5/Datasets/ExampleImages/MicasenseRededge", "/tmp", - thresholds=(0.7, 0.7, 0.7, 0.7, 0.7)) - masker.process(callback=lambda paths: print(paths)) - - masker = P4MSThresholdMasker("/media/taylor/Samsung_T5/Datasets/ExampleImages/P4MS", "/tmp", - thresholds=(0.7, 0.7, 0.7, 0.7, 0.7)) - masker.process(callback=lambda paths: print(paths)) - - masker = RGBThresholdMasker("/media/taylor/Samsung_T5/Datasets/ExampleImages/RGB", "/tmp") - masker.process(callback=lambda paths: print(paths))