Exemplo n.º 1
0
    def __init__(self):
        super(ApplicationWindow, self).__init__()
        self.ui = Ui_Form()
        self.ui.setupUi(self)

        # self.ui.pb_browse.setIcon(self.Ui.QtGui.QIcon('123.jpg'))
        self.ui.pb_browse.clicked.connect(self.button_clicked)
Exemplo n.º 2
0
 def __init__(self):
     super(ApplicationWindow, self).__init__()
     self.ui = Ui_Form()
     self.ui.setupUi(self)
     self.ui.pb_browse.clicked.connect(self.Browse)
     self.ui.pb_resume.clicked.connect(self.Resume)
     self.ui.pb_start.clicked.connect(self.FFT_IFFT)
     self.ui.pb_pause.clicked.connect(self.Pause)
     self.ui.spinBox.valueChanged.connect(self.Spin_Box)
Exemplo n.º 3
0
    def __init__(self):
        super(Program, self).__init__()
        self.ui = Ui_Form()
        self.ui.setupUi(self)

        self.image = []
        self.check = []
        self.rows, self.ccol, self.crow, self.rowX, self.colsX, self.cols, self.Step,\
        self.Counter, self.loop, self.pause = [0, 0, 0, 0, 0, 0, 0, 0, 1, True]

        self.ui.pb_browse.clicked.connect(self.Browse)
        self.ui.pb_resume.clicked.connect(self.Resume)
        self.ui.pb_start.clicked.connect(self.FFT_IFFT)
        self.ui.pb_pause.clicked.connect(self.Pause)
        self.ui.spinBox.valueChanged.connect(self.Spin_Box)
        self.ui.pb_resume.setEnabled(False)
        self.ui.pb_start.setEnabled(False)
        self.ui.pb_pause.setEnabled(False)
Exemplo n.º 4
0
class ApplicationWindow(QtWidgets.QMainWindow):
    def __init__(self):
        super(ApplicationWindow, self).__init__()
        self.ui = Ui_Form()
        self.ui.setupUi(self)
        self.ui.pb_browse.clicked.connect(self.Browse)
        self.ui.pb_resume.clicked.connect(self.Resume)
        self.ui.pb_start.clicked.connect(self.FFT_IFFT)
        self.ui.pb_pause.clicked.connect(self.Pause)
        self.ui.spinBox.valueChanged.connect(self.Spin_Box)

    def Browse(self):

        fileName, _filter = QFileDialog.getOpenFileName(
            self, "Title", "Default File",
            "Photos Files (*.png);;Photos Files (*.jpg)")

        if fileName:
            global image, rows, cols, ccol, crow
            image = cv2.imread(fileName, 0)
            if type(image) == np.ndarray:
                rows, cols = image.shape
                crow, ccol = rows / 2, cols / 2
                print(fileName)
                print(_filter)

                if rows == 512 and cols == 512 or rows == 128 and cols == 128:
                    trans = Image.fromarray(image)
                    res = ImageQt(trans).scaled(321, 271)
                    self.ui.lab_original.setPixmap(QPixmap.fromImage(res))
                    self.ui.lab_Fourier.clear()
                else:
                    QMessageBox.information(
                        self, 'Message',
                        'The selected photo should be 128×128 or 512×512')
            else:
                QMessageBox.information(self, 'Message', 'File is not image')

    def Outer_Frame(self, cwidth, rwidth, img, imgwidth, imgheight):
        img[0:rwidth, 0:] = 0
        img[imgheight - rwidth:imgheight, 0:] = 0
        img[0:, 0:cwidth] = 0
        img[0:, imgwidth - cwidth:imgwidth] = 0
        return img

    def Spin_Box(self):
        global Step
        Step = self.ui.spinBox.value()

    def Pause(self):
        global pause
        pause = False

    def Resume(self):
        global pause
        if pause == False:
            pause = True
            self.FFT_IFFT()

    def FFT_IFFT(self):
        global image, ccol, crow, rows, cols, pause, Counter, loop
        rows, cols = image.shape
        crow, ccol = rows / 2, cols / 2
        progress = 0
        #Counter < int(cols/2)+Step

        while ((Counter < int(cols / 2) + Step) and loop == 1):
            if pause:
                Counter = Counter + Step
                if Counter > int(cols / 2):
                    if progress < 100:
                        Counter = int(cols / 2)
                    else:
                        break
                progress = round(Counter * (100 / int(cols / 2)))

                #self.ui.progressBar.setMaximum(cols/2)
                self.ui.progressBar.setProperty("value", progress)

                # Fourier transform & shift ll low freq
                f = np.fft.fft2(image)
                fshift = np.fft.fftshift(f)
                # Outer_Frame function ---> btsfar mn bara l gowa
                self.Outer_Frame(Counter, Counter, fshift, rows, cols)
                magnitude_spectrum = 20 * np.log(np.abs(fshift))
                magnitude_spectrum = np.asarray(magnitude_spectrum,
                                                dtype=np.uint8)
                trans = Image.fromarray(magnitude_spectrum)
                res = ImageQt(trans).scaled(321, 271)
                self.ui.lab_Fourier.setPixmap(QPixmap.fromImage(res))
                # 3aks ll shift b3d kda bn3ml inverse
                f_ishift = np.fft.ifftshift(fshift)
                img_back = np.fft.ifft2(f_ishift)
                img_back = np.abs(img_back)
                img_back = np.asarray(img_back, dtype=np.uint8)
                original_image = Image.fromarray(img_back)
                res = ImageQt(original_image).scaled(321, 271)
                self.ui.lab_original.setPixmap(QPixmap.fromImage(res))
                #Counter = Counter + Step
                QApplication.processEvents()
                time.sleep(0.1)

            else:
                break

        if pause and loop == 1:
            Counter = 0
            loop = 2

        if pause:

            while ((Counter < int(cols / 2) + Step) and loop == 2):
                if pause:
                    Counter = Counter + Step
                    if Counter > int(cols / 2):
                        if progress < 100:
                            Counter = int(cols / 2)
                        else:
                            continue
                    progress = round(Counter * (100 / int(cols / 2)))
                    #self.ui.progressBar.setMaximum(cols/2)
                    self.ui.progressBar.setProperty("value", progress)
                    # Fourier transform & shift ll low freq
                    f = np.fft.fft2(image)
                    fshift = np.fft.fftshift(f)
                    # bn3ml tsfer mn gowa l bara
                    fshift[int(crow - Counter):int(crow + Counter),
                           int(ccol - Counter):int(ccol + Counter)] = 0
                    magnitude_spectrum = 20 * np.log(np.abs(fshift))
                    magnitude_spectrum = np.asarray(magnitude_spectrum,
                                                    dtype=np.uint8)
                    trans = Image.fromarray(magnitude_spectrum)
                    res = ImageQt(trans).scaled(321, 271)
                    self.ui.lab_Fourier.setPixmap(QPixmap.fromImage(res))
                    # 3aks ll shift b3d kda bn3ml inverse
                    f_ishift = np.fft.ifftshift(fshift)
                    img_back = np.fft.ifft2(f_ishift)
                    img_back = np.abs(img_back)
                    img_back = np.asarray(img_back, dtype=np.uint8)
                    original_image = Image.fromarray(img_back)
                    res = ImageQt(original_image).scaled(321, 271)
                    self.ui.lab_original.setPixmap(QPixmap.fromImage(res))
                    #Counter=Counter+Step
                    QApplication.processEvents()
                    time.sleep(0.1)

                else:
                    break

        if pause and loop == 2:
            Counter = 0
            loop = 1
Exemplo n.º 5
0
class Program(QWidget):
    def __init__(self):
        super(Program, self).__init__()
        self.ui = Ui_Form()
        self.ui.setupUi(self)

        self.image = []
        self.check = []
        self.rows, self.ccol, self.crow, self.rowX, self.colsX, self.cols, self.Step,\
        self.Counter, self.loop, self.pause = [0, 0, 0, 0, 0, 0, 0, 0, 1, True]

        self.ui.pb_browse.clicked.connect(self.Browse)
        self.ui.pb_resume.clicked.connect(self.Resume)
        self.ui.pb_start.clicked.connect(self.FFT_IFFT)
        self.ui.pb_pause.clicked.connect(self.Pause)
        self.ui.spinBox.valueChanged.connect(self.Spin_Box)
        self.ui.pb_resume.setEnabled(False)
        self.ui.pb_start.setEnabled(False)
        self.ui.pb_pause.setEnabled(False)

    def Browse(self):
        filename, _filter = QFileDialog.getOpenFileName(self, "Browse", "")
        if filename:
            self.check = cv2.imread(filename, 0)
            if type(self.check) == np.ndarray:
                self.rowsX, self.colsX = self.check.shape
                if self.rowsX == 512 and self.colsX == 512 or self.rowsX == 128 and self.colsX == 128:
                    self.image = self.check
                    self.rows = self.rowsX
                    self.cols = self.colsX
                    self.crow, self.ccol = self.rows / 2, self.cols / 2
                    print(filename)
                    print(_filter)

                    trans = qimage2ndarray.array2qimage(self.image)
                    res = QPixmap(trans).scaled(321, 271)
                    self.ui.lab_original.setPixmap(res)

                    self.Counter = 0
                    self.ui.progressBar.setValue(0)
                    self.ui.lab_Fourier.clear()
                    self.ui.pb_start.setEnabled(True)
                    self.ui.pb_resume.setEnabled(False)
                else:
                    QMessageBox.information(
                        self, 'Message',
                        'The selected photo should be 128×128 or 512×512')

            else:
                QMessageBox.information(self, 'Message',
                                        "File should be image")

    def Outer_Frame(self, cwidth, rwidth, img, imgwidth, imgheight):
        img[0:rwidth, 0:] = 0
        img[imgheight - rwidth:imgheight, 0:] = 0
        img[0:, 0:cwidth] = 0
        img[0:, imgwidth - cwidth:imgwidth] = 0
        return img

    def Spin_Box(self):
        self.Step = self.ui.spinBox.value()

    def Pause(self):
        self.ui.pb_resume.setEnabled(True)
        self.pause = False

    def Resume(self):
        if self.pause == False:
            self.pause = True
            self.FFT_IFFT()

    def FFT_IFFT(self):
        self.pause = True
        self.ui.pb_start.setEnabled(False)
        self.ui.pb_pause.setEnabled(True)
        self.rows, self.cols = self.image.shape
        self.crow, self.ccol = self.rows / 2, self.cols / 2
        progress = 0

        while (self.Counter < int(self.cols / 2)) and self.loop == 1:
            if self.pause:
                self.Counter = self.Counter + self.Step
                if self.Counter > int(self.cols / 2):
                    if progress < 100:
                        self.Counter = int(self.cols / 2)
                    else:
                        break

                progress = round(self.Counter * (100 / int(self.cols / 2)))
                self.ui.progressBar.setProperty("value", progress)

                f = np.fft.fft2(self.image)
                fshift = np.fft.fftshift(f)
                self.Outer_Frame(self.Counter, self.Counter, fshift, self.rows,
                                 self.cols)
                magnitude_spectrum = 20 * np.log(np.abs(fshift))
                trans = qimage2ndarray.array2qimage(magnitude_spectrum)
                res = QPixmap(trans).scaled(321, 271)
                self.ui.lab_Fourier.setPixmap(res)

                f_ishift = np.fft.ifftshift(fshift)
                img_back = np.fft.ifft2(f_ishift)
                img_back = np.abs(img_back)
                trans = qimage2ndarray.array2qimage(img_back)
                res = QPixmap(trans).scaled(321, 271)
                self.ui.lab_original.setPixmap(res)
                QApplication.processEvents()
                time.sleep(0.1)

            else:
                break

        if self.pause and self.loop == 1:
            self.Counter = 0
            self.loop = 2

        if self.pause:

            while (self.Counter < int(self.cols / 2)) and self.loop == 2:
                if self.pause:
                    self.Counter = self.Counter + self.Step
                    if self.Counter > int(self.cols / 2):
                        if progress < 100:
                            self.Counter = int(self.cols / 2)
                        else:
                            break
                    progress = round(self.Counter * (100 / int(self.cols / 2)))
                    self.ui.progressBar.setProperty("value", progress)

                    f = np.fft.fft2(self.image)
                    fshift = np.fft.fftshift(f)
                    fshift[int(self.crow - self.Counter):int(self.crow +
                                                             self.Counter),
                           int(self.ccol - self.Counter):int(self.ccol +
                                                             self.Counter)] = 0
                    magnitude_spectrum = 20 * np.log(np.abs(fshift))
                    trans = qimage2ndarray.array2qimage(magnitude_spectrum)
                    res = QPixmap(trans).scaled(321, 271)
                    self.ui.lab_Fourier.setPixmap(res)

                    f_ishift = np.fft.ifftshift(fshift)
                    img_back = np.fft.ifft2(f_ishift)
                    img_back = np.abs(img_back)
                    trans = qimage2ndarray.array2qimage(img_back)
                    res = QPixmap(trans).scaled(321, 271)
                    self.ui.lab_original.setPixmap(res)
                    QApplication.processEvents()
                    time.sleep(0.1)

                else:
                    break

        if self.pause and self.loop == 2:
            self.Counter = 0
            self.loop = 1
            self.ui.pb_resume.setEnabled(False)
            self.ui.pb_pause.setEnabled(False)
            self.ui.pb_start.setEnabled(True)
Exemplo n.º 6
0
class ApplicationWindow(QtWidgets.QMainWindow):
    def __init__(self):
        super(ApplicationWindow, self).__init__()
        self.ui = Ui_Form()
        self.ui.setupUi(self)
        # self.ui.threadclass=threadclass()
        #  self.ui.threadclass.start()
        # self.ui.pb_browse.setIcon(self.Ui.QtGui.QIcon('123.jpg'))
        self.ui.pb_browse.clicked.connect(self.button_clicked)
        # self.ui.pb_start.clicked.connect(self.forier)

        # thread = threading.Thread(target=self.progressbar)
        # thread.start()

    def button_clicked(self):
        fileName, _filter = QFileDialog.getOpenFileName(
            self, "Title", "Default File",
            "Photos Files (*.png);;Photos Files (*.jpg)")

        if fileName:
            image = cv2.imread(fileName, 0)
            rows, cols = image.shape
            crow, ccol = rows / 2, cols / 2
            print(fileName)
            print(_filter)

            if (rows == 512 and cols == 512 or rows == 128 and cols == 128):
                trans = Image.fromarray(image)
                res = ImageQt(trans)
                self.ui.lab_original.setPixmap(QPixmap.fromImage(res))

                self.ui.pb_browse.setEnabled(False)
                for i in range(int(cols / 2)):
                    f = np.fft.fft2(image)
                    fshift = np.fft.fftshift(f)
                    self.box(i, i, fshift, rows, cols)
                    magnitude_spectrum = 20 * np.log(np.abs(fshift))
                    magnitude_spectrum = np.asarray(magnitude_spectrum,
                                                    dtype=np.uint8)
                    trans = Image.fromarray(magnitude_spectrum)
                    res = ImageQt(trans).scaled(321, 271)
                    self.ui.lab_Forier.setPixmap(QPixmap.fromImage(res))

                    f_ishift = np.fft.ifftshift(fshift)
                    img_back = np.fft.ifft2(f_ishift)
                    img_back = np.abs(img_back)
                    img_back = np.asarray(img_back, dtype=np.uint8)
                    original_image = Image.fromarray(img_back)
                    res = ImageQt(original_image).scaled(321, 271)
                    self.ui.lab_original.setPixmap(QPixmap.fromImage(res))

                    QApplication.processEvents()
                    time.sleep(0.001)

                for i in range(int(cols / 2)):
                    f = np.fft.fft2(image)
                    fshift = np.fft.fftshift(f)
                    fshift[int(crow - i):int(crow + i),
                           int(ccol - i):int(ccol + i)] = 0
                    magnitude_spectrum = 20 * np.log(np.abs(fshift))
                    magnitude_spectrum = np.asarray(magnitude_spectrum,
                                                    dtype=np.uint8)
                    trans = Image.fromarray(magnitude_spectrum)
                    res = ImageQt(trans).scaled(321, 271)
                    self.ui.lab_Forier.setPixmap(QPixmap.fromImage(res))

                    f_ishift = np.fft.ifftshift(fshift)
                    img_back = np.fft.ifft2(f_ishift)
                    img_back = np.abs(img_back)
                    img_back = np.asarray(img_back, dtype=np.uint8)
                    original_image = Image.fromarray(img_back)
                    res = ImageQt(original_image).scaled(321, 271)
                    self.ui.lab_original.setPixmap(QPixmap.fromImage(res))

                    QApplication.processEvents()
                    time.sleep(0.001)

            else:
                QMessageBox.information(
                    self, 'Message',
                    'The selected photo should be 128×128 or 512×512')
            self.ui.pb_browse.setEnabled(True)

    # def progressbar(self):
    #     val=count
    #     self.ui.progressBar.setValue(val)

    def box(self, cwidth, rwidth, img, imgwidth, imgheight):
        img[0:rwidth, 0:] = 0
        img[imgheight - rwidth:imgheight, 0:] = 0
        img[0:, 0:cwidth] = 0
        img[0:, imgwidth - cwidth:imgwidth] = 0
        return img