treizh commited on
Commit
9d1e3ce
·
verified ·
1 Parent(s): 6dad0e0

Upload scripts/tap_const.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. scripts/tap_const.py +241 -0
scripts/tap_const.py ADDED
@@ -0,0 +1,241 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from pathlib import Path
2
+
3
+ import cv2
4
+
5
+ parent = Path(__file__).parent.resolve()
6
+ root = parent.joinpath("..").joinpath("..").resolve()
7
+
8
+ datain = root.joinpath("datain").resolve()
9
+ images = datain.joinpath("images").resolve()
10
+ phenopsis = images.joinpath("phenopsis").resolve()
11
+ cvpp = images.joinpath("Plant_Phenotyping_Datasets").resolve()
12
+ param_set = images.joinpath("param_setting").resolve()
13
+ param_set_images = images.joinpath("param_setting").joinpath("images").resolve()
14
+ param_set_masks = images.joinpath("param_setting").joinpath("masks").resolve()
15
+ param_set_thresholds = images.joinpath("param_setting").joinpath("thresholds").resolve()
16
+ param_set_demo = images.joinpath("param_setting").joinpath("demo").resolve()
17
+ param_set_gt_seg = (
18
+ images.joinpath("param_setting").joinpath("ground_truth_segmented").resolve()
19
+ )
20
+ param_set_train_data = images.joinpath("param_setting").joinpath("train_data").resolve()
21
+ exp_phenopsis = datain.joinpath("phenopsis").resolve()
22
+ data = datain.joinpath("data").resolve()
23
+ datasets = datain.joinpath("datasets").resolve()
24
+
25
+ dataout = root.joinpath("dataout").resolve()
26
+ configurations = dataout.joinpath("confs").resolve()
27
+ mask_cache = dataout.joinpath("masks").resolve()
28
+ masks_raw = dataout.joinpath("raw_masks").resolve()
29
+
30
+ checkpoints = root.joinpath("checkpoints").resolve()
31
+
32
+ notebooks = root.joinpath("notebooks")
33
+ scripts = notebooks.joinpath("scripts")
34
+
35
+ # MARK: Constants
36
+ DI_SRC = "source"
37
+ DI_SRC_BBOXES = "Source with bboxes"
38
+
39
+ DI_NONE = "no image"
40
+ DI_SEG_SEED_MASK = "segmentation seed mask"
41
+ DI_SEG_SEED_MASK_KEEP = "segmentation seed mask keep"
42
+ DI_SEG_SEED_MASK_DISCARD = "segmentation seed mask discard"
43
+ DI_SEG_DISTANCE_MAP = "segmentation distance map"
44
+ DI_SEG_DISTANCE_MAP_KEEP = "segmentation distance map keep"
45
+ DI_SEG_DISTANCE_MAP_DISCARD = "segmentation distance map discard"
46
+ DI_SEG_DISTANCE_MAP_KEEP_WITH_SEEDS = "segmentation distance map keep with seeds"
47
+ DI_SEG_DISTANCE_MAP_DISCARD_WITH_SEEDS = "segmentation distance map discard with seeds"
48
+ DI_SEG_SEEDS = "segmentation seeds"
49
+ DI_SEG_RAW_MASK = "segmentation raw mask"
50
+ DI_SEG_LOW_RES_LOGITS_MASK = "segmentation low resolution logits mask"
51
+ DI_SEG_EVOLVING_MASK = "segmentation mask progression"
52
+ DI_SEG_CLEAN_MASK = "segmentation clean mask"
53
+ DI_SEG_CLEAN_MASK_DEMO = "segmentation clean mask demo"
54
+ DI_SEG_CLEAN_MASK_ON_IMAGE = "segmentation clean mask on image"
55
+ DI_SEG_CONTOURS_ON_SRC_IMAGE = "contours on source image"
56
+ DI_SEG_CLEAN_MASK_ON_IMAGE_WITH_CONTOURS = "clean mask on image with contours"
57
+ DI_SEG_MASK_ON_IMAGE_SUSPECT_CONTOURS = "masked image with suspect contours"
58
+ DI_SEG_CLEAN_MASK_ON_IMAGE_WTH_BOXES = "masked image with boxes"
59
+ DI_SEG_CLEAN_MASK_ON_IMAGE_WITH_SEEDS = "segmentation clean mask on image with seeds"
60
+ DI_SEG_PLANT_ONLY = "segmentation plant only"
61
+
62
+ DI_SEQ_SRC_IMAGE = "source image"
63
+ DI_SEG_RM_MASK = "raw mask"
64
+ DI_SEQ_RM_PLANT = "plant only"
65
+ DI_SEQ_RM_PLANT_HIGHLIGHT = "plant highlight"
66
+ DF_SEQ_RM_CONTOURS = "plant with contours"
67
+ DI_SEQ_RM_CONTOURS_HIERARCHY = "plant with contour hierarchy"
68
+ DI_SEQ_RM_SUSPECT_CONTOURS = "plant and suspect contours"
69
+ DI_SEQ_SM_MASK = "sifted mask"
70
+ DI_SEQ_SM_PLANT = "sifted plant"
71
+ DI_SEQ_SM_CONTOURS = "sifted plant with contours"
72
+ DI_SEQ_SM_CONTOURS_ON_SRC = "source image with sifted contours"
73
+
74
+ DI_SYMP_SEED_MASK = "symptoms seed mask"
75
+ DI_SYMP_SEED_MASK_KEEP = "symptoms seed mask keep"
76
+ DI_SYMP_SEED_MASK_DISCARD = "symptoms seed mask discard"
77
+ DI_SYMP_SEEDS = "symptoms seeds"
78
+
79
+
80
+ C_BLACK = (0, 0, 0)
81
+ C_BLUE = (255, 0, 0)
82
+ C_BLUE_VIOLET = (226, 43, 138)
83
+ C_CABIN_BLUE = (209, 133, 67)
84
+ C_CYAN = (255, 255, 0)
85
+ C_DIM_GRAY = (105, 105, 105)
86
+ C_FUCHSIA = (255, 0, 255)
87
+ C_GREEN = (0, 128, 0)
88
+ C_LIGHT_STEEL_BLUE = (222, 196, 176)
89
+ C_LIME = (0, 255, 0)
90
+ C_MAROON = (0, 0, 128)
91
+ C_ORANGE = (80, 127, 255)
92
+ C_PURPLE = (128, 0, 128)
93
+ C_RED = (0, 0, 255)
94
+ C_SILVER = (192, 192, 192)
95
+ C_TEAL = (128, 128, 0)
96
+ C_WHITE = (255, 255, 255)
97
+ C_YELLOW = (0, 255, 255)
98
+ C_BROWN = (42, 42, 165)
99
+ C_SIENNA = (45, 82, 160)
100
+
101
+
102
+ KLC_FULLY_INSIDE = dict(val=0, color=C_GREEN)
103
+ KLC_OVERLAPS = dict(val=1, color=C_LIME)
104
+ KLC_OK_TOLERANCE = dict(val=4, color=C_TEAL)
105
+ KLC_SMALL = dict(val=5, color=C_BLUE)
106
+ KLC_FAR = dict(val=6, color=C_RED)
107
+ KLC_SMALL_FAR = dict(val=7, color=C_FUCHSIA)
108
+
109
+
110
+ MP_HULL = "masp_property_hull"
111
+ MP_CENTROID = "masp_property_centroid"
112
+ MP_BOUND_RECT = "masp_property_bounding_rectangle"
113
+ MP_ROT_BOUND_RECT = "masp_property_rotated_bounding_rectangle"
114
+ MP_ENCLOSING_CIRCLE = "masp_property_enclosing_circle"
115
+ AVAILABLE_MASK_PROPERTIES = [
116
+ MP_HULL,
117
+ MP_CENTROID,
118
+ MP_BOUND_RECT,
119
+ MP_ROT_BOUND_RECT,
120
+ MP_ENCLOSING_CIRCLE,
121
+ ]
122
+
123
+ colors_dict = dict(
124
+ black=C_BLACK,
125
+ blue=C_BLUE,
126
+ blue_violet=C_BLUE_VIOLET,
127
+ blue_cabin=C_CABIN_BLUE,
128
+ cyan=C_CYAN,
129
+ dim_grey=C_DIM_GRAY,
130
+ fuchsia=C_FUCHSIA,
131
+ green=C_GREEN,
132
+ light_steel_blue=C_LIGHT_STEEL_BLUE,
133
+ lime=C_LIME,
134
+ maroon=C_MAROON,
135
+ orange=C_ORANGE,
136
+ purple=C_PURPLE,
137
+ red=C_RED,
138
+ silver=C_SILVER,
139
+ teal=C_TEAL,
140
+ white=C_WHITE,
141
+ yellow=C_YELLOW,
142
+ brown=C_BROWN,
143
+ sienna=C_SIENNA,
144
+ )
145
+
146
+ COLORS = [v for v in colors_dict.values()]
147
+
148
+ channel_names = ["red", "green", "blue", "hue", "sat", "light"]
149
+ channel_colors = {
150
+ "red": "red",
151
+ "green": "green",
152
+ "blue": "blue",
153
+ "hue": "orange",
154
+ "sat": "pink",
155
+ "light": "grey",
156
+ }
157
+
158
+ image_names = {
159
+ DI_NONE: "noImage",
160
+ DI_SEG_SEED_MASK: "segmentationSeedMask",
161
+ DI_SEG_SEED_MASK_KEEP: "segmentationMeedMaskKeep",
162
+ DI_SEG_SEED_MASK_DISCARD: "segmentationSeedMaskDiscard",
163
+ DI_SEG_DISTANCE_MAP: "segmentationDistanceMap",
164
+ DI_SEG_DISTANCE_MAP_KEEP: "segmentationDistanceMapKeep",
165
+ DI_SEG_DISTANCE_MAP_DISCARD: "segmentationDistanceMapDiscard",
166
+ DI_SEG_DISTANCE_MAP_KEEP_WITH_SEEDS: "segmentationDistanceMapKeepWithSeeds",
167
+ DI_SEG_DISTANCE_MAP_DISCARD_WITH_SEEDS: "segmentationDistanceMapDiscardWithSeeds",
168
+ DI_SEG_SEEDS: "segmentationSeeds",
169
+ DI_SEG_RAW_MASK: "segmentationRawMask",
170
+ DI_SEG_LOW_RES_LOGITS_MASK: "segmentationLowResolutionLogitsMask",
171
+ DI_SEG_EVOLVING_MASK: "segmentationMaskProgression",
172
+ DI_SEG_CLEAN_MASK: "segmentationCleanMask",
173
+ DI_SEG_CLEAN_MASK_DEMO: "segmentationCleanMaskDemo",
174
+ DI_SEG_CLEAN_MASK_ON_IMAGE: "segmentationCleanMaskOnImage",
175
+ DI_SEG_CLEAN_MASK_ON_IMAGE_WITH_CONTOURS: "cleanMaskOnImageWithContours",
176
+ DI_SEG_MASK_ON_IMAGE_SUSPECT_CONTOURS: "maskedImage",
177
+ DI_SEG_CLEAN_MASK_ON_IMAGE_WTH_BOXES: "maskedImageWith boxes",
178
+ DI_SEG_CLEAN_MASK_ON_IMAGE_WITH_SEEDS: "segmentationCleanMaskOnImageWithSeeds",
179
+ DI_SEG_PLANT_ONLY: "segmentationPlantOnly",
180
+ DI_SEQ_SRC_IMAGE: "sourceImage",
181
+ DI_SEG_RM_MASK: "rawMask",
182
+ DI_SEQ_RM_PLANT: "plantOnly",
183
+ DI_SEQ_RM_PLANT_HIGHLIGHT: "plantHighlight",
184
+ DF_SEQ_RM_CONTOURS: "plantWithContours",
185
+ DI_SEQ_RM_CONTOURS_HIERARCHY: "plantWithContourHierarchy",
186
+ DI_SEQ_RM_SUSPECT_CONTOURS: "plantAndSuspectContours",
187
+ DI_SEQ_SM_MASK: "siftedMask",
188
+ DI_SEQ_SM_PLANT: "siftedPlant",
189
+ DI_SEQ_SM_CONTOURS: "siftedPlantWithContours",
190
+ DI_SEQ_SM_CONTOURS_ON_SRC: "sourceImageWithSiftedContours",
191
+ DI_SYMP_SEED_MASK: "symptomsSeedMask",
192
+ DI_SYMP_SEED_MASK_KEEP: "symptomsSeedMaskKeep",
193
+ DI_SYMP_SEED_MASK_DISCARD: "symptomsSeedMaskDiscard",
194
+ DI_SYMP_SEEDS: "symptomsSeeds",
195
+ }
196
+
197
+
198
+ OPENCV_DIST_METHODS = {
199
+ "Correlation": cv2.HISTCMP_CORREL,
200
+ "Chi-Squared": cv2.HISTCMP_CHISQR,
201
+ "Intersection": cv2.HISTCMP_INTERSECT,
202
+ "Hellinger": cv2.HISTCMP_BHATTACHARYYA,
203
+ }
204
+
205
+ THS_SOURCE = "source"
206
+ THS_RAW_MASK_PLANT = "raw plant mask"
207
+ THS_MASK_PLANT = "plant mask"
208
+ THS_RAW_MASK_BACKGROUND = "raw background mask"
209
+ THS_MASK_BACKGROUND = "background mask"
210
+ THS_MASK_PLANT_REGIONS = "plant mask regions"
211
+ THS_MASK_BACKGROUND_REGIONS = "background mask regions"
212
+ THS_MASK_MERGED = "merged mask"
213
+ THS_MASK_REGIONS = "regions"
214
+ THS_MASK_SEEDS = "merged mask with seeds"
215
+ THS_MASK_REGIONS_SEEDS = "regions with seeds"
216
+ THS_SEG_MASK_RAW = "raw mask"
217
+ THS_SEG_MASK_CLEAN = "clean mask"
218
+ THS_SEG_MASK_DEMO = "demo klc mask"
219
+ THS_SEG_MASK_LOGITS = "logits"
220
+ THS_SEG_MASK_EVO = "segmentation evolution"
221
+ THS_SEG_PLANT_ONLY = "plant only"
222
+ THS_SEG_PLANT_DEMO = "plant demo"
223
+
224
+ AVAILABLE_IMAGES = [
225
+ THS_SOURCE,
226
+ THS_RAW_MASK_PLANT,
227
+ THS_MASK_PLANT,
228
+ THS_RAW_MASK_BACKGROUND,
229
+ THS_MASK_BACKGROUND,
230
+ THS_MASK_MERGED,
231
+ THS_MASK_REGIONS,
232
+ THS_MASK_REGIONS_SEEDS,
233
+ THS_MASK_SEEDS,
234
+ THS_SEG_MASK_RAW,
235
+ THS_SEG_MASK_CLEAN,
236
+ THS_SEG_MASK_DEMO,
237
+ THS_SEG_MASK_LOGITS,
238
+ THS_SEG_MASK_EVO,
239
+ THS_SEG_PLANT_ONLY,
240
+ THS_SEG_PLANT_DEMO,
241
+ ]