def FIR_hp_callBack(self): if self.raw_data is None: self.infile_error() else: # prompt the user to select the dataset to Process data_var, ok = QtWidgets.QInputDialog.getItem( self, "Select Dataset to process", "Dataset", self.data_list, 0, False) if ok: input_dialog = QtWidgets.QDialog() input_ui = FIR_LHP.Ui_FIR_Design() input_ui.setupUi(input_dialog) input_dialog.show() if input_dialog.exec(): ntaps, freq, win = input_ui.onOk() if ntaps and freq: if ntaps % 2 == 0: ntaps = ntaps + 1 # converitng to Odd number of taps FIR_hp_Data = FIR_hp_func( 'FIR highpass Filtered with taps ' + str(ntaps), self.data_avail[str(data_var)], self.dt, self.nrx, self.rx_component, ntaps, freq, win) self.data_avail[ 'FIR Highpass Data'] = FIR_hp_Data # Updating available datasets if 'FIR Highpass Data' not in self.data_list: self.data_list.append( 'FIR Highpass Data' ) #Updating the available dataset list tab_Var = mplt_plot(self.tab, FIR_hp_Data, self.dt, self.rx, self.rx_component) self.t_index = self.tabWidget.addTab( tab_Var, 'FIR highpass Filtered with taps ' + str(ntaps)) self.tabWidget.setCurrentIndex(self.t_index)
def FIR_bp_callBack(self): if self.raw_data is None: self.infile_error() else: # prompt the user to select the dataset to Process data_var, ok = QtWidgets.QInputDialog.getItem( self, "Select Dataset to process", "Dataset", self.data_list, 0, False) if ok: input_dialog = QtWidgets.QDialog() input_ui = FIR_B_PS.Ui_FIR_Design() input_ui.setupUi(input_dialog) input_dialog.show() if input_dialog.exec(): ntaps, freq1, freq2, win = input_ui.onOk() if ntaps % 2 == 0: ntaps = ntaps + 1 # converitng to Odd number of taps self.FIR_bp_Data = FIR_bp_func( 'FIR Bandpass Filtered with taps ' + str(ntaps), self.raw_data, self.dt, self.nrx, self.rx_component, ntaps, freq1, freq2, win) tab_Var = mplt_plot(self.tab, self.FIR_bp_Data, self.dt, self.rx, self.rx_component) self.t_index = self.tabWidget.addTab( tab_Var, 'FIR Bandpass Filtered with taps ' + str(ntaps)) self.tabWidget.setCurrentIndex(self.t_index)
def median_Filter_callBack(self): if self.raw_data is None: self.infile_error() else: # prompt the user to select the dataset to Process data_var, ok = QtWidgets.QInputDialog.getItem( self, "Select Dataset to process", "Dataset", self.data_list, 0, False) if ok: input_dialog = QtWidgets.QDialog() input_ui = Median_Filter_Window_size.Ui_dialog() input_ui.setupUi(input_dialog) input_dialog.show() if input_dialog.exec(): win1, win2 = input_ui.onOk() if win1 and win2: self.med_filt_Data = median_Filter_func( 'Median Filtered with ' + str(win1) + 'x' + str(win2) + ' window', self.data_avail[str(data_var)], self.dt, self.nrx, self.rx_component, win1, win2) self.data_avail[ 'Median Filtered Data'] = self.med_filt_Data # Updating available datasets if 'Median Filtered Data' not in self.data_list: self.data_list.append( 'Median Filtered Data' ) #Updating the available dataset list tab_Var = mplt_plot(self.tab, self.med_filt_Data, self.dt, self.rx, self.rx_component) self.t_index = self.tabWidget.addTab( tab_Var, 'Median Filtered with ' + str(win1) + 'x' + str(win2) + ' window') self.tabWidget.setCurrentIndex(self.t_index)
def gauss_Filter_callBack(self): if self.raw_data is None: self.infile_error() else: # prompt the user to select the dataset to Process data_var, ok = QtWidgets.QInputDialog.getItem( self, "Select Dataset to process", "Dataset", self.data_list, 0, False) if ok: sigma, okPressed = QtWidgets.QInputDialog.getInt( self, "Enter Sigma ", "Sigma", 2, 1, 4, 1) if sigma: gauss_filt_Data = gauss_Filter_func( 'Gaussian Filtered with sigma ' + str(sigma), self.data_avail[str(data_var)], self.dt, self.nrx, self.rx_component, sigma) self.data_avail[ 'Gaussian Filtered Data'] = gauss_filt_Data # Updating available datasets if 'Gaussian Filtered Data' not in self.data_list: self.data_list.append( 'Gaussian Filtered Data' ) #Updating the available dataset list tab_Var = mplt_plot(self.tab, gauss_filt_Data, self.dt, self.rx, self.rx_component) self.t_index = self.tabWidget.addTab( tab_Var, 'Gaussian Filtered with sigma ' + str(sigma)) self.tabWidget.setCurrentIndex(self.t_index)
def field_to_Power(self): if self.raw_data is None: self.infile_error() else: # prompt the user to select the dataset to Process data_var, ok = QtWidgets.QInputDialog.getItem( self, "Select Dataset to process", "Dataset", self.data_list, 0, False) if ok: self.dx, okPressed = QtWidgets.QInputDialog.getDouble( self, "Enter dx(m)", "Descretisation Size (m)", 0.002, 0.0001, 0.5, 4) if self.dx and okPressed: f_Power = field_to_Power_func( 'Power (dB)', self.data_avail[str(data_var)], self.dt, self.nrx, self.rx_component, self.dx) self.data_avail[ 'Field Power(dB)'] = f_Power # Updating available datasets if 'Field Power(dB)' not in self.data_list: self.data_list.append( 'Field Power(dB)' ) #Updating the available dataset list tab_Var = mplt_plot(self.tab, f_Power, self.dt, self.rx, 'P') self.t_index = self.tabWidget.addTab( tab_Var, 'Converted Powerplot (dB) for dx = ' + str(self.dx)) self.tabWidget.setCurrentIndex(self.t_index)
def time_gain(self): if self.raw_data is None: self.infile_error() else: # prompt the user to select the dataset to Process data_var, ok = QtWidgets.QInputDialog.getItem( self, "Select Dataset to process", "Dataset", self.data_list, 0, False) if ok: time_pow, okPressed = QtWidgets.QInputDialog.getDouble( self, "Enter time Power", "Time Power", 2, 0.1, 20, 4) if time_pow: t_Data = time_gain_func( 'Time Gain ' + str(time_pow) + 'Applied', self.data_avail[str(data_var)], self.dt, self.nrx, self.rx_component, time_pow) self.data_avail[ 'Time Gain Applied Data'] = t_Data # Updating available datasets if 'Time Gain Applied Data' not in self.data_list: self.data_list.append( 'Time Gain Applied Data' ) #Updating the available dataset list tab_Var = mplt_plot(self.tab, t_Data, self.dt, self.rx, self.rx_component) self.t_index = self.tabWidget.addTab( tab_Var, 'Time Gain Applied with ' 't' 'power = ' + str(time_pow)) self.tabWidget.setCurrentIndex(self.t_index)
def nonmaxima(self): nonmaxima_img = np.array(self.image_out_grad.copy()) imagea = np.array(self.image_out_angle.copy()) (h, w) = self.image_out_grad.shape for i in range(h): for j in range(w): if (i == 0 or i == h - 1 or j == 0 or j == w - 1): nonmaxima_img[i][j] = 0 continue tq = (imagea[i][j]) % 4 if (tq == 0): if (self.image_out_grad[i, j] <= self.image_out_grad[i, j - 1] or self.image_out_grad[i, j] <= self.image_out_grad[i, j + 1]): nonmaxima_img[i][j] = 0 if (tq == 1): if (self.image_out_grad[i, j] <= self.image_out_grad[i - 1, j + 1] or self.image_out_grad[i, j] <= self.image_out_grad[i + 1, j - 1]): nonmaxima_img[i][j] = 0 if (tq == 2): if (self.image_out_grad[i, j] <= self.image_out_grad[i - 1, j] or self.image_out_grad[i, j] <= self.image_out_grad[i + 1, j]): nonmaxima_img[i][j] = 0 if (tq == 3): if (self.image_out_grad[i, j] <= self.image_out_grad[i - 1, j - 1] or self.image_out_grad[i, j] <= self.image_out_grad[i + 1, j + 1]): nonmaxima_img[i][j] = 0 if self.completed < 40: self.completed += 0.1 self.progress.setValue(self.completed) self.nonmaxima_img = nonmaxima_img self.progress.setValue(self.completed) tab_Var = mplt_plot(self.tab, nonmaxima_img) self.t_index = self.tabWidget.addTab(tab_Var, 'Non-Maximum Supressed') self.tabWidget.setCurrentIndex(self.t_index) QMessageBox.about(self, "Status!", "Non-max image Generated!") # '''Input Window for Max and Min Threshold''' input_dialog = QtWidgets.QDialog() input_ui = Threshold.Ui_Dialog() input_ui.setupUi(input_dialog) input_dialog.show() if input_dialog.exec(): thes_l, Thresh_h = input_ui.onOk() if thes_l and Thresh_h: thresh = thes_l, Thresh_h self.h_thres = np.max(thresh) # Value self.l_thres = np.min(thresh) # Value self.thres()
def File_Open_window(self): file_name = QtWidgets.QFileDialog.getOpenFileName( self, 'Select Image File', filter="JPEG (*.jpg);;PNG(*.png);;All (*)") if file_name[0]: self.fname = file_name[0] self.f_type = path.splitext(file_name[0]) (self.directory, self.filename) = path.split(self.fname) self.raw_data = np.array( cv2.imread(self.fname, cv2.IMREAD_GRAYSCALE)) self.tab_Var = mplt_plot(self.tab, self.raw_data) self.t_index = self.tabWidget.addTab(self.tab_Var, str(self.filename)) self.tabWidget.setCurrentIndex(self.t_index) elif self.raw_data is None: self.infile_error()
def G_Blur(self): if self.raw_data is None: self.infile_error() else: input_dialog = QtWidgets.QDialog() input_ui3 = sigma_in.Ui_Dialog() input_ui3.setupUi(input_dialog) input_dialog.show() if input_dialog.exec(): self.sigma = input_ui3.onOk() ws = int(np.round(3 * self.sigma)) shape = (ws, ws) m, n = [(ss - 1.) / 2. for ss in shape] y, x = np.ogrid[-m:m + 1, -n:n + 1] h = np.exp(-(x * x + y * y) / (2. * self.sigma * self.sigma)) h[h < np.finfo(h.dtype).eps * h.max()] = 0 sumh = h.sum() if sumh != 0: h /= sumh fil = np.array(h) gaussian_out = np.array(self.raw_data.copy()) (h, w) = self.raw_data.shape (hf, wf) = fil.shape hf2 = hf // 2 wf2 = wf // 2 for i in range(hf2, h - hf2): for j in range(wf2, w - wf2): tsum = 0 for ii in range(hf): for jj in range(wf): tsum = tsum + ( self.raw_data[i - hf2 + ii, j - wf2 + jj] * fil[hf - 1 - ii, wf - 1 - jj]) gaussian_out[i][j] = tsum if self.completed < 10: self.completed += 0.1 self.progress.setValue(self.completed) self.gaussian_out = gaussian_out self.progress.setValue(self.completed) tab_Var = mplt_plot(self.tab, gaussian_out) self.t_index = self.tabWidget.addTab(tab_Var, 'Gaussian Blur') self.tabWidget.setCurrentIndex(self.t_index) QMessageBox.about(self, "Status!", "Gaussian Blur Applied!") self.gradient()
def hysteresis(self): finalEdges = self.strong.copy() thresholdedEdges = self.l_h_t currentPixels = [] wr = int(np.floor(self.windows_size / 2)) wc = int(np.round(self.windows_size / 2)) for r in range(wr, finalEdges.shape[0] - wr): for c in range(wc, finalEdges.shape[1] - wc): if thresholdedEdges[r, c] != 50: continue #Not a weak pixel #Get 3x3 patch localPatch = thresholdedEdges[r - wr:r + wc, c - wr:c + wc] patchMax = localPatch.max() if patchMax == 50: currentPixels.append((r, c)) finalEdges[r, c] = 255 #Extend strong edges based on current pixels while len(currentPixels) > 0: newPix = [] for r, c in currentPixels: for dr in range(-1, 2): for dc in range(-1, 2): if dr == 0 and dc == 0: continue r2 = r + dr c2 = c + dc if thresholdedEdges[r2, c2] == 50 and finalEdges[r2, c2] == 0: #Copy this weak pixel to final result newPix.append((r2, c2)) finalEdges[r2, c2] = 255 currentPixels = newPix if self.completed < 95: self.completed += 0.05 self.progress.setValue(self.completed) tab_Var = mplt_plot(self.tab, finalEdges) self.t_index = self.tabWidget.addTab(tab_Var, 'Edge_Image') self.tabWidget.setCurrentIndex(self.t_index) self.progress.setValue(100) self.statusBar().showMessage('Done!')
def thres(self): im = self.nonmaxima_img Imax = np.max(np.max(self.nonmaxima_img)) Imin = np.min(np.min(self.nonmaxima_img)) Il = self.l_thres Ih = self.h_thres l_thres = Il * (Imax - Imin) + Imin h_thres = Ih * (Imax - Imin) + Imin print(l_thres, h_thres) si, sj = np.where(im > h_thres) wi, wj = np.where((im >= l_thres) & (im < h_thres)) zi, zj = np.where(im < l_thres) im[si, sj] = np.int32(255) im[wi, wj] = np.int32(50) im[zi, zj] = np.int32(0) s = np.zeros(im.shape) s[si, sj] = np.int32(255) W = np.zeros(im.shape) W[wi, wj] = np.int32(50) if self.completed < 60: self.completed += 0.1 self.progress.setValue(self.completed) self.threshold = W self.strong = s self.l_h_t = im tab_Var = mplt_plot(self.tab, im) self.t_index = self.tabWidget.addTab(tab_Var, 'strong_Weak') self.tabWidget.setCurrentIndex(self.t_index) self.progress.setValue(70) input_dialog2 = QtWidgets.QDialog() input_ui2 = Hist_window.Ui_Dialog() input_ui2.setupUi(input_dialog2) input_dialog2.show() if input_dialog2.exec(): self.windows_size = input_ui2.onOk() if int((self.windows_size) % 2) == 0: self.windows_size = self.windows_size else: self.windows_size = self.windows_size + 1 self.hysteresis()
def trim_Data(self): if self.raw_data is None: self.infile_error() else: # prompt the user to select the dataset to Process data_var, ok = QtWidgets.QInputDialog.getItem( self, "Select Dataset to process", "Dataset", self.data_list, 0, False) if ok: xmin, xmax, ymin, ymax = 0, 300, 0, 300 Data = self.data_avail[str(data_var)] tr_Data = Data[xmin:xmax, ymin:ymax] self.data_avail[ 'Trimmed Data'] = tr_Data # Updating available datasets if 'Trimmed Data' not in self.data_list: self.data_list.append( 'Trimmed Data') #Updating the available dataset list tab_Var = mplt_plot(self.tab, tr_Data, self.dt, self.rx, self.rx_component) self.t_index = self.tabWidget.addTab(tab_Var, 'Trimmed Data') self.tabWidget.setCurrentIndex(self.t_index)
def gradient(self): image_out_grad = np.array(self.gaussian_out.copy()) image_out_angle = np.array(self.gaussian_out.copy()) gx = np.array([[-1, 0, 1], [-2, 0, 2], [-1, 0, 1]]) gy = gx.T (h, w) = self.gaussian_out.shape (hf, wf) = gx.shape hf2 = hf // 2 wf2 = wf // 2 for i in range(hf2, h - hf2): for j in range(wf2, w - wf2): tsumx = 0 tsumy = 0 for ii in range(hf): for jj in range(wf): tsumx = tsumx + ( self.gaussian_out[i - hf2 + ii, j - wf2 + jj] * gx[hf - 1 - ii, wf - 1 - jj]) tsumy = tsumy + ( self.gaussian_out[i - hf2 + ii, j - wf2 + jj] * gy[hf - 1 - ii, wf - 1 - jj]) image_out_grad[i][j] = math.sqrt((tsumx * tsumx) + (tsumy * tsumy)) theta = np.arctan2(tsumy, tsumx) image_out_angle[i][j] = (np.round(theta * (5.0 / np.pi)) + 5) % 5 #angle quantization if self.completed < 35: self.completed += 0.03 self.progress.setValue(self.completed) self.image_out_grad = image_out_grad self.image_out_angle = image_out_angle self.progress.setValue(self.completed) tab_Var = mplt_plot(self.tab, image_out_grad) self.t_index = self.tabWidget.addTab(tab_Var, 'Gradient') self.tabWidget.setCurrentIndex(self.t_index) QMessageBox.about(self, "Status!", "Gradient image Generated!") self.nonmaxima()
def FIR_bs_callBack(self): if self.raw_data is None: self.infile_error() else: input_dialog = QtWidgets.QDialog() input_ui = FIR_B_PS.Ui_FIR_Design() input_ui.setupUi(input_dialog) input_dialog.show() if input_dialog.exec(): ntaps, freq1, freq2, win = input_ui.onOk() if ntaps % 2 == 0: ntaps = ntaps + 1 # converitng to Odd number of taps self.FIR_bs_Data = FIR_bs_func( 'FIR Bandpass Filtered with taps ' + str(ntaps), self.raw_data, self.dt, self.nrx, self.rx_component, ntaps, freq1, freq2, win) tab_Var = mplt_plot(self.tab, self.FIR_bs_Data, self.dt, self.rx, self.rx_component) self.t_index = self.tabWidget.addTab( tab_Var, 'FIR Bandstop Filtered with taps ' + str(ntaps)) self.tabWidget.setCurrentIndex(self.t_index)
def median_R(self): if self.raw_data is None: self.infile_error() else: # prompt the user to select the dataset to Process data_var, ok = QtWidgets.QInputDialog.getItem( self, "Select Dataset to process", "Dataset", self.data_list, 0, False) if ok: median_r_Data = median_removal_func( 'Median trace Removed', self.data_avail[str(data_var)], self.dt, self.nrx, self.rx_component) self.data_avail[ 'Median Removed Data'] = median_r_Data # Updating available datasets if 'Median Removed Data' not in self.data_list: self.data_list.append( 'Median Removed Data' ) #Updating the available dataset list tab_Var = mplt_plot(self.tab, median_r_Data, self.dt, self.rx, self.rx_component) self.t_index = self.tabWidget.addTab(tab_Var, 'Median Trace Removed') self.tabWidget.setCurrentIndex(self.t_index)
def File_Open_window(self): file_name = QtWidgets.QFileDialog.getOpenFileName( self, 'Select a File', filter="gprMax file (*.out);;GSSI File (*.DZT);;All (*)") if file_name[0]: self.fname = file_name[0] self.f_type = path.splitext(file_name[0]) (self.directory, self.filename) = path.split(self.fname) if self.f_type[1] == '.out': f = h5py.File(self.fname, 'r') self.nrx = f.attrs['nrx'] f.close() rx_c_list = ('Ez', 'Ex', 'Ey', 'Hx', 'Hy', 'Hz', 'Ix', 'Iy', 'Iz') self.rx_component, ok = QtWidgets.QInputDialog.getItem( self, "Select component to plot", "Rx Component", rx_c_list, 0, False) if ok: # self.overlay.show() for self.rx in range(1, self.nrx + 1): self.raw_data, self.dt = get_output_data( self.fname, self.rx, self.rx_component) tab_Var = mplt_plot(self.tab, self.raw_data, self.dt, self.rx, self.rx_component) self.t_index = self.tabWidget.addTab( tab_Var, str(self.filename)) self.tabWidget.setCurrentIndex(self.t_index) # out_plot(self.fname,self.raw_data,self.dt,self.rx,self.rx_component) self.data_avail['Raw Data'] = self.raw_data if 'Raw Data' not in self.data_list: self.data_list.append('Raw Data') print(np.min(self.raw_data), np.max(self.raw_data)) # print(self.data_list) # print(self.data_avail['Raw Data']) # self.overlay.kill_Timer() elif self.f_type[1] == '.DZT': (self.directory, self.filename) = path.split(self.fname) self.header, self.raw_data = readgssi(self.fname) print(np.min(self.raw_data), np.max(self.raw_data)) self.data_avail['Raw Data'] = self.raw_data if 'Raw Data' not in self.data_list: self.data_list.append('Raw Data') self.dt = (self.header['rhf_range'] / (self.header['rh_nsamp'] - 1)) * pow(10, -9) self.rx = 1 self.nrx = 1 self.rx_component = 'Ez' tab_Var = mplt_plot(self.tab, self.raw_data, self.dt, self.rx, self.rx_component) self.t_index = self.tabWidget.addTab(tab_Var, str(self.filename)) self.tabWidget.setCurrentIndex(self.t_index) # out_plot(self.fname,self.raw_data,self.dt,self.rx,self.rx_component) print( ' File : ', self.header['infile'], '\n', 'Antenna : ', self.header['rh_antname'], '\n', 'Bit Rate : ', self.header['rh_bits'], '\n', 'Scans per Second : ', self.header['rhf_sps'], '\n', 'Samples per Scan : ', self.header['rh_nsamp'], '\n', 'Sampling interval (ns) : ', self.dt * pow(10, 9), '\n', 'Range in ns : ', self.header['rhf_range'], '\n', 'Scans per pass : '******'rh_npass'], '\n', 'Scans per m : ', self.header['rhf_spm'], '\n', 'Scan Spacing : ', 1 / self.header['rhf_spm'], '\n', 'Di-electric Const : ', self.header['rhf_epsr'], '\n', 'Appearent Depth(m) : ', self.header['rhf_depth'], '\n') # print(self.header) elif self.f_type[1] and self.raw_data is None: QtWidgets.QMessageBox.warning( self, 'File Type Error!', 'Invalid file Type \nPlease select valid file', QtWidgets.QMessageBox.Ok) elif self.raw_data is None: self.infile_error()