reab5555 commited on
Commit
caf2618
·
verified ·
1 Parent(s): 8e662fb

Update visualization.py

Browse files
Files changed (1) hide show
  1. visualization.py +17 -7
visualization.py CHANGED
@@ -1,6 +1,7 @@
1
  import matplotlib.pyplot as plt
2
  from matplotlib.backends.backend_agg import FigureCanvasAgg
3
  import matplotlib.colors as mcolors
 
4
  import seaborn as sns
5
  import numpy as np
6
  import pandas as pd
@@ -138,6 +139,7 @@ def plot_mse_histogram(mse_values, title, anomaly_threshold, color='blue'):
138
  plt.close()
139
  return fig
140
 
 
141
  def plot_mse_heatmap(mse_values, title, df):
142
  plt.figure(figsize=(20, 3), dpi=300)
143
  fig, ax = plt.subplots(figsize=(20, 3))
@@ -219,9 +221,6 @@ def create_video_with_heatmap(video_path, df, mse_embeddings, mse_posture, outpu
219
  fourcc = cv2.VideoWriter_fourcc(*'mp4v')
220
  out = cv2.VideoWriter(output_path, fourcc, original_fps, (width, height + 200))
221
 
222
- cmap = mcolors.LinearSegmentedColormap.from_list("custom",
223
- [(1, 1, 1), (1, 0, 0)], N=256) # More reddish for higher MSE values
224
-
225
  mse_embeddings = np.interp(np.linspace(0, len(mse_embeddings) - 1, total_frames),
226
  np.arange(len(mse_embeddings)), mse_embeddings)
227
  mse_posture = np.interp(np.linspace(0, len(mse_posture) - 1, total_frames),
@@ -230,12 +229,23 @@ def create_video_with_heatmap(video_path, df, mse_embeddings, mse_posture, outpu
230
  mse_embeddings_norm = (mse_embeddings - np.min(mse_embeddings)) / (np.max(mse_embeddings) - np.min(mse_embeddings))
231
  mse_posture_norm = (mse_posture - np.min(mse_posture)) / (np.max(mse_posture) - np.min(mse_posture))
232
 
233
- combined_mse = np.zeros((2, total_frames, 3))
234
- combined_mse[0] = np.array([1 - mse_embeddings_norm, 1 - mse_embeddings_norm, 1 - mse_embeddings_norm]).T.reshape(-1, 3) # More reddish for facial
235
- combined_mse[1] = np.array([1 - mse_posture_norm, 1 - mse_posture_norm, 1 - mse_posture_norm]).T.reshape(-1, 3) # More reddish for posture
 
 
 
 
 
 
 
 
 
 
 
236
 
237
  fig, ax = plt.subplots(figsize=(width/100, 2))
238
- im = ax.imshow(combined_mse, aspect='auto', extent=[0, total_frames, 0, 2])
239
  ax.set_yticks([0.5, 1.5])
240
  ax.set_yticklabels(['Face', 'Posture'])
241
  ax.set_xticks([])
 
1
  import matplotlib.pyplot as plt
2
  from matplotlib.backends.backend_agg import FigureCanvasAgg
3
  import matplotlib.colors as mcolors
4
+ from matplotlib.colors import LinearSegmentedColormap
5
  import seaborn as sns
6
  import numpy as np
7
  import pandas as pd
 
139
  plt.close()
140
  return fig
141
 
142
+
143
  def plot_mse_heatmap(mse_values, title, df):
144
  plt.figure(figsize=(20, 3), dpi=300)
145
  fig, ax = plt.subplots(figsize=(20, 3))
 
221
  fourcc = cv2.VideoWriter_fourcc(*'mp4v')
222
  out = cv2.VideoWriter(output_path, fourcc, original_fps, (width, height + 200))
223
 
 
 
 
224
  mse_embeddings = np.interp(np.linspace(0, len(mse_embeddings) - 1, total_frames),
225
  np.arange(len(mse_embeddings)), mse_embeddings)
226
  mse_posture = np.interp(np.linspace(0, len(mse_posture) - 1, total_frames),
 
229
  mse_embeddings_norm = (mse_embeddings - np.min(mse_embeddings)) / (np.max(mse_embeddings) - np.min(mse_embeddings))
230
  mse_posture_norm = (mse_posture - np.min(mse_posture)) / (np.max(mse_posture) - np.min(mse_posture))
231
 
232
+ combined_mse = np.zeros((2, total_frames))
233
+ combined_mse[0] = mse_embeddings_norm # Use normalized MSE values for facial
234
+ combined_mse[1] = mse_posture_norm # Use normalized MSE values for posture
235
+
236
+ cdict = {
237
+ 'red': [(0.0, 1.0, 1.0), # Neutral (low MSE) to more red (high MSE)
238
+ (1.0, 1.0, 1.0)],
239
+ 'green': [(0.0, 1.0, 1.0), # Neutral (low MSE) to less green (high MSE)
240
+ (1.0, 0.0, 0.0)],
241
+ 'blue': [(0.0, 1.0, 1.0), # Neutral (low MSE) to less blue (high MSE)
242
+ (1.0, 0.0, 0.0)]
243
+ }
244
+
245
+ custom_cmap = LinearSegmentedColormap('custom_cmap', segmentdata=cdict, N=256)
246
 
247
  fig, ax = plt.subplots(figsize=(width/100, 2))
248
+ im = ax.imshow(combined_mse, aspect='auto', cmap=custom_cmap, extent=[0, total_frames, 0, 2])
249
  ax.set_yticks([0.5, 1.5])
250
  ax.set_yticklabels(['Face', 'Posture'])
251
  ax.set_xticks([])