-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVibrations.py
169 lines (129 loc) · 5.56 KB
/
Vibrations.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
"""
TU/e
Tom van Hattem - 1580698
Biomaterials Processing and Design
Script for analyzing MEW Nozzle Blurring
Expects a series of videos where two classes can be compared (also works for 1 class)
Automatically detects where the printhead start to move
by analyzing the frame and checking for any movement in the frame.
Calculates the amount of blur in the image by subtracting the first non blurred
image from a range of blurred images. Accumulates the thresholded 'blur' in the range
percentage of blur for this accumulated white pixel image is calculated by dividing by
the total pixel count. This is a relative quantification.
returns a dataframe with the class, speed and percentage of the blur.
This data can then be plotted.
Blurr detection algorithm is found in utils.
Please use a constant background for consitant results.
For plottin the frames ipython is used, do not run directly in normal console svp.
"""
# Open Source Libraries
import numpy as np
import cv2 as cv2
import time
import datetime
import math
import matplotlib.pyplot as plt
import os
import time
import pandas as pd
import seaborn as sns
import sys
#Custom Libraries
sys.path.insert(0, './lib')
import Jet_Vibration_Analysis as JVA
import utils
import importlib
importlib.reload(utils) #Force Reload to ensure latest version is loaded
importlib.reload(JVA) #Force Reload to ensure latest version is loaded
"""VARIABLES"""
#Video should be defined as Class_run_VariableSpeed
#For example: New_1_F1000.wmv
classes = ['Og','ABS','SLS','PLA'] #Subclass that are compared
#classes = ['SLS','SLS_2.5cm_'] #Subclass that are compared
variable = 'F' #The variable that is experimented with
file_extension = '.wmv' #File extension of the video
subfolder = 'Data\\Vibration_3\\' #Subfolder where videos are located
amount_of_runs=4 #Runs per class
variable_start = 100 #Start of speed range
variable_end = 1000 #End of speed range
variable_step = 100 #Stepsize of speed range
vibration_threshold = 80 #Threshold used, higher this if percentages are high, inspect frames_output for more information on the threshold
#strongly advised not to plot too many images, as it gets slow
debug = utils.debug(
segmentation=False, #only used in legacy rotation
scharr_segmentation=False, #Top/Nozzle Segmentation
calibration=False,
rotation=False,
search_height = False,
height_threshold = False,
annotate=False,
threshold = False,
CLI=False,
blur=False
)
df = JVA.blur_analysis_series(amount_of_runs,
classes,
variable,
file_extension,
variable_start,
variable_end,
variable_step,
subfolder,
vibration_threshold,
debug,
mode="Full" #Full or LinearOnly
)
df.to_csv('csv\\Vibrations4.csv',index=False)
############################ DATA ANALYTICS ###################################
#df.loc[df['Classes'] == 'Original', 'Nozzle Diameter in Pixels'] = 24
mean = df['Nozzle Diameter in Pixels'].mean()
std = df['Nozzle Diameter in Pixels'].std()
threshold = mean + 2 * std
df['Nozzle_no_outliers'] = np.where(df['Nozzle Diameter in Pixels'] > threshold, np.nan, df['Nozzle Diameter in Pixels'])
nozzle_averages = df.groupby('Classes')['Nozzle_no_outliers'].transform('mean')
df['Normalized Blur'] = df['Blur'] / nozzle_averages * 100
palette = sns.color_palette("mako", 4)
fig = sns.lineplot(data=df, x="Speed", y="Normalized Blur", hue="Classes",palette=palette,estimator='median')
plt.legend(loc = "upper left",title='Material')
fig.axes.set_title('Material-Specific Pixel Change per Speed', fontsize=18, fontweight='bold')
fig.set_xlabel('Speed [mm/min]')
fig.set_ylabel('Normalized Pixel Change [-]')
plt.savefig('plots\\vibrations_lineplot2.png',dpi=400)
plt.show()
plt.clf()
palette = sns.color_palette("mako", 4)
fig = sns.barplot(data=df, x="Speed", y="Normalized Blur", hue="Classes",palette=palette,estimator='median')
plt.legend(loc="upper left", title='Material')
plt.title('Material-Specific Pixel Change per Speed', fontsize=18, fontweight='bold')
plt.xlabel('Speed [mm/min]')
plt.ylabel('Normalized Pixel Change [-]')
plt.savefig('plots\\vibrations_barplot2.png', dpi=400)
plt.show()
plt.clf()
"""HEATMAP"""
unique_classes = df['Classes'].unique()
# Determine the number of rows and columns for the subplots
num_rows = 1 # Adjust as needed
num_cols = 4 # Adjust as needed
# Create the subplots
fig, axes = plt.subplots(num_rows, num_cols, figsize=(12, 3))
# Flatten the axes array to simplify indexing
axes = axes.flatten()
# Iterate over the unique classes and create heatmaps
for i, class_name in enumerate(unique_classes):
# Filter the DataFrame for the current class
class_data = df[df['Classes'] == class_name]
# Pivot the class data for the heatmap
heatmap_data = class_data.pivot("Speed", "run", "Normalized Blur")
# Select the appropriate subplot for the current class
ax = axes[i]
# Create the heatmap for the current class
sns.heatmap(heatmap_data, annot=True, fmt=".2f", cmap=palette, ax=ax)
# Set the title of the subplot
ax.set_title(class_name)
# Adjust the layout and spacing of the subplots
plt.tight_layout()
plt.savefig('plots\\vibrations_heatmap.png', dpi=400)
# Show the plot
plt.show()
# %%