-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdesinusouid_data.py
More file actions
47 lines (36 loc) · 1.64 KB
/
desinusouid_data.py
File metadata and controls
47 lines (36 loc) · 1.64 KB
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
import numpy as np
import scipy
from tkinter import filedialog
class DesinusouidData:
def __init__(self):
self.mat_file = None
self.desinusoid_matrix = None
def load_desinusouid_file(self):
"""
Function to load the desinusoid matrix created in matlab
:return: None
"""
self.mat_file = filedialog.askopenfilename(title='Select file containing the calibration matrix:',
filetypes=[('MATLAB Mats', '*.mat')])
desinusoid_mat = scipy.io.loadmat(self.mat_file)
self.desinusoid_matrix = desinusoid_mat['vertical_fringes_desinusoid_matrix']
def desinusoid_data(self, vid_data):
"""
Function that takes in the desinusoid matrix and matrix multiplies every frame by it and re-saves the video into
new folder with the same name.
:param vid_data: current location and name of the video to be processed
:return: the desinusoided video as a numpy array
"""
height, width, frames = vid_data.shape
r, c = self.desinusoid_matrix.shape
# Make the video output array
output = np.zeros((height, r, frames))
for i in range(0, frames):
curr_frame = vid_data[:, :, i]
# perform the matrix multipy to desinusouid the data
transpose_mat = self.desinusoid_matrix.T
desinusoid_frame = np.matmul(curr_frame, transpose_mat)
desinusoid_frame[desinusoid_frame < 0] = 0
desinusoid_frame[desinusoid_frame > 255] = 255
output[:, :, i] = desinusoid_frame.astype(np.uint8)
return output