예제 #1
0
class DialogOptions(QtGui.QDialog):

    def __init__(self, number_of_landmarks=77, parent=None):
        QtGui.QDialog.__init__(self)
        self.ui = Ui_Dialog()
        self.ui.setupUi(self)

        self.initUI(number_of_landmarks)

    def initUI(self, number_of_landmarks):
        self.ui.graphicsView.scale(0.21, 0.21)
        self.ui.scene = QtGui.QGraphicsScene()
        self.ui.scene.setSceneRect(QtCore.QRectF())
        self.ui.graphicsView.setScene(self.ui.scene)
        self.ui.graphicsView.setInteractive(True)
        #QtGui.QGraphicsPixmapItem(pixmap, scene=self.ui.scene)
        self.ui.pushButton.clicked.connect(lambda : self.select_part('eyebrows'))
        self.ui.pushButton_2.clicked.connect(lambda : self.select_part('eyes'))
        self.ui.pushButton_3.clicked.connect(lambda : self.select_part('mouth'))
        self.ui.pushButton_4.clicked.connect(lambda : self.select_part('nose'))
      
        self.load_image(os.path.join(os.path.dirname(__file__), 
                        "Images/landmarking_1.jpg"))
        self.load_landmarks(range(number_of_landmarks))
        self.setWindowTitle('Landmarking Selection')
        self.exec_()

    def load_image(self, image_path):
        """Load Image in graphics view of dialog"""
        qitmp = toqimage(io.imread(image_path))
        pix = QtGui.QGraphicsPixmapItem(QtGui.QPixmap(QtGui.QPixmap.fromImage(qitmp)), scene=self.ui.scene)

    def load_landmarks(self, number_landmarks):
        """Set pixmap items in landmarks position and set"""
        for n in number_landmarks:
            Landmark(n, STATIC_LANDMARKS[n][0], STATIC_LANDMARKS[n][1], 30, 30, scene=self.ui.scene, flag=QtGui.QGraphicsItem.ItemIsSelectable, text=True)

    def get_number_landmarks(self):
        """Return the number of landmarks in ascending order selected by ctrl + click to be used."""
        landmarks = filter(lambda x: isinstance(x, Landmark) and x.isSelected(), self.ui.scene.items())
        clear_landmarks = [l.nro_landmark for l in landmarks]
        clear_landmarks.reverse()
        return clear_landmarks

    def select_part(self, name_part):
        """Set as selected all the landmarks in the anatomical chosen part."""
        landmarks_to_select = STATIC_POSITIONS[name_part]
        landmarks = filter(lambda x: isinstance(x, Landmark) and x.nro_landmark in landmarks_to_select, self.ui.scene.items())
        map(lambda x: x.setSelected(True) if x.isSelected() == False else x.setSelected(False), landmarks)
예제 #2
0
    def __init__(self, number_of_landmarks=77, parent=None):
        QtGui.QDialog.__init__(self)
        self.ui = Ui_Dialog()
        self.ui.setupUi(self)

        self.initUI(number_of_landmarks)
예제 #3
0
class DialogOptions(QtGui.QDialog):
    def __init__(self, number_of_landmarks=77, parent=None):
        QtGui.QDialog.__init__(self)
        self.ui = Ui_Dialog()
        self.ui.setupUi(self)

        self.initUI(number_of_landmarks)

    def initUI(self, number_of_landmarks):
        self.ui.graphicsView.scale(0.21, 0.21)
        self.ui.scene = QtGui.QGraphicsScene()
        self.ui.scene.setSceneRect(QtCore.QRectF())
        self.ui.graphicsView.setScene(self.ui.scene)
        self.ui.graphicsView.setInteractive(True)
        #QtGui.QGraphicsPixmapItem(pixmap, scene=self.ui.scene)
        self.ui.pushButton.clicked.connect(
            lambda: self.select_part('eyebrows'))
        self.ui.pushButton_2.clicked.connect(lambda: self.select_part('eyes'))
        self.ui.pushButton_3.clicked.connect(lambda: self.select_part('mouth'))
        self.ui.pushButton_4.clicked.connect(lambda: self.select_part('nose'))

        self.load_image(
            os.path.join(os.path.dirname(__file__),
                         "Images/landmarking_1.jpg"))
        self.load_landmarks(range(number_of_landmarks))
        self.setWindowTitle('Landmarking Selection')
        self.exec_()

    def load_image(self, image_path):
        """Load Image in graphics view of dialog"""
        qitmp = toqimage(io.imread(image_path))
        pix = QtGui.QGraphicsPixmapItem(QtGui.QPixmap(
            QtGui.QPixmap.fromImage(qitmp)),
                                        scene=self.ui.scene)

    def load_landmarks(self, number_landmarks):
        """Set pixmap items in landmarks position and set"""
        for n in number_landmarks:
            Landmark(n,
                     STATIC_LANDMARKS[n][0],
                     STATIC_LANDMARKS[n][1],
                     30,
                     30,
                     scene=self.ui.scene,
                     flag=QtGui.QGraphicsItem.ItemIsSelectable,
                     text=True)

    def get_number_landmarks(self):
        """Return the number of landmarks in ascending order selected by ctrl + click to be used."""
        landmarks = filter(
            lambda x: isinstance(x, Landmark) and x.isSelected(),
            self.ui.scene.items())
        clear_landmarks = [l.nro_landmark for l in landmarks]
        clear_landmarks.reverse()
        return clear_landmarks

    def select_part(self, name_part):
        """Set as selected all the landmarks in the anatomical chosen part."""
        landmarks_to_select = STATIC_POSITIONS[name_part]
        landmarks = filter(
            lambda x: isinstance(x, Landmark) and x.nro_landmark in
            landmarks_to_select, self.ui.scene.items())
        map(
            lambda x: x.setSelected(True)
            if x.isSelected() == False else x.setSelected(False), landmarks)
예제 #4
0
    def __init__(self, number_of_landmarks=77, parent=None):
        QtGui.QDialog.__init__(self)
        self.ui = Ui_Dialog()
        self.ui.setupUi(self)

        self.initUI(number_of_landmarks)