Пример #1
0
 def _update_image(self):
     wt = WaitProcess
     wt.run()
     wt.change_info("Obteniendo imagen")
     wt.change_value(5)
     id = self._images_ui_synchronizer.get_selected_image_id()
     #verificar si la imagen seleccionada es distinta de la imagen actual
     clean_pipes = (Application.get_current_image_id() != id)
     #limpia las tuberías en caso de ser necesario
     if id is not None:
         if clean_pipes:
             Application.get_current_document().clean_pipes()
         wt.change_info("Cambiando imagen")
         wt.change_value(50)
         Application.set_current_image_id(id)  #cambiar la imagen actual
         img = Application.get_current_image()  #obtener la imagen actual
         self._ui.imageName.setText(
             img.DisplayName)  #actualiza el nombre mostrado de la imagen
         wt.change_info("Visualizando imagen")
         wt.change_value(65)
         #actualizar la vista de los tres planos de la imagen
         self._planes.Image = img
         #habilitar el procesameinto de la imagen
         self._ui.processImage.setEnabled(True)
         #habilitar la configuración de los filtros
         self._ui.filters.setEnabled(True)
         #habilitar la salva de la configuración de los filtros
         self._ui.actionGuardar_2.setEnabled(True)
         #habilitar la carga de la configuración de los filtros
         self._ui.actionCargar_configuraci_n.setEnabled(True)
         #actualizar la información de los filtros
         self._filters_ui_synchronizer.update()
     wt.stop()
Пример #2
0
    def _update_filters_properties(self):
        """
        Actualiza las propiedades que se muestran de los filtros
        """
        self._properties_tree.blockSignals(True)

        smooth = Application.get_current_document()._smooth_pipe
        self._iterations_prop.setText(1,str(smooth.NumberOfIterations))
        self._time_step_prop.setText(1,str(smooth.TimeStep))
        self._conductance_prop.setText(1,str(smooth.Conductance))
        self._smoother_prop.setText(1,str([smooth.NumberOfIterations,smooth.TimeStep,
                                           smooth.Conductance]))
        state = Qt.Unchecked
        if Application.get_current_document().usingSmoother():
            state = Qt.Checked
        self._smoother_prop.setCheckState(0,state)

        segment = Application.get_current_document()._segment_pipe
        self._seed_prop.setText(1,str(segment.Seed))
        self._seedX_prop.setText(1,str(segment.Seed[0]))
        self._seedY_prop.setText(1,str(segment.Seed[1]))
        self._seedZ_prop.setText(1,str(segment.Seed[2]))
        self._min_threshold_prop.setText(1,str(segment.LowerThreshold))
        self._max_threshold_prop.setText(1,str(segment.UpperThreshold))
        self._replace_value_prop.setText(1,str(segment.ReplaceValue))
        state = Qt.Unchecked
        if Application.get_current_document().usingSegmentor():
            state = Qt.Checked
        self._segment_prop.setCheckState(0,state)


        confidence = Application.get_current_document()._confidence_connected_pipe
        self._conf_seed_prop.setText(1,str(confidence.Seed))
        self._conf_seedX_prop.setText(1,str(confidence.Seed[0]))
        self._conf_seedY_prop.setText(1,str(confidence.Seed[1]))
        self._conf_seedZ_prop.setText(1,str(confidence.Seed[2]))
        self._conf_radius_prop.setText(1,str(confidence.InitialRadius))
        self._conf_mult_value_prop.setText(1,str(confidence.Multiplier))
        self._conf_repl_value_prop.setText(1,str(confidence.ReplaceValue))
        self._conf_iter_prop.setText(1,str(confidence.NumberOfIterations))
        state = Qt.Unchecked
        if Application.get_current_document().usingConfidenceConnected():
            state = Qt.Checked
        self._confidence_prop.setCheckState(0,state)

        voting = Application.get_current_document()._voting_pipe
        self._radius_prop.setText(1,str(voting.Radius))
        self._radiusX_prop.setText(1,str(voting.Radius[0]))
        self._radiusY_prop.setText(1,str(voting.Radius[1]))
        self._radiusZ_prop.setText(1,str(voting.Radius[2]))
        self._foreground_prop.setText(1,str(voting.Foreground))
        self._background_prop.setText(1,str(voting.Background))
        self._survival_prop.setText(1,str(voting.SurvivalValue))
        self._birth_prop.setText(1,str(voting.BirthValue))
        state = Qt.Unchecked
        if Application.get_current_document().usingVoter():
            state = Qt.Checked
        self._voting_prop.setCheckState(0,state)

        self._properties_tree.blockSignals(False)
Пример #3
0
    def load_configuration(self):
        res = self._file_load_dialog.exec_(
        )  #ejecutar el diálogo para obtener el nombre del fichero
        if res == QFileDialog.Rejected:  #se canceló la salva
            return
        file_name = unicode(self._file_load_dialog.selectedFiles()
                            [0])  #obtener el nombre del fichero
        doc = Application.get_current_document(
        )  #referencia al docmento actual de la aplicación
        f = open(file_name, "rt")
        try:
            smoother = doc._smooth_pipe
            doc.useSmoother(self._read_bool(f))
            smoother.NumberOfIterations = self._read_int(f)
            smoother.TimeStep = self._read_float(f)
            smoother.Conductance = self._read_float(f)

            segmentor = doc._segment_pipe
            doc.useSegmentor(self._read_bool(f))
            segmentor.Seed = self._read_int_list(f)
            segmentor.LowerThreshold = self._read_float(f)
            segmentor.UpperThreshold = self._read_float(f)
            segmentor.ReplaceValue = self._read_float(f)

            conf_conn = doc._confidence_connected_pipe
            doc.useConfidenceConnected(self._read_bool(f))
            conf_conn.Seed = self._read_int_list(f)
            conf_conn.InitialRadius = self._read_int(f)
            conf_conn.Multiplier = self._read_float(f)
            conf_conn.ReplaceValue = self._read_float(f)
            conf_conn.NumberOfIterations = self._read_int(f)

            voter = doc._voting_pipe
            doc.useVoter(self._read_bool(f))
            voter.Radius = self._read_int_list(f)
            voter.Background = self._read_float(f)
            voter.Foreground = self._read_float(f)
            voter.SurvivalValue = self._read_int(f)
            voter.BirthValue = self._read_int(f)
        finally:
            f.close()
Пример #4
0
    def save_configuration(self):
        res = self._file_save_dialog.exec_(
        )  #ejecutar el diálogo para obtener el nombre del fichero
        if res == QFileDialog.Rejected:  #se canceló la salva
            return
        file_name = unicode(self._file_save_dialog.selectedFiles()
                            [0])  #obtener el nombre del fichero
        doc = Application.get_current_document(
        )  #referencia al docmento actual de la aplicación
        f = open(file_name, "wt")
        try:
            smoother = doc._smooth_pipe
            f.write(str(doc.usingSmoother()) + "\n")
            f.write(str(smoother.NumberOfIterations) + "\n")
            f.write(str(smoother.TimeStep) + "\n")
            f.write(str(smoother.Conductance) + "\n")

            segmentor = doc._segment_pipe
            f.write(str(doc.usingSegmentor()) + "\n")
            f.write(str(segmentor.Seed) + "\n")
            f.write(str(segmentor.LowerThreshold) + "\n")
            f.write(str(segmentor.UpperThreshold) + "\n")
            f.write(str(segmentor.ReplaceValue) + "\n")

            conf_conn = doc._confidence_connected_pipe
            f.write(str(doc.usingConfidenceConnected()) + "\n")
            f.write(str(conf_conn.Seed) + "\n")
            f.write(str(conf_conn.InitialRadius) + "\n")
            f.write(str(conf_conn.Multiplier) + "\n")
            f.write(str(conf_conn.ReplaceValue) + "\n")
            f.write(str(conf_conn.NumberOfIterations) + "\n")

            voter = doc._voting_pipe
            f.write(str(doc.usingVoter()) + "\n")
            f.write(str(voter.Radius) + "\n")
            f.write(str(voter.Background) + "\n")
            f.write(str(voter.Foreground) + "\n")
            f.write(str(voter.SurvivalValue) + "\n")
            f.write(str(voter.BirthValue) + "\n")
        finally:
            f.close()
Пример #5
0
    def _update_filters(self,item,col):
        """
        Actualiza las propiedades de los filtros luego de editarlas
        @param item: item que se editó
        @param col: columna del item que se editó
        @return: None
        """
        #cambiaron la etiqueta de la propiedad no el valor
        if col == 0:
            self._update_editable_labels()
            if item.text(0) == "Suavizador":
                Application.get_current_document().useSmoother(item.checkState(0) == Qt.Checked)
            elif item.text(0) == "Segmentador":
                Application.get_current_document().useSegmentor(item.checkState(0) == Qt.Checked)
            elif item.text(0) == "Segmentador estadístico":
                Application.get_current_document().useConfidenceConnected(item.checkState(0) == Qt.Checked)
            elif item.text(0) == "Votación":
                Application.get_current_document().useVoter(item.checkState(0) == Qt.Checked)
            return
        if item.text(0) == "Iteraciones" and item.parent().text(0) == "Suavizador":
            try:
                num = int(item.text(1))
                if num<0 or num>20:
                    raise ValueError()
                Application.get_current_document()._smooth_pipe.NumberOfIterations = num
            except ValueError:
                pass
        elif item.text(0) == "Iteraciones" and item.parent().text(0) == "Segmentador estadístico":
            try:
                num = int(item.text(1))
                if num<0 or num>50:
                    raise ValueError()
                Application.get_current_document()._confidence_connected_pipe.NumberOfIterations = num
            except ValueError:
                pass
        elif item.text(0) == "Paso de tiempo":
            try:
                num = float(item.text(1))
                if num<0.0 or num>1.0: #límites del paso de tiempo
                    raise ValueError()
                Application.get_current_document()._smooth_pipe.TimeStep = num
            except ValueError:
                pass
        elif item.text(0) == "Conductancia":
            try:
                num = float(item.text(1))
                if num<0.0 or num>100.0: #límites rasonables de conductancia
                    raise ValueError()
                Application.get_current_document()._smooth_pipe.Conductance = num
            except ValueError:
                pass
        elif item.parent().text(0) == "Semilla" and item.parent().parent().text(0) == "Segmentador":
            #los hijos de 'Semilla' son las coordenadas
            seed = [ self._seedX_prop.text(1),
                     self._seedY_prop.text(1),
                     self._seedZ_prop.text(1) ]
            try:
                seed = map(int,seed)
                #verificar que no se incluya como semilla un valor mayor que el tamaño de la imagen o
                #menor que cero
                if any(map(lambda x: x<0,seed)) or\
                   any(imap(lambda x,y: x>=y,seed,Application.get_current_image().Size)):
                    raise ValueError()
                Application.get_current_document()._segment_pipe.Seed = seed
            except ValueError:
                pass
        elif item.parent().text(0) == "Semilla" and item.parent().parent().text(0) == "Segmentador estadístico":
            #los hijos de 'Semilla' son las coordenadas
            seed = [ self._conf_seedX_prop.text(1),
                     self._conf_seedY_prop.text(1),
                     self._conf_seedZ_prop.text(1) ]
            try:
                seed = map(int,seed)
                #verificar que no se incluya como semilla un valor mayor que el tamaño de la imagen o
                #menor que cero
                if any(map(lambda x: x<0,seed)) or\
                   any(imap(lambda x,y: x>=y,seed,Application.get_current_image().Size)):
                    raise ValueError()
                Application.get_current_document()._confidence_connected_pipe.Seed = seed
            except ValueError:
                pass
        elif item.text(0) == "Mínimo":
            try:
                min = float(self._min_threshold_prop.text(1))
                Application.get_current_document()._segment_pipe.LowerThreshold = min
            except ValueError:
                pass
        elif item.text(0) == "Máximo":
            try:
                max = float(self._max_threshold_prop.text(1))
                Application.get_current_document()._segment_pipe.UpperThreshold = max
            except ValueError:
                pass
        elif item.text(0) == "Relleno" and item.parent().parent().text(0) == "Segmentador":
            try:
                val = float(self._replace_value_prop.text(1))
                Application.get_current_document()._segment_pipe.ReplaceValue = val
            except ValueError:
                pass
        elif item.text(0) == "Relleno" and item.parent().parent().text(0) == "Segmentador estadístico":
            try:
                val = float(self._conf_repl_value_prop.text(1))
                Application.get_current_document()._confidence_connected_pipe.ReplaceValue = val
            except ValueError:
                pass
        elif item.parent().text(0) == "Radio":
            radius = [  self._radiusX_prop.text(1),
                        self._radiusY_prop.text(1),
                        self._radiusZ_prop.text(1) ]
            try:
                radius = map(str,radius)
                radius = map(int,radius)
                #verificar que no se incluya como radio un valor sensato (por ahora entre 0 y 20)
                if any(map(lambda x: x<0 or x>20,radius)):
                    raise ValueError()
                Application.get_current_document()._voting_pipe.Radius = radius
            except ValueError:
                pass
        elif item.text(0) == "Radio inicial":
            try:
                val = int(self._conf_radius_prop.text(1))
                if val<0 or val>20:
                    raise ValueError()
                Application.get_current_document()._confidence_connected_pipe.InitialRadius = val
            except ValueError:
                pass
        elif item.text(0) == "Multiplicador":
            try:
                val = float(self._conf_mult_value_prop.text(1))
                if val<0:
                    raise ValueError()
                Application.get_current_document()._confidence_connected_pipe.Multiplier = val
            except ValueError:
                pass
        elif item.text(0) == "Fondo":
            try:
                val = int(self._background_prop.text(1))
                if val<0 or val>255:
                    raise ValueError()
                Application.get_current_document()._voting_pipe.Background = val
            except ValueError:
                pass
        elif item.text(0) == "Máscara":
            try:
                val = int(self._foreground_prop.text(1))
                if val<0:
                    raise ValueError()
                Application.get_current_document()._voting_pipe.Foreground = val
            except ValueError:
                pass
        elif item.text(0) == "Supervivencia":
            try:
                val = int(self._survival_prop.text(1))
                if val<0:
                    raise ValueError()
                Application.get_current_document()._voting_pipe.SurvivalValue = val
            except ValueError:
                pass
        elif item.text(0) == "Nacimiento":
            try:
                val = int(self._birth_prop.text(1))
                if val<0:
                    raise ValueError()
                Application.get_current_document()._voting_pipe.BirthValue = val
            except ValueError:
                pass

        self._update_filters_properties()