From 798bf1367dd04db91ceb2770666e985cabf0a20a Mon Sep 17 00:00:00 2001 From: Hunor Laczko Date: Sun, 29 Jan 2023 12:51:17 +0000 Subject: [PATCH] option to use global binning --- curvature_analysis.py | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/curvature_analysis.py b/curvature_analysis.py index ee59ae3..8dc49c2 100644 --- a/curvature_analysis.py +++ b/curvature_analysis.py @@ -67,7 +67,7 @@ def get_bins(values, nr_of_bins): return bins -def generate_curvatures(folder, frame, neighbourhoods=[25], nr_of_labels=6): +def generate_curvatures(folder, frame, bins, neighbourhoods=[25], nr_of_labels=6): id = frame.split('_')[0] frame_nr = int(frame.split('_')[1].split('.')[0]) @@ -98,20 +98,20 @@ def generate_curvatures(folder, frame, neighbourhoods=[25], nr_of_labels=6): cloud.add_scalar_field("curvature", ev=ev) curvature = np.array(cloud.points["curvature(" + str(neighbourhood+1) + ")"]) - bins = get_bins(curvature, nr_of_labels) - labels = np.linspace(0, bins.shape[0] - 2, bins.shape[0] - 1) + bins_local = bins[neighbourhood] if bins is not None else get_bins(curvature, nr_of_labels) + labels = np.linspace(0, bins_local.shape[0] - 2, bins_local.shape[0] - 1) frame_labels = np.zeros((curvature.shape[0]), dtype=np.float32) - for j in range(bins.shape[0] - 2): - frame_labels[(curvature >= bins[j]) * (curvature < bins[j+1])] = labels[j] - frame_labels[curvature >= bins[-2]] = labels[-1] + for j in range(bins_local.shape[0] - 2): + frame_labels[(curvature >= bins_local[j]) * (curvature < bins_local[j+1])] = labels[j] + frame_labels[curvature >= bins_local[-2]] = labels[-1] curvatures.append(frame_labels) return curvatures -def visualize_curvature_labels(folder, frame, neighbourhoods): +def visualize_curvature_labels(folder, frame, bins, neighbourhoods): id = frame.split('_')[0] frame_nr = frame.split('_')[1].split('.')[0] @@ -119,7 +119,7 @@ def visualize_curvature_labels(folder, frame, neighbourhoods): _, faces = _maskFaces(np.zeros((14475,3)), F, mask) verts = np.load(os.path.join(folder, 'mesh_posed', f'{id}_{frame_nr}.npz'))['mesh_posed'][mask,:] - curvature_labels_all = generate_curvatures(folder, frame, neighbourhoods) + curvature_labels_all = generate_curvatures(folder, frame, bins, neighbourhoods) colors_binned_all = [] for curvature_labels in curvature_labels_all: @@ -166,7 +166,7 @@ def visualize_curvature_labels(folder, frame, neighbourhoods): scene2_aspectmode='manual', scene2_aspectratio=dict(x=1, y=1, z=1), scene3_aspectmode='manual', scene3_aspectratio=dict(x=1, y=1, z=1), scene4_aspectmode='manual', scene4_aspectratio=dict(x=1, y=1, z=1), - scene5_aspectmode='manual', scene5_aspectratio=dict(x=1, y=1, z=1), + # scene5_aspectmode='manual', scene5_aspectratio=dict(x=1, y=1, z=1), ) helper = dict(xaxis = dict(nticks=4, range=[-1,1],), yaxis = dict(nticks=4, range=[-1,1],), @@ -175,7 +175,7 @@ def visualize_curvature_labels(folder, frame, neighbourhoods): scene2 = helper, scene3 = helper, scene4 = helper, - scene5 = helper, + # scene5 = helper, ) @@ -211,6 +211,13 @@ if __name__ == '__main__': # k_neighbours(k=25) folder = '/home/workspace/local-data/valid_skirt' + bins = dict() + bins[10] = np.load(f'custom_data/train_bins_skirt_10.npy') + bins[25] = np.load(f'custom_data/train_bins_skirt.npy') + bins[100] = np.load(f'custom_data/train_bins_skirt_100.npy') + + bins = None + nr_of_labels = 6 neighbourhood = 50 @@ -220,4 +227,4 @@ if __name__ == '__main__': else: dist = np.load('custom_data/dijkstra_skirt.npy') - visualize_curvature_labels(folder, '02572_1', neighbourhoods=[10, 25, 50, 100]) \ No newline at end of file + visualize_curvature_labels(folder, '02572_1', bins, neighbourhoods=[10, 25, 100]) \ No newline at end of file