Adds color visualization script
Browse filesAdds a script to generate a color legend image, mapping semantic labels to specific colors.
Also, converts some numpy arrays to lists to prevent issues with serialization.
- color_visu.py +144 -0
- gestalt_color_legend.png +0 -0
- predict.py +1 -1
- train.py +2 -0
color_visu.py
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import cv2
|
| 2 |
+
import numpy as np
|
| 3 |
+
|
| 4 |
+
# Color mappings (as provided in the context file)
|
| 5 |
+
gestalt_color_mapping = {
|
| 6 |
+
"unclassified": (215, 62, 138),
|
| 7 |
+
"apex": (235, 88, 48),
|
| 8 |
+
"eave_end_point": (248, 130, 228),
|
| 9 |
+
"flashing_end_point": (71, 11, 161),
|
| 10 |
+
"ridge": (214, 251, 248),
|
| 11 |
+
"rake": (13, 94, 47),
|
| 12 |
+
"eave": (54, 243, 63),
|
| 13 |
+
"post": (187, 123, 236),
|
| 14 |
+
"ground_line": (136, 206, 14),
|
| 15 |
+
"flashing": (162, 162, 32),
|
| 16 |
+
"step_flashing": (169, 255, 219),
|
| 17 |
+
"hip": (8, 89, 52),
|
| 18 |
+
"valley": (85, 27, 65),
|
| 19 |
+
"roof": (215, 232, 179),
|
| 20 |
+
"door": (110, 52, 23),
|
| 21 |
+
"garage": (50, 233, 171),
|
| 22 |
+
"window": (230, 249, 40),
|
| 23 |
+
"shutter": (122, 4, 233),
|
| 24 |
+
"fascia": (95, 230, 240),
|
| 25 |
+
"soffit": (2, 102, 197),
|
| 26 |
+
"horizontal_siding": (131, 88, 59),
|
| 27 |
+
"vertical_siding": (110, 187, 198),
|
| 28 |
+
"brick": (171, 252, 7),
|
| 29 |
+
"concrete": (32, 47, 246),
|
| 30 |
+
"other_wall": (112, 61, 240),
|
| 31 |
+
"trim": (151, 206, 58),
|
| 32 |
+
"unknown": (127, 127, 127),
|
| 33 |
+
"transition_line": (0,0,0),
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
edge_color_mapping = {
|
| 37 |
+
'cornice_return': (215, 62, 138),
|
| 38 |
+
'cornice_strip': (235, 88, 48),
|
| 39 |
+
'eave': (54, 243, 63),
|
| 40 |
+
"flashing": (162, 162, 32),
|
| 41 |
+
'hip': (8, 89, 52),
|
| 42 |
+
'rake': (13, 94, 47),
|
| 43 |
+
'ridge': (214, 251, 248),
|
| 44 |
+
"step_flashing": (169, 255, 219),
|
| 45 |
+
'transition_line': (200,0,50),
|
| 46 |
+
'valley': (85, 27, 65),
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
# Parameters for the legend image
|
| 50 |
+
swatch_width = 150
|
| 51 |
+
swatch_height = 25
|
| 52 |
+
text_color_bgr = (0, 0, 0) # Black
|
| 53 |
+
font = cv2.FONT_HERSHEY_SIMPLEX
|
| 54 |
+
font_scale = 0.4
|
| 55 |
+
font_thickness = 1
|
| 56 |
+
horizontal_padding = 20
|
| 57 |
+
vertical_padding = 15 # Padding at top/bottom of sections and between items
|
| 58 |
+
text_offset_x = 10 # Space between swatch and text
|
| 59 |
+
item_row_height = swatch_height + 5 # Total height for one swatch + text row, including small spacing
|
| 60 |
+
section_title_font_scale = 0.6
|
| 61 |
+
section_title_font_thickness = 1
|
| 62 |
+
section_title_area_height = 40 # Space allocated for section title
|
| 63 |
+
|
| 64 |
+
all_mappings_with_titles = [
|
| 65 |
+
("Gestalt Colors", gestalt_color_mapping),
|
| 66 |
+
("Edge Colors", edge_color_mapping),
|
| 67 |
+
]
|
| 68 |
+
|
| 69 |
+
# Calculate maximum width needed for labels to determine overall image width
|
| 70 |
+
max_label_width = 0
|
| 71 |
+
for _, color_map in all_mappings_with_titles:
|
| 72 |
+
for label in color_map.keys():
|
| 73 |
+
(text_w, _), _ = cv2.getTextSize(label, font, font_scale, font_thickness)
|
| 74 |
+
if text_w > max_label_width:
|
| 75 |
+
max_label_width = text_w
|
| 76 |
+
|
| 77 |
+
image_width = horizontal_padding + swatch_width + text_offset_x + max_label_width + horizontal_padding
|
| 78 |
+
|
| 79 |
+
# Calculate total image height
|
| 80 |
+
image_height = vertical_padding # Initial top padding
|
| 81 |
+
for i, (_, color_map) in enumerate(all_mappings_with_titles):
|
| 82 |
+
image_height += section_title_area_height
|
| 83 |
+
image_height += len(color_map) * item_row_height
|
| 84 |
+
if i < len(all_mappings_with_titles) - 1:
|
| 85 |
+
image_height += vertical_padding # Padding between sections
|
| 86 |
+
image_height += vertical_padding # Final bottom padding
|
| 87 |
+
|
| 88 |
+
# Create a white canvas
|
| 89 |
+
legend_image = np.full((image_height, image_width, 3), 255, dtype=np.uint8) # White background
|
| 90 |
+
|
| 91 |
+
current_y = vertical_padding
|
| 92 |
+
|
| 93 |
+
for title_text, color_map in all_mappings_with_titles:
|
| 94 |
+
# Draw section title
|
| 95 |
+
(title_w, title_h), title_baseline = cv2.getTextSize(title_text, font, section_title_font_scale, section_title_font_thickness)
|
| 96 |
+
title_x = horizontal_padding # Align title to the left
|
| 97 |
+
# Center title vertically within its allocated space
|
| 98 |
+
title_y_baseline = current_y + (section_title_area_height - title_h) // 2 + title_h - title_baseline // 2
|
| 99 |
+
cv2.putText(legend_image, title_text, (title_x, title_y_baseline), font, section_title_font_scale, text_color_bgr, section_title_font_thickness)
|
| 100 |
+
current_y += section_title_area_height
|
| 101 |
+
|
| 102 |
+
# Draw color swatches and labels for the current map
|
| 103 |
+
for label, rgb_color in color_map.items():
|
| 104 |
+
# OpenCV uses BGR, so convert RGB to BGR
|
| 105 |
+
bgr_color = (rgb_color[2], rgb_color[1], rgb_color[0])
|
| 106 |
+
|
| 107 |
+
swatch_x1 = horizontal_padding
|
| 108 |
+
swatch_y1 = current_y
|
| 109 |
+
swatch_x2 = swatch_x1 + swatch_width
|
| 110 |
+
swatch_y2 = swatch_y1 + swatch_height
|
| 111 |
+
|
| 112 |
+
# Draw the color swatch (filled rectangle)
|
| 113 |
+
cv2.rectangle(legend_image, (swatch_x1, swatch_y1), (swatch_x2, swatch_y2), bgr_color, -1)
|
| 114 |
+
# Draw a thin black border around the swatch for clarity
|
| 115 |
+
cv2.rectangle(legend_image, (swatch_x1, swatch_y1), (swatch_x2, swatch_y2), (0,0,0), 1)
|
| 116 |
+
|
| 117 |
+
|
| 118 |
+
# Get text size for precise vertical centering
|
| 119 |
+
(text_w, text_h), baseline = cv2.getTextSize(label, font, font_scale, font_thickness)
|
| 120 |
+
|
| 121 |
+
# Calculate position for the text (vertically centered with the swatch)
|
| 122 |
+
text_x = swatch_x2 + text_offset_x
|
| 123 |
+
# The 'org' for putText is the bottom-left corner of the text string.
|
| 124 |
+
# To center text_h within swatch_height:
|
| 125 |
+
text_y_baseline = swatch_y1 + (swatch_height - text_h) // 2 + text_h
|
| 126 |
+
|
| 127 |
+
cv2.putText(legend_image, label, (text_x, text_y_baseline), font, font_scale, text_color_bgr, font_thickness)
|
| 128 |
+
|
| 129 |
+
current_y += item_row_height # Move to the next item row
|
| 130 |
+
|
| 131 |
+
current_y += vertical_padding # Add padding after the items in this section
|
| 132 |
+
|
| 133 |
+
# Save the image
|
| 134 |
+
output_filename = "gestalt_color_legend.png"
|
| 135 |
+
try:
|
| 136 |
+
cv2.imwrite(output_filename, legend_image)
|
| 137 |
+
print(f"Legend image saved as {output_filename}")
|
| 138 |
+
except Exception as e:
|
| 139 |
+
print(f"Error saving image: {e}")
|
| 140 |
+
|
| 141 |
+
# To display the image (optional, uncomment if you have a display environment)
|
| 142 |
+
# cv2.imshow("Gestalt Color Legend", legend_image)
|
| 143 |
+
# cv2.waitKey(0)
|
| 144 |
+
# cv2.destroyAllWindows()
|
gestalt_color_legend.png
ADDED
|
predict.py
CHANGED
|
@@ -9,7 +9,7 @@ def convert_entry_to_human_readable(entry):
|
|
| 9 |
if 'colmap' in k:
|
| 10 |
out[k] = read_colmap_rec(v)
|
| 11 |
elif k in ['wf_vertices', 'wf_edges', 'K', 'R', 't', 'depth']:
|
| 12 |
-
out[k] =
|
| 13 |
else:
|
| 14 |
out[k]=v
|
| 15 |
out['__key__'] = entry['order_id']
|
|
|
|
| 9 |
if 'colmap' in k:
|
| 10 |
out[k] = read_colmap_rec(v)
|
| 11 |
elif k in ['wf_vertices', 'wf_edges', 'K', 'R', 't', 'depth']:
|
| 12 |
+
out[k] = v
|
| 13 |
else:
|
| 14 |
out[k]=v
|
| 15 |
out['__key__'] = entry['order_id']
|
train.py
CHANGED
|
@@ -25,6 +25,8 @@ idx = 0
|
|
| 25 |
for a in ds['train']:
|
| 26 |
colmap = read_colmap_rec(a['colmap_binary'])
|
| 27 |
|
|
|
|
|
|
|
| 28 |
try:
|
| 29 |
pred_vertices, pred_edges = predict_wireframe(a)
|
| 30 |
except:
|
|
|
|
| 25 |
for a in ds['train']:
|
| 26 |
colmap = read_colmap_rec(a['colmap_binary'])
|
| 27 |
|
| 28 |
+
#plot_all_modalities(a)
|
| 29 |
+
|
| 30 |
try:
|
| 31 |
pred_vertices, pred_edges = predict_wireframe(a)
|
| 32 |
except:
|