from pathlib import Path import cv2 parent = Path(__file__).parent.resolve() root = parent.joinpath("..").joinpath("..").resolve() datain = root.joinpath("datain").resolve() images = datain.joinpath("images").resolve() phenopsis = images.joinpath("phenopsis").resolve() cvpp = images.joinpath("Plant_Phenotyping_Datasets").resolve() param_set = images.joinpath("param_setting").resolve() param_set_images = images.joinpath("param_setting").joinpath("images").resolve() param_set_masks = images.joinpath("param_setting").joinpath("masks").resolve() param_set_thresholds = images.joinpath("param_setting").joinpath("thresholds").resolve() param_set_demo = images.joinpath("param_setting").joinpath("demo").resolve() param_set_gt_seg = ( images.joinpath("param_setting").joinpath("ground_truth_segmented").resolve() ) param_set_train_data = images.joinpath("param_setting").joinpath("train_data").resolve() exp_phenopsis = datain.joinpath("phenopsis").resolve() data = datain.joinpath("data").resolve() datasets = datain.joinpath("datasets").resolve() dataout = root.joinpath("dataout").resolve() configurations = dataout.joinpath("confs").resolve() mask_cache = dataout.joinpath("masks").resolve() masks_raw = dataout.joinpath("raw_masks").resolve() checkpoints = root.joinpath("checkpoints").resolve() notebooks = root.joinpath("notebooks") scripts = notebooks.joinpath("scripts") # MARK: Constants DI_SRC = "source" DI_SRC_BBOXES = "Source with bboxes" DI_NONE = "no image" DI_SEG_SEED_MASK = "segmentation seed mask" DI_SEG_SEED_MASK_KEEP = "segmentation seed mask keep" DI_SEG_SEED_MASK_DISCARD = "segmentation seed mask discard" DI_SEG_DISTANCE_MAP = "segmentation distance map" DI_SEG_DISTANCE_MAP_KEEP = "segmentation distance map keep" DI_SEG_DISTANCE_MAP_DISCARD = "segmentation distance map discard" DI_SEG_DISTANCE_MAP_KEEP_WITH_SEEDS = "segmentation distance map keep with seeds" DI_SEG_DISTANCE_MAP_DISCARD_WITH_SEEDS = "segmentation distance map discard with seeds" DI_SEG_SEEDS = "segmentation seeds" DI_SEG_RAW_MASK = "segmentation raw mask" DI_SEG_LOW_RES_LOGITS_MASK = "segmentation low resolution logits mask" DI_SEG_EVOLVING_MASK = "segmentation mask progression" DI_SEG_CLEAN_MASK = "segmentation clean mask" DI_SEG_CLEAN_MASK_DEMO = "segmentation clean mask demo" DI_SEG_CLEAN_MASK_ON_IMAGE = "segmentation clean mask on image" DI_SEG_CONTOURS_ON_SRC_IMAGE = "contours on source image" DI_SEG_CLEAN_MASK_ON_IMAGE_WITH_CONTOURS = "clean mask on image with contours" DI_SEG_MASK_ON_IMAGE_SUSPECT_CONTOURS = "masked image with suspect contours" DI_SEG_CLEAN_MASK_ON_IMAGE_WTH_BOXES = "masked image with boxes" DI_SEG_CLEAN_MASK_ON_IMAGE_WITH_SEEDS = "segmentation clean mask on image with seeds" DI_SEG_PLANT_ONLY = "segmentation plant only" DI_SEQ_SRC_IMAGE = "source image" DI_SEG_RM_MASK = "raw mask" DI_SEQ_RM_PLANT = "plant only" DI_SEQ_RM_PLANT_HIGHLIGHT = "plant highlight" DF_SEQ_RM_CONTOURS = "plant with contours" DI_SEQ_RM_CONTOURS_HIERARCHY = "plant with contour hierarchy" DI_SEQ_RM_SUSPECT_CONTOURS = "plant and suspect contours" DI_SEQ_SM_MASK = "sifted mask" DI_SEQ_SM_PLANT = "sifted plant" DI_SEQ_SM_CONTOURS = "sifted plant with contours" DI_SEQ_SM_CONTOURS_ON_SRC = "source image with sifted contours" DI_SYMP_SEED_MASK = "symptoms seed mask" DI_SYMP_SEED_MASK_KEEP = "symptoms seed mask keep" DI_SYMP_SEED_MASK_DISCARD = "symptoms seed mask discard" DI_SYMP_SEEDS = "symptoms seeds" C_BLACK = (0, 0, 0) C_BLUE = (255, 0, 0) C_BLUE_VIOLET = (226, 43, 138) C_CABIN_BLUE = (209, 133, 67) C_CYAN = (255, 255, 0) C_DIM_GRAY = (105, 105, 105) C_FUCHSIA = (255, 0, 255) C_GREEN = (0, 128, 0) C_LIGHT_STEEL_BLUE = (222, 196, 176) C_LIME = (0, 255, 0) C_MAROON = (0, 0, 128) C_ORANGE = (80, 127, 255) C_PURPLE = (128, 0, 128) C_RED = (0, 0, 255) C_SILVER = (192, 192, 192) C_TEAL = (128, 128, 0) C_WHITE = (255, 255, 255) C_YELLOW = (0, 255, 255) C_BROWN = (42, 42, 165) C_SIENNA = (45, 82, 160) KLC_FULLY_INSIDE = dict(val=0, color=C_GREEN) KLC_OVERLAPS = dict(val=1, color=C_LIME) KLC_OK_TOLERANCE = dict(val=4, color=C_TEAL) KLC_SMALL = dict(val=5, color=C_BLUE) KLC_FAR = dict(val=6, color=C_RED) KLC_SMALL_FAR = dict(val=7, color=C_FUCHSIA) MP_HULL = "masp_property_hull" MP_CENTROID = "masp_property_centroid" MP_BOUND_RECT = "masp_property_bounding_rectangle" MP_ROT_BOUND_RECT = "masp_property_rotated_bounding_rectangle" MP_ENCLOSING_CIRCLE = "masp_property_enclosing_circle" AVAILABLE_MASK_PROPERTIES = [ MP_HULL, MP_CENTROID, MP_BOUND_RECT, MP_ROT_BOUND_RECT, MP_ENCLOSING_CIRCLE, ] colors_dict = dict( black=C_BLACK, blue=C_BLUE, blue_violet=C_BLUE_VIOLET, blue_cabin=C_CABIN_BLUE, cyan=C_CYAN, dim_grey=C_DIM_GRAY, fuchsia=C_FUCHSIA, green=C_GREEN, light_steel_blue=C_LIGHT_STEEL_BLUE, lime=C_LIME, maroon=C_MAROON, orange=C_ORANGE, purple=C_PURPLE, red=C_RED, silver=C_SILVER, teal=C_TEAL, white=C_WHITE, yellow=C_YELLOW, brown=C_BROWN, sienna=C_SIENNA, ) COLORS = [v for v in colors_dict.values()] channel_names = ["red", "green", "blue", "hue", "sat", "light"] channel_colors = { "red": "red", "green": "green", "blue": "blue", "hue": "orange", "sat": "pink", "light": "grey", } image_names = { DI_NONE: "noImage", DI_SEG_SEED_MASK: "segmentationSeedMask", DI_SEG_SEED_MASK_KEEP: "segmentationMeedMaskKeep", DI_SEG_SEED_MASK_DISCARD: "segmentationSeedMaskDiscard", DI_SEG_DISTANCE_MAP: "segmentationDistanceMap", DI_SEG_DISTANCE_MAP_KEEP: "segmentationDistanceMapKeep", DI_SEG_DISTANCE_MAP_DISCARD: "segmentationDistanceMapDiscard", DI_SEG_DISTANCE_MAP_KEEP_WITH_SEEDS: "segmentationDistanceMapKeepWithSeeds", DI_SEG_DISTANCE_MAP_DISCARD_WITH_SEEDS: "segmentationDistanceMapDiscardWithSeeds", DI_SEG_SEEDS: "segmentationSeeds", DI_SEG_RAW_MASK: "segmentationRawMask", DI_SEG_LOW_RES_LOGITS_MASK: "segmentationLowResolutionLogitsMask", DI_SEG_EVOLVING_MASK: "segmentationMaskProgression", DI_SEG_CLEAN_MASK: "segmentationCleanMask", DI_SEG_CLEAN_MASK_DEMO: "segmentationCleanMaskDemo", DI_SEG_CLEAN_MASK_ON_IMAGE: "segmentationCleanMaskOnImage", DI_SEG_CLEAN_MASK_ON_IMAGE_WITH_CONTOURS: "cleanMaskOnImageWithContours", DI_SEG_MASK_ON_IMAGE_SUSPECT_CONTOURS: "maskedImage", DI_SEG_CLEAN_MASK_ON_IMAGE_WTH_BOXES: "maskedImageWith boxes", DI_SEG_CLEAN_MASK_ON_IMAGE_WITH_SEEDS: "segmentationCleanMaskOnImageWithSeeds", DI_SEG_PLANT_ONLY: "segmentationPlantOnly", DI_SEQ_SRC_IMAGE: "sourceImage", DI_SEG_RM_MASK: "rawMask", DI_SEQ_RM_PLANT: "plantOnly", DI_SEQ_RM_PLANT_HIGHLIGHT: "plantHighlight", DF_SEQ_RM_CONTOURS: "plantWithContours", DI_SEQ_RM_CONTOURS_HIERARCHY: "plantWithContourHierarchy", DI_SEQ_RM_SUSPECT_CONTOURS: "plantAndSuspectContours", DI_SEQ_SM_MASK: "siftedMask", DI_SEQ_SM_PLANT: "siftedPlant", DI_SEQ_SM_CONTOURS: "siftedPlantWithContours", DI_SEQ_SM_CONTOURS_ON_SRC: "sourceImageWithSiftedContours", DI_SYMP_SEED_MASK: "symptomsSeedMask", DI_SYMP_SEED_MASK_KEEP: "symptomsSeedMaskKeep", DI_SYMP_SEED_MASK_DISCARD: "symptomsSeedMaskDiscard", DI_SYMP_SEEDS: "symptomsSeeds", } OPENCV_DIST_METHODS = { "Correlation": cv2.HISTCMP_CORREL, "Chi-Squared": cv2.HISTCMP_CHISQR, "Intersection": cv2.HISTCMP_INTERSECT, "Hellinger": cv2.HISTCMP_BHATTACHARYYA, } THS_SOURCE = "source" THS_RAW_MASK_PLANT = "raw plant mask" THS_MASK_PLANT = "plant mask" THS_RAW_MASK_BACKGROUND = "raw background mask" THS_MASK_BACKGROUND = "background mask" THS_MASK_PLANT_REGIONS = "plant mask regions" THS_MASK_BACKGROUND_REGIONS = "background mask regions" THS_MASK_MERGED = "merged mask" THS_MASK_REGIONS = "regions" THS_MASK_SEEDS = "merged mask with seeds" THS_MASK_REGIONS_SEEDS = "regions with seeds" THS_SEG_MASK_RAW = "raw mask" THS_SEG_MASK_CLEAN = "clean mask" THS_SEG_MASK_DEMO = "demo klc mask" THS_SEG_MASK_LOGITS = "logits" THS_SEG_MASK_EVO = "segmentation evolution" THS_SEG_PLANT_ONLY = "plant only" THS_SEG_PLANT_DEMO = "plant demo" AVAILABLE_IMAGES = [ THS_SOURCE, THS_RAW_MASK_PLANT, THS_MASK_PLANT, THS_RAW_MASK_BACKGROUND, THS_MASK_BACKGROUND, THS_MASK_MERGED, THS_MASK_REGIONS, THS_MASK_REGIONS_SEEDS, THS_MASK_SEEDS, THS_SEG_MASK_RAW, THS_SEG_MASK_CLEAN, THS_SEG_MASK_DEMO, THS_SEG_MASK_LOGITS, THS_SEG_MASK_EVO, THS_SEG_PLANT_ONLY, THS_SEG_PLANT_DEMO, ]