Spaces:
Sleeping
Sleeping
File size: 8,490 Bytes
9d1e3ce |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 |
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,
]
|