def __init__(self): """ Main loop of the UI :param mainWindow: QMainWindow Object """ #super(ApplicationWindow, self).setupUi(starterWindow) super(ApplicationWindow, self).__init__() self.ui = Ui_MainWindow() self.ui.setupUi(self) # Load Buttons #self.loadButtons = [self.actionImage1, self.actionImage2] # Images Lists self.inputImages = [self.ui.img1,self.ui.img2] self.updatedImages = [self.ui.img1_component,self.ui.img2_component] self.outputImages = [self.ui.output1,self.ui.output2] self.imagesModels = [..., ...] self.imageWidgets = [self.ui.img1,self.ui.img2, self.ui.img1_component,self.ui.img2_component,self.ui.output1,self.ui.output2] self.heights = [..., ...] self.weights = [..., ...] # Combo Lists self.imagecombos = [self.ui.img1_combo,self.ui.img2_combo] #self.imageCombos = [self.ui.img1_combo,self.ui.img2_combo] #self.componentCombos = [self.combo_select_mode1, self.combo_select_mode2] self.counter=-1 self.data=[] self.ui.pause.clicked.connect(lambda:self.loadFile()) self.ui.actionOpen.triggered.connect(lambda:self.Components()) self.ui.img1_combo.currentTextChanged.connect(lambda:self.Components(0)) self.ui.img2_combo.currentTextChanged.connect(lambda:self.Components(1)) self.setupImagesView()
def __init__(self): super(ApplicationWindow, self).__init__() self.ui = Ui_MainWindow() self.ui.setupUi(self) self.count = -1 self.counter = -1 self.counter2 = -1 self.data = [] self.paths = [] self.Size = [] self.imgdata = [] self.ui.actionOpen1.triggered.connect(lambda: self.opensignal()) self.ui.img1_combo.currentTextChanged.connect( lambda: self.Components(2)) self.ui.img2_combo.currentTextChanged.connect( lambda: self.Components(3)) self.ui.component1_type.currentTextChanged.connect( lambda: self.setcombotext(self.ui.component1_type.currentText())) self.ui.component2_type.currentTextChanged.connect( lambda: self.Mixer()) self.ui.component1_type.currentTextChanged.connect( lambda: self.Mixer()) self.ui.component1_img.currentTextChanged.connect(lambda: self.Mixer()) self.ui.component2_img.currentTextChanged.connect(lambda: self.Mixer()) self.ui.component1_slider.valueChanged.connect(lambda: self.Mixer()) self.ui.component2_slider.valueChanged.connect(lambda: self.Mixer())
class ApplicationWindow(QtWidgets.QMainWindow): def __init__(self): """ Main loop of the UI :param mainWindow: QMainWindow Object """ #super(ApplicationWindow, self).setupUi(starterWindow) super(ApplicationWindow, self).__init__() self.ui = Ui_MainWindow() self.ui.setupUi(self) # Load Buttons #self.loadButtons = [self.actionImage1, self.actionImage2] # Images Lists self.inputImages = [self.ui.img1,self.ui.img2] self.updatedImages = [self.ui.img1_component,self.ui.img2_component] self.outputImages = [self.ui.output1,self.ui.output2] self.imagesModels = [..., ...] self.imageWidgets = [self.ui.img1,self.ui.img2, self.ui.img1_component,self.ui.img2_component,self.ui.output1,self.ui.output2] self.heights = [..., ...] self.weights = [..., ...] # Combo Lists self.imagecombos = [self.ui.img1_combo,self.ui.img2_combo] #self.imageCombos = [self.ui.img1_combo,self.ui.img2_combo] #self.componentCombos = [self.combo_select_mode1, self.combo_select_mode2] self.counter=-1 self.data=[] self.ui.pause.clicked.connect(lambda:self.loadFile()) self.ui.actionOpen.triggered.connect(lambda:self.Components()) self.ui.img1_combo.currentTextChanged.connect(lambda:self.Components(0)) self.ui.img2_combo.currentTextChanged.connect(lambda:self.Components(1)) self.setupImagesView() def loadFile(self, imgID): """ Load the File from User :param imgID: 0 or 1 :return: """ # Open File & Check if it was loaded correctly logger.info("Browsing the files...") repo_path = "D:\Study\Courses\Python\DSP Tasks - 3rd Year\sbe309-2020-task3-Abdullah-Alrefaey\images" self.filename, self.format = QtWidgets.QFileDialog.getOpenFileName(None, "Load Image", repo_path, "*.jpg;;" "*.jpeg;;" "*.png;;") imgName = self.filename.split('/')[-1] if self.filename == "": pass else: image = cv2.imread(self.filename, flags=cv2.IMREAD_GRAYSCALE).T self.heights[imgID], self.weights[imgID] = image.shape self.imagesModels[imgID] = image_components(self.filename) if ty# Importing Packages
def __init__(self): super(ApplicationWindow, self).__init__() self.ui = Ui_MainWindow() self.ui.setupUi(self) self.images = [ self.ui.img1, self.ui.img2, self.ui.img1_component, self.ui.img2_component, self.ui.output1, self.ui.output2 ] self.img_combo = [self.ui.img1_combo, self.ui.img2_combo] self.sliders = [self.ui.component1_slider, self.ui.component2_slider] self.types = [self.ui.component1_type, self.ui.component2_type] self.opimg = [self.ui.component1_img, self.ui.component2_img] self.enable = [ self.ui.output_channel, self.ui.component1_img, self.ui.component2_img, self.ui.component1_type, self.ui.component2_type, self.ui.component1_slider, self.ui.component2_slider, self.ui.img1_combo, self.ui.img2_combo ] self.ui.component1_type.addItem("Uniphase") self.ui.component1_type.addItem("Unimagnitude") self.ui.component2_type.clear() for i in range(9): self.enable[i].setEnabled(False) for i in range(len(self.images)): self.images[i].ui.histogram.hide() self.images[i].ui.roiBtn.hide() self.images[i].ui.menuBtn.hide() self.images[i].ui.roiPlot.hide() self.counter = -1 self.counter2 = -1 self.data = [] self.paths = [] self.imgwidth = [] self.imgheight = [] self.ui.actionOpen1.triggered.connect(lambda: self.opensignal(0)) self.ui.actionOpen2.triggered.connect(lambda: self.opensignal(1)) self.ui.img1_combo.currentTextChanged.connect( lambda: self.Components(0)) self.ui.img2_combo.currentTextChanged.connect( lambda: self.Components(1)) self.ui.output_channel.currentTextChanged.connect( lambda: self.mixer(0, False)) self.ui.component2_type.currentTextChanged.connect( lambda: self.mixer(0, False)) self.ui.component1_type.currentTextChanged.connect( lambda: self.mixer(1, True)) self.ui.component1_img.currentTextChanged.connect( lambda: self.mixer(0, False)) self.ui.component2_img.currentTextChanged.connect( lambda: self.mixer(0, False)) self.ui.component1_slider.valueChanged.connect( lambda: self.mixer(0, False)) self.ui.component2_slider.valueChanged.connect( lambda: self.mixer(0, False))
class ApplicationWindow(QtWidgets.QMainWindow): def __init__(self): super(ApplicationWindow, self).__init__() self.ui = Ui_MainWindow() self.ui.setupUi(self) self.images = [ self.ui.img1, self.ui.img2, self.ui.img1_component, self.ui.img2_component, self.ui.output1, self.ui.output2 ] self.img_combo = [self.ui.img1_combo, self.ui.img2_combo] self.sliders = [self.ui.component1_slider, self.ui.component2_slider] self.types = [self.ui.component1_type, self.ui.component2_type] self.opimg = [self.ui.component1_img, self.ui.component2_img] self.enable = [ self.ui.output_channel, self.ui.component1_img, self.ui.component2_img, self.ui.component1_type, self.ui.component2_type, self.ui.component1_slider, self.ui.component2_slider, self.ui.img1_combo, self.ui.img2_combo ] for i in range(9): self.enable[i].setEnabled(False) # self.images=[self.ui.img2,self.ui.img1_component,self.ui.img2_component,self.ui.output1,self.ui.output2] for i in range(len(self.images)): self.images[i].ui.histogram.hide() self.images[i].ui.roiBtn.hide() self.images[i].ui.menuBtn.hide() self.images[i].ui.roiPlot.hide() self.counter = -1 self.data = [] self.paths = [] self.imgwidth = [] self.imgheight = [] self.ui.actionOpen1.triggered.connect(lambda: self.opensignal(0)) self.ui.actionOpen2.triggered.connect(lambda: self.opensignal(1)) self.ui.img1_combo.currentTextChanged.connect( lambda: self.Components(0)) self.ui.img2_combo.currentTextChanged.connect( lambda: self.Components(1)) self.ui.output_channel.currentTextChanged.connect(lambda: self.mixer()) for i in range(0, 2): self.sliders[i].valueChanged.connect(lambda: self.mixer()) self.types[i].currentTextChanged.connect(lambda: self.mixer()) self.opimg[i].currentTextChanged.connect(lambda: self.mixer()) def readsignal(self): self.fname = QtGui.QFileDialog.getOpenFileName( self, ' Open File', os.getenv('home'), "jpg(*.jpg) ;; jpeg(*.jpeg) ") self.path = self.fname[0] self.imgdata = inputimg(self.path) self.img = cv2.imread(self.path, 0) self.height, self.width = self.img.shape if (self.path): pass def opensignal(self, num): if num == 0: self.readsignal() self.paths.append(self.path) self.imgwidth.append(self.width) self.imgheight.append(self.height) self.ui.img1_combo.setEnabled(True) #print(self.imgwidth , self.imgheight) self.ui.images[0].setImage((self.imgdata.img).T) #self.ui.images[0].view.setRange(xRange=[0,self.width], yRange=[0,self.height],padding=0) if num == 1: self.readsignal() if self.width != self.imgwidth[0] or self.height != self.imgheight[ 0]: QMessageBox.about( self, "Error !", "Please Choose Another image with the same dimensions") else: self.paths.append(self.path) self.imgwidth.append(self.width) self.imgheight.append(self.height) self.ui.images[1].setImage((self.imgdata.img).T) for i in range(9): self.enable[i].setEnabled(True) #self.ui.images[1].view.setRange(xRange=[0,self.width], yRange=[0,self.height],padding=0) def Components(self, y): self.images[2 + y % 2].clear() # if y==0 : # self.path=self.paths[0] # else: # self.path= self.paths[1] self.path = self.paths[y % 2] self.imgdata = inputimg(self.path) for i in range(0, y + 1): if self.img_combo[i].currentText() == "Magnitude": x = self.imgdata.magnitude print(self.img_combo[i].currentText()) print(y) elif self.img_combo[i].currentText() == "Phase": x = self.imgdata.phaseshift print(self.img_combo[i].currentText()) print(y) elif self.img_combo[i].currentText() == "Real": x = self.imgdata.realshift print(self.img_combo[i].currentText()) print(y) elif self.img_combo[i].currentText() == "Imaginary": x = self.imgdata.imaginaryshift print(self.img_combo[i].currentText()) print(y) else: self.images[2 + y % 2].clear() self.images[2 + y % 2].setImage(x.T) self.images[2 + y % 2].view.setRange(xRange=[0, self.imgheight[y % 2]], yRange=[0, self.imgwidth[y % 2]], padding=0) def mixer(self): self.gain1 = self.ui.component1_slider.value() self.gain2 = self.ui.component2_slider.value() self.type1 = self.types[0].currentText() self.type2 = self.types[1].currentText() self.img1 = self.opimg[0].currentText() self.img2 = self.opimg[1].currentText() if (self.img1 != self.img2): self.path1 = self.paths[0] self.path2 = self.paths[1] self.imgmix1 = inputimg(self.path1) self.imgmix2 = inputimg(self.path2) if (self.type1 == "Magnitude" or self.type1 == "Phase") and (self.type2 == "Magnitude" or self.type2 == "Phase"): self.mode = "magphase" print("check1") print(self.type1, self.type2) print(self.img1, self.img2) elif (self.type1 == "Real" or self.type1 == "Imaginary") and ( self.type2 == "Real" or self.type2 == "Imaginary"): self.mode = "realimg" print(self.type1, self.type2) print(self.img1, self.img2) print("check2") else: self.mode = "other" print("can't mix") print(self.type1, self.type2) print(self.img1, self.img2) if (self.img1 == "Image 1" and self.img2 == "Image 2"): output = self.imgmix1.mix(self.imgmix2, self.gain1, self.gain2, self.mode, self.type1, self.type2) print("check3") else: output = self.imgmix2.mix(self.imgmix1, self.gain1, self.gain2, self.mode, self.type1, self.type2) print("check4", "\n") elif (self.img1 == "Image 1" and self.img2 == "Image 1"): self.path1 = self.paths[0] output = inputimg(self.path1).img elif (self.img1 == "Image 2" and self.img2 == "Image 2"): self.path1 = self.paths[1] output = inputimg(self.path1).img else: print(self.type1, self.type2) print(self.img1, self.img2) print(" Unexpected error") #show the same image ba3deen if self.ui.output_channel.currentText() == "Output 1": self.images[4].setImage((output).T) elif self.ui.output_channel.currentText() == "Output 2": # self.ui.component1_type.setItemText(0) self.images[5].setImage((output).T)
class ApplicationWindow(QtWidgets.QMainWindow): def __init__(self): super(ApplicationWindow, self).__init__() self.ui = Ui_MainWindow() self.ui.setupUi(self) self.count = -1 self.counter = -1 self.counter2 = -1 self.data = [] self.paths = [] self.Size = [] self.imgdata = [] self.ui.actionOpen1.triggered.connect(lambda: self.opensignal()) self.ui.img1_combo.currentTextChanged.connect( lambda: self.Components(2)) self.ui.img2_combo.currentTextChanged.connect( lambda: self.Components(3)) self.ui.component1_type.currentTextChanged.connect( lambda: self.setcombotext(self.ui.component1_type.currentText())) self.ui.component2_type.currentTextChanged.connect( lambda: self.Mixer()) self.ui.component1_type.currentTextChanged.connect( lambda: self.Mixer()) self.ui.component1_img.currentTextChanged.connect(lambda: self.Mixer()) self.ui.component2_img.currentTextChanged.connect(lambda: self.Mixer()) self.ui.component1_slider.valueChanged.connect(lambda: self.Mixer()) self.ui.component2_slider.valueChanged.connect(lambda: self.Mixer()) def readsignal(self): logger.info("Browsing image ...") self.fname = QtGui.QFileDialog.getOpenFileName( self, ' Open File', os.getenv('home'), "jpg(*.jpg) ;; jpeg(*.jpeg) ") self.path = self.fname[0] self.img = cv2.imread(self.path, 0) self.height, self.width = self.img.shape if (self.path): logger.info(" Browsed Successfully ! ") else: logger.warning(" No image to open ") def opensignal(self): self.readsignal() if (len(self.imgdata) != 0 and (self.width != self.Size[0] or self.height != self.Size[1])): QMessageBox.about( self, "Error !", "Please Choose Another image with the same dimensions") logger.warning("Opened Image with different dimensions ...") else: self.count += 1 self.ui.images[self.count % 2].clear() if (len(self.imgdata) == 2): self.imgdata = [] self.Size = [] print(self.imgdata) print(self.Size) self.imgdata.append(inputimg(self.path)) print(self.width) print(self.height) self.ui.enable[self.count % 2].setEnabled(True) self.Size.append(self.width) self.Size.append(self.height) self.ui.images[self.count % 2].setImage( (self.imgdata[self.count % 2].img).T) self.ui.images[self.count % 2].view.setAspectLocked(False) logger.info(f" Opening image {1+self.count%2} ...") if (len(self.imgdata) == 2): for i in range(1, 9): self.ui.enable[i].setEnabled(True) # def Reset(self): def Components(self, number): imageComponetns = [ self.ui.img1_combo.currentText(), self.ui.img2_combo.currentText() ] component = [0, 0] component[number - 2] = self.imgdata[number - 2].components[imageComponetns[number - 2]] logger.info(f" Presenting {imageComponetns[number-2]}.... ") self.ui.images[number].setImage(component[number - 2].T) self.ui.images[number].view.setAspectLocked(False) def Mixer(self): ratio = [ self.ui.component1_slider.value() / 100, self.ui.component2_slider.value() / 100 ] component = [ self.ui.component1_type.currentText(), self.ui.component2_type.currentText() ] image = [ int(self.ui.component1_img.currentText()[-1]) - 1, int(self.ui.component2_img.currentText()[-1]) - 1 ] Mix = [0, 0] MagnitudeIndex = 0 PhaseIndex = 1 if component[0] == "Real" or component[0] == "Imaginary": for i in range(2): Mix[i] = ratio[i] * self.imgdata[image[i]].Components[ component[i]] + (1 - ratio[i]) * self.imgdata[ 1 - image[i]].Components[component[i]] MixInverse = np.real(np.fft.ifft2(Mix[0] + Mix[1])) # print(mixInverse) else: if component[0] == "Phase" or component[0] == "Uniphase": MagnitudeIndex = 1 PhaseIndex = 0 Mix[PhaseIndex] = np.exp( 1j * (ratio[PhaseIndex] * self.imgdata[ image[PhaseIndex]].Components[component[PhaseIndex]] + (1 - ratio[PhaseIndex]) * self.imgdata[ 1 - image[PhaseIndex]].Components[component[PhaseIndex]])) Mix[MagnitudeIndex] = (ratio[MagnitudeIndex] * self.imgdata[image[ MagnitudeIndex]].Components[component[MagnitudeIndex]]) + ( (1 - ratio[MagnitudeIndex]) * self.imgdata[1 - image[MagnitudeIndex]].Components[ component[MagnitudeIndex]]) MixInverse = np.real(np.fft.ifft2(Mix[0] * Mix[1])) self.ui.images[int(self.ui.output_channel.currentText()[-1]) + 3].setImage(MixInverse.T) def setcombotext(self, type1): self.ui.component2_type.clear() if (type1 == "Magnitude" or type1 == "Unimagnitude"): self.ui.component2_type.addItem("Phase") self.ui.component2_type.addItem("Uniphase") self.ui.component2_type.setCurrentText("Phase") elif (type1 == "Phase" or type1 == "Uniphase"): self.ui.component2_type.addItem("Magnitude") self.ui.component2_type.addItem("Unimagnitude") self.ui.component2_type.setCurrentText("Magnitude") elif type1 == "Real": self.ui.component2_type.addItem("Imaginary") self.ui.component2_type.setCurrentText("Imaginary") elif type1 == "Imaginary": self.ui.component2_type.addItem("Real") self.ui.component2_type.setCurrentText("Real")
class ApplicationWindow(QtWidgets.QMainWindow): def __init__(self): super(ApplicationWindow, self).__init__() self.ui = Ui_MainWindow() self.ui.setupUi(self) self.images = [ self.ui.img1, self.ui.img2, self.ui.img1_component, self.ui.img2_component, self.ui.output1, self.ui.output2 ] self.img_combo = [self.ui.img1_combo, self.ui.img2_combo] self.sliders = [self.ui.component1_slider, self.ui.component2_slider] self.types = [self.ui.component1_type, self.ui.component2_type] self.opimg = [self.ui.component1_img, self.ui.component2_img] self.enable = [ self.ui.output_channel, self.ui.component1_img, self.ui.component2_img, self.ui.component1_type, self.ui.component2_type, self.ui.component1_slider, self.ui.component2_slider, self.ui.img1_combo, self.ui.img2_combo ] self.ui.component1_type.addItem("Uniphase") self.ui.component1_type.addItem("Unimagnitude") self.ui.component2_type.clear() for i in range(9): self.enable[i].setEnabled(False) for i in range(len(self.images)): self.images[i].ui.histogram.hide() self.images[i].ui.roiBtn.hide() self.images[i].ui.menuBtn.hide() self.images[i].ui.roiPlot.hide() self.counter = -1 self.counter2 = -1 self.data = [] self.paths = [] self.imgwidth = [] self.imgheight = [] self.ui.actionOpen1.triggered.connect(lambda: self.opensignal(0)) self.ui.actionOpen2.triggered.connect(lambda: self.opensignal(1)) self.ui.img1_combo.currentTextChanged.connect( lambda: self.Components(0)) self.ui.img2_combo.currentTextChanged.connect( lambda: self.Components(1)) self.ui.output_channel.currentTextChanged.connect( lambda: self.mixer(0, False)) self.ui.component2_type.currentTextChanged.connect( lambda: self.mixer(0, False)) self.ui.component1_type.currentTextChanged.connect( lambda: self.mixer(1, True)) self.ui.component1_img.currentTextChanged.connect( lambda: self.mixer(0, False)) self.ui.component2_img.currentTextChanged.connect( lambda: self.mixer(0, False)) self.ui.component1_slider.valueChanged.connect( lambda: self.mixer(0, False)) self.ui.component2_slider.valueChanged.connect( lambda: self.mixer(0, False)) # for i in range(0,2): # self.sliders[i].valueChanged.connect(lambda:self.mixer()) # # self.types[i].currentTextChanged.connect(lambda:self.mixer()) # self.opimg[i].currentTextChanged.connect(lambda:self.mixer()) def readsignal(self): logger.info("Browsing image ...") self.fname = QtGui.QFileDialog.getOpenFileName( self, ' Open File', os.getenv('home'), "jpg(*.jpg) ;; jpeg(*.jpeg) ") self.path = self.fname[0] self.imgdata = inputimg(self.path) self.img = cv2.imread(self.path, 0) self.height, self.width = self.img.shape if (self.path == True): logger.warning(" No image to open ") else: logger.info(" Browsed Successfully ! ") def opensignal(self, num): if num == 0: self.readsignal() self.paths.append(self.path) self.imgwidth.append(self.width) self.imgheight.append(self.height) self.ui.img1_combo.setEnabled(True) self.ui.images[0].setImage((self.imgdata.img).T) self.ui.images[0].view.setAspectLocked(False) logger.info("Opened First image ...") if num == 1: self.readsignal() if self.width != self.imgwidth[0] or self.height != self.imgheight[ 0]: QMessageBox.about( self, "Error !", "Please Choose Another image with the same dimensions") logger.warning("Opened Image with different dimensions ...") else: self.paths.append(self.path) self.imgwidth.append(self.width) self.imgheight.append(self.height) self.ui.images[1].setImage((self.imgdata.img).T) self.ui.images[1].view.setAspectLocked(False) for i in range(9): self.enable[i].setEnabled(True) logger.info(" Opening Second image ...") def Components(self, y): self.images[2 + y % 2].clear() self.path = self.paths[y % 2] self.imgdata = inputimg(self.path) for i in range(0, y + 1): if self.img_combo[i].currentText() == "Magnitude": x = self.imgdata.magnitude logger.info(" Presenting Magnitude.... ") elif self.img_combo[i].currentText() == "Phase": x = self.imgdata.phaseshift logger.info(" Presenting Phase.... ") elif self.img_combo[i].currentText() == "Real": x = self.imgdata.realshift logger.info(" Presenting Real.... ") elif self.img_combo[i].currentText() == "Imaginary": x = self.imgdata.imaginaryshift logger.info(" Presenting Imaginary.... ") else: self.images[2 + y % 2].clear() self.images[2 + y % 2].setImage(x.T) self.images[2 + y % 2].view.setAspectLocked(False) # for i in range (0,y+1): # n=self.img_combo[i].currentText().lower() # x=self.imgdata.n # self.images[2+y%2].view.setRange(xRange=[0,self.imgheight[y%2]], yRange=[0,self.imgwidth[y%2]],padding=0) def mixer(self, z, flag): gain1 = self.ui.component1_slider.value() gain2 = self.ui.component2_slider.value() type1 = self.types[0].currentText() type2 = self.ui.component2_type.currentText() type22 = self.ui.component2_type.currentText() self.img1 = self.opimg[0].currentText() self.img2 = self.opimg[1].currentText() opchannel = self.ui.output_channel.currentText() if (flag): self.setcombotext(type1, type22) if (self.img1 != self.img2): self.path1 = self.paths[0] self.path2 = self.paths[1] self.imgmix1 = inputimg(self.path1) self.imgmix2 = inputimg(self.path2) if (type1 == "Magnitude" and type2 == "Phase") or (type2 == "Magnitude" and type1 == "Phase"): mode = "magphase" elif (type1 == "Real" or type1 == "Imaginary") and (type2 == "Real" or type2 == "Imaginary"): mode = "realimg" elif (type1 == "Unimagnitude" and type2 == "Phase") or (type2 == "Unimagnitude" and type1 == "Phase"): mode = "unimag" elif (type1 == "Uniphase" and type2 == "Magnitude") or (type2 == "Uniphase" and type1 == "Magnitude"): mode = "uniphase" elif (type1 == "Uniphase" and type2 == "Unimagnitude") or ( type2 == "Uniphase" and type1 == "Unimagnitude"): mode = "uniuni" else: logger.info("Error! Can't Mix ... ") try: if (self.img1 == "Image 1" and self.img2 == "Image 2"): output = self.imgmix1.mix(self.imgmix2, gain1, gain2, mode, type1, type2) else: output = self.imgmix2.mix(self.imgmix1, gain1, gain2, mode, type1, type2) except: pass try: if self.ui.output_channel.currentText() == "Output 1": self.images[4].setImage((output).T) elif self.ui.output_channel.currentText() == "Output 2": self.images[5].setImage((output).T) except: pass # self.output(output) if (self.img1 == "Image 1" and self.img2 == "Image 1"): # logger.warning("Mixing the same image! , Dosen't affect the image") self.path1 = self.paths[0] output = inputimg(self.path1).img elif (self.img1 == "Image 2" and self.img2 == "Image 2"): # logger.warning("Mixing the same image! , Dosen't affect the image") self.path1 = self.paths[1] output = inputimg(self.path1).img try: logger.info( f"Mixing {gain1}% of {self.img1} {type1} and {gain2}% of {self.img2} {type2} in {self.ui.output_channel.currentText()} at mixing mood of: {mode} " ) except: pass def setcombotext(self, type1, type2): # def setcombotext(self, type1, type2): self.ui.component2_type.clear() if (type1 == "Magnitude" or type1 == "Unimagnitude"): self.ui.component2_type.addItem("Phase") self.ui.component2_type.addItem("Uniphase") self.ui.component2_type.setCurrentText("Phase") elif (type1 == "Phase" or type1 == "Uniphase"): self.ui.component2_type.addItem("Magnitude") self.ui.component2_type.addItem("Unimagnitude") self.ui.component2_type.setCurrentText("Magnitude") elif type1 == "Real": self.ui.component2_type.addItem("Imaginary") self.ui.component2_type.setCurrentText("Imaginary") elif type1 == "Imaginary": self.ui.component2_type.addItem("Real") self.ui.component2_type.setCurrentText("Real")
class ApplicationWindow(QtWidgets.QMainWindow): def __init__(self): """ Main loop of the UI :param mainWindow: QMainWindow Object """ #super(ApplicationWindow, self).setupUi(starterWindow) super(ApplicationWindow, self).__init__() self.ui = Ui_MainWindow() self.ui.setupUi(self) # Load Buttons #self.loadButtons = [self.actionImage1, self.actionImage2] # Images Lists self.inputImages = [self.ui.img1,self.ui.img2] self.updatedImages = [self.ui.img1_component,self.ui.img2_component] self.outputImages = [self.ui.output1,self.ui.output2] self.imagesModels = [..., ...] self.imageWidgets = [self.ui.img1,self.ui.img2, self.ui.img1_component,self.ui.img2_component,self.ui.output1,self.ui.output2] self.heights = [..., ...] self.weights = [..., ...] # Combo Lists self.imagecombos = [self.ui.img1_combo,self.ui.img2_combo] #self.imageCombos = [self.ui.img1_combo,self.ui.img2_combo] #self.componentCombos = [self.combo_select_mode1, self.combo_select_mode2] self.counter=-1 self.data=[] self.ui.pause.clicked.connect(lambda:self.loadFile()) self.ui.actionOpen.triggered.connect(lambda:self.Components()) self.ui.img1_combo.currentTextChanged.connect(lambda:self.Components(0)) self.ui.img2_combo.currentTextChanged.connect(lambda:self.Components(1)) self.setupImagesView() def loadFile(self, imgID): """ Load the File from User :param imgID: 0 or 1 :return: """ # Open File & Check if it was loaded correctly logger.info("Browsing the files...") repo_path = "D:\Study\Courses\Python\DSP Tasks - 3rd Year\sbe309-2020-task3-Abdullah-Alrefaey\images" self.filename, self.format = QtWidgets.QFileDialog.getOpenFileName(None, "Load Image", repo_path, "*.jpg;;" "*.jpeg;;" "*.png;;") imgName = self.filename.split('/')[-1] if self.filename == "": pass else: image = cv2.imread(self.filename, flags=cv2.IMREAD_GRAYSCALE).T self.heights[imgID], self.weights[imgID] = image.shape self.imagesModels[imgID] = image_components(self.filename) if type(self.imagesModels[~imgID]) == type(...): # Create and Display Original Image self.displayImage(self.imagesModels[imgID].imgByte, self.inputImages[imgID]) self.updateCombos[imgID].setEnabled(True) logger.info(f"Added Image{imgID + 1}: {imgName} successfully") else: if self.heights[1] != self.heights[0] or self.weights[1] != self.weights[0]: self.showMessage("Warning!!", "Image sizes must be the same, please upload another image", QMessageBox.Ok, QMessageBox.Warning) logger.warning("Warning!!. Image sizes must be the same, please upload another image") else: self.displayImage(self.imagesModels[imgID].imgByte, self.inputImages[imgID]) self.updateCombos[imgID].setEnabled(True) logger.info(f"Added Image{imgID + 1}: {imgName} successfully") if self.updateCombos[0].isEnabled() and self.updateCombos[1].isEnabled(): self.enableOutputCombos() logger.info("ComboBoxes have been enabled successfully") def displayImage(self, data, widget): """ Display the given data :param data: 2d numpy array :param widget: ImageView object :return: """ widget.setImage(data) widget.view.setRange(xRange=[0, self.imagesModels[0].imgShape[0]], yRange=[0, self.imagesModels[0].imgShape[1]], padding=0) widget.ui.roiPlot.hide() def setupImagesView(self): """ Adjust the shape and scales of the widgets Remove unnecessary options :return: """ for widget in self.imageWidgets: widget.ui.histogram.hide() widget.ui.roiBtn.hide() widget.ui.menuBtn.hide() widget.ui.roiPlot.hide() widget.getView().setAspectLocked(False) widget.view.setAspectLocked(False)