def move_connect(self, event): if self.drawRadioButton.isChecked(): if self.view.currentIndex() == 0: x = event.pos().x() y = event.pos().y() - round( (self.image.height() - self.image.pixmap().height()) / 2) else: x = event.pos().x() y = event.pos().y() - round( (self.superImage.height() - self.superImage.pixmap().height()) / 2) if y < 0 or x < 0 or y >= self.image.pixmap().height( ) or x >= self.image.pixmap().width(): return if self.point == (-1, -1) or self.point == (x, y): self.point = (x, y) self.save_point(x, y) draw_markings(self.image_path, self.image, self.background, self.foreground, self.algs, self.superImage) return if abs(self.point[0] - x) < abs(self.point[1] - y): if self.point[1] > y: self.save_liney(x, self.point[0], y, self.point[1]) else: self.save_liney(self.point[0], x, self.point[1], y) else: if self.point[0] > x: self.save_linex(x, self.point[0], y, self.point[1]) else: self.save_linex(self.point[0], x, self.point[1], y) self.point = (x, y) draw_markings(self.image_path, self.image, self.background, self.foreground, self.algs, self.superImage)
def clear_markings(self): self.foreground[self.image_path].clear() self.background[self.image_path].clear() draw_markings(self.image_path, self.image, self.background, self.foreground, self.algs, self.superImage) draw_bounds(self.image_path, self.superImage, self.algs, self.foreground, self.background) self.image.update() self.superImage.update() self.result_image.update()
def calculate_superpixels(self): self.algs.compute_superpixels(self.superpixelSpinBox.value(), self.compactnessSpinBox.value(), self.iterationsSpinBox.value(), self.sigmaSpinBox.value()) self.algs.compute_neighbors() self.algs.compute_centers() draw_bounds(self.image_path, self.superImage, self.algs, self.foreground, self.background) draw_markings(self.image_path, self.image, self.background, self.foreground, self.algs, self.superImage) self.disable_buttons() self.enable_buttons(2) self.superpixelStatus.setText("Calculated") self.superpixelStatus.setStyleSheet("color: lime") if self.extractionStatus.text() == "Calculated": self.extractionStatus.setText("Need recalculation") self.extractionStatus.setStyleSheet("color: red") if self.clusteringStatus.text() == "Calculated": self.clusteringStatus.setText("Recalculation needed") self.clusteringStatus.setStyleSheet("color: red")
def move_start(self, event): if self.view.currentIndex() == 0: x = event.pos().x() y = event.pos().y() - round( (self.image.height() - self.image.pixmap().height()) / 2) else: x = event.pos().x() y = event.pos().y() - round( (self.superImage.height() - self.superImage.pixmap().height()) / 2) if y < 0 or x < 0 or y >= self.image.pixmap().height( ) or x >= self.image.pixmap().width(): return if self.histogramRadioButton.isChecked(): on_click_superpixel(self.plotMarked, self.views, self.algs, self.image_path, self.superImage, self.foreground, self.background, x, y) else: self.save_point(x, y) self.point = (x, y) draw_markings(self.image_path, self.image, self.background, self.foreground, self.algs, self.superImage)
def choose_image(self): if self.listWidget.currentItem() is not None: self.image_path = self.relpath + '/' + self.listWidget.currentItem( ).text() pixmap = QtGui.QPixmap(self.image_path) self.image.setPixmap(pixmap) self.image.mousePressEvent = self.move_start self.image.mouseMoveEvent = self.move_connect self.image.mouseReleaseEvent = self.release_move self.superImage.mousePressEvent = self.move_start self.superImage.mouseMoveEvent = self.move_connect self.superImage.mouseReleaseEvent = self.release_move self.enable_buttons(1) if self.image_path not in self.foreground: self.foreground[self.image_path] = [] self.background[self.image_path] = [] else: draw_markings(self.image_path, self.image, self.background, self.foreground, self.algs, self.superImage) draw_bounds(self.image_path, self.superImage, self.algs, self.foreground, self.background) self.plotMarked.clear() if self.algs.images_superpixels_uncertainties_node[ self.image_path]: self.draw_uncertainties() if self.image_path in self.algs.images_cosegmented: if self.result == "graphcut": self.draw_graph_cut() elif self.result == "kmeans": self.draw_kmeans() if self.image_path in self.groundtruth: self.draw_gt() elif self.compare_image.pixmap() is not None: self.compare_image.clear() else: self.disable_buttons()