-
Notifications
You must be signed in to change notification settings - Fork 0
/
stats.py
95 lines (69 loc) · 2.78 KB
/
stats.py
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
import os, sys
from scipy.ndimage import binary_hit_or_miss
from PIL import Image
import numpy as np
import matplotlib.pyplot as plt
from tqdm import tqdm
from natsort import natsorted
from glob import glob
import json
from node import SplittingTree
from utils import make_rgb_indices, rplan_map
import networkx as nx
from easydict import EasyDict as ED
import pickle
if __name__ == '__main__':
stats = ED()
NUM_ROOM_TYPES = rplan_map.shape[0]
stats.n_rooms = []
stats.widths = [[] for _ in range(NUM_ROOM_TYPES)]
stats.heights = [[] for _ in range(NUM_ROOM_TYPES)]
stats.xlocs = [[] for _ in range(NUM_ROOM_TYPES)]
stats.ylocs = [[] for _ in range(NUM_ROOM_TYPES)]
stats.hadjs = [[] for _ in range(NUM_ROOM_TYPES)]
stats.vadjs = [[] for _ in range(NUM_ROOM_TYPES)]
errors = {}
for jj in tqdm(range(316)):
IMG_PATH = f'/mnt/iscratch/datasets/rplan_ddg_var/{jj}/'
IMAGES = natsorted(glob(IMG_PATH + '*_nodoor.png'))
bads = []
graphs_consistent = []
for idx in tqdm(range(len(IMAGES)), leave=False):
with open(IMAGES[idx], 'rb') as fd:
img_pil = Image.open(fd)
img_np = np.asarray(img_pil)
img_idx = make_rgb_indices(img_np, rplan_map)
walls = img_idx == 1
structure1 = np.array([[0, 1], [1, 0]])
wall_corners = binary_hit_or_miss(walls, structure1=structure1)
img_idx[wall_corners] = 1
structure1 = np.array([[1, 0], [0, 1]])
wall_corners = binary_hit_or_miss(walls, structure1=structure1, origin1=(0, -1))
img_idx[wall_corners] = 1
try:
st = SplittingTree(img_idx, rplan_map, grad_from='whole')
st.create_tree()
st._merge_small_boxes(cross_wall=False)
st._merge_vert_boxes(cross_wall=False)
except Exception as e:
continue
pass
# raise(e)
# bads.append(IMAGES[idx])
# horiz_adj = st.find_horiz_adj()
# vert_adj = st.find_vert_adj()
n_nodes = len(st.boxes)
stats.n_rooms.append(n_nodes)
for rr in st.boxes:
room_type = rr.idx
stats.widths[room_type].append(rr.get_width())
stats.heights[room_type].append(rr.get_height())
stats.xlocs[room_type].append(rr.aabb.getx())
stats.ylocs[room_type].append(rr.aabb.gety())
stats_file = './data_stats.pkl'
if not os.path.exists(stats_file):
with open(stats_file, 'wb') as fd:
pickle.dump(stats, fd, protocol=pickle.HIGHEST_PROTOCOL)
## plot the stats for type 5 Living Room
plt.hist(stats.widths[5], bins=20)
plt.show()