Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.09 KB | None | 0 0
  1. function a = visualize_result(log_dir)
  2. %% Visualize Supervised Network Results
  3.  
  4. mesh_0 = load('1.mat');
  5. mesh_1 = load('2.mat');
  6. cd ..
  7. X = load(curr.mat'));
  8. cd misc/
  9. colors = create_colormap(mesh_1,mesh_1);
  10. figure;
  11. subplot(1,2,1); colormap(colors);
  12. plot_scalar_map(mesh_1,[1: size(mesh_1.VERT,1)]');freeze_colors;title('Target');
  13. view(0,90)
  14. subplot(1,2,2); colormap(colors(X,:));
  15. plot_scalar_map(mesh_0,[1: size(mesh_0.VERT,1)]');freeze_colors;title('Source');
  16. view(0,90)
  17.  
  18.  
  19.  
  20. function colors = create_colormap(M,N)
  21.  
  22. % create colormap
  23. minx = min(min(M.VERT(:,1)),min(N.VERT(:,1)));
  24. miny = min(min(M.VERT(:,2)),min(N.VERT(:,2)));
  25. minz = min(min(M.VERT(:,3)),min(N.VERT(:,3)));
  26. maxx = max(max(M.VERT(:,1)),max(N.VERT(:,1)));
  27. maxy = max(max(M.VERT(:,2)),max(N.VERT(:,2)));
  28. maxz = max(max(M.VERT(:,3)),max(N.VERT(:,3)));
  29. colors = [(M.VERT(:,1)-minx)/(maxx-minx) (M.VERT(:,2)-miny)/(maxy-miny) (M.VERT(:,3)-minz)/(maxz-minz)];
  30.  
  31. end
  32.  
  33. import matplotlib.pyplot as plt
  34. from mpl_toolkits.mplot3d import Axes3D
  35. import scipy.io as sio
  36. import numpy as np
  37. fig = plt.figure()
  38. ax = fig.add_subplot(111, projection='3d')
  39.  
  40. def plot_compare_meshes(mesh_1_path,mesh_2_path,):
  41. fig = plt.figure()
  42. ax1 = fig.add_subplot(121, projection='3d'); ax1.view_init(90, -90)
  43.  
  44. mesh_1 = sio.loadmat(mesh_1_path)
  45. X_1 = mesh_1['VERT'][:, 0]
  46. Y_1 = mesh_1['VERT'][:, 1]
  47. Z_1 = mesh_1['VERT'][:, 2]
  48. TRIV_1 = mesh_1['TRIV'] - 1
  49.  
  50. colormap = create_colormap(mesh_1['VERT'])
  51.  
  52.  
  53. ax1.plot_trisurf(X_1, Y_1, Z_1, triangles=TRIV_1,color=colormap)
  54.  
  55. plt.show()
  56.  
  57. def create_colormap(VERT):
  58. VERT = np.double(VERT)
  59. minx = np.min(VERT[:,0])
  60. miny = np.min(VERT[:,1])
  61. minz = np.min(VERT[:,2])
  62. maxx = np.max(VERT[:,0])
  63. maxy = np.max(VERT[:,1])
  64. maxz = np.max(VERT[:,2])
  65. colors = list(zip(
  66. ((VERT[:,0] - minx) / (maxx - minx)),
  67. ((VERT[:, 1] - miny) / (maxy - miny)),
  68. ((VERT[:, 2] - minz) / (maxz - minz))))
  69. return colors
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76. if __name__ == "__main__":
  77. plot_compare_meshes(mesh1,mesh2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement