Esempio n. 1
0
    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()