Exemplo n.º 1
0
    def __init__(self, nifti_path, parent):

        self._nifti_path = nifti_path
        self._workspace_parent = parent
        try:
            self._nifti = nib.load(self._nifti_path)
        except FileNotFoundError:
            print('Error in path %s' % nifti_path)
            return
        self._array_data = self._nifti.get_data()

        # Nifti file does not show stable shape, sometimes as (num,x,y) and at times as (x,y,num) or (x,num,y)
        self._array_data = utils.shape_nifti_2_segtool(self._array_data)

        # normalize images
        self.frames = (self._array_data.astype(np.float64) / np.max(self._array_data)) * 255

        # TODO: perform in separate thread
        self._contrasted_frames = np.zeros((10, self.frames.shape[0], self.frames.shape[1], self.frames.shape[2]))
        for i in range(1, 11):
            self._contrasted_frames[i-1] = contrast_change(i, self.frames)

        # index of current frame displayed
        self.frame_displayed_index = 0

        # numpy array of frames with segmentation as binary images
        self._segmentation_array = None

        # perform segmentation algorithm in separate thread so that gui is not frozen
        self._segmentation_thread = Thread(target=self._workspace_parent.perform_segmentation)
        self._segmentation_thread.setDaemon(True)

        self.image_label = ImageLabel(self.frames, self._contrasted_frames, self._workspace_parent)

        # text representing scan's status: in Queue \ Processing \ Ready \ etc.
        self.status = ''

        # class which performs the segmentation process
        self._segment_worker = BrainSegment(self.frames)

        # what is currently displayed: USER MARKS / SEGMENTATION / CONVEX / BRAIN HALVES / CSF
        self.display_state = ''

        # volume calculated of different parts of the scan
        self._full_brain_volume = 0
        self._brain_halves_volume = [0, 0]
        self._csf_volume = 0
Exemplo n.º 2
0
 def init_label_frame(self):
     self.label_frame = ImageLabel('video')
     self.label_frame.setAlignment(Qt.AlignCenter)
     self.label_frame.setStyleSheet('border: 1px solid black')
     self.vbox_layout.addWidget(self.label_frame, 10)
Exemplo n.º 3
0
    def __init__(self, args):
        super().__init__()
        self.annotation_path = args.label_file
        self.scale_factor = args.scale
        self.annotaion_dict = dict()
        self.img_list = list()
        self.img_name = list()
        img_list = os.listdir(args.img_dir)
        for i in range(len(img_list)):
            if img_list[i].endswith('jpg') or img_list[i].endswith('png'):
                img_path = os.path.join(args.img_dir, img_list[i])
                self.img_list.append(img_path)
                self.img_name.append(img_list[i])
        self.img_num = len(self.img_list)
        self.img_id = 0
        self.class_id = 1
        if self.img_num == 0:
            return
        self._read_img()
        self.region_img_view = ImageLabel(self)
        self.region_img_view.setPixmap(
            QPixmap(cvimg_to_qtimg(self.current_img_resize)))
        self.region_img_view.setMouseTracking(True)
        self.region_img_view.update_img(self.current_img_resize,
                                        self.img_name[self.img_id])

        self.button_width = 400 * self.scale_factor
        self.button_height = 60 * self.scale_factor
        self.pushButton1 = QPushButton(self)
        self.pushButton1.setText("Next Img")
        self.pushButton1.clicked.connect(self._down_func)
        self.pushButton2 = QPushButton(self)
        self.pushButton2.setText("Last Img")
        self.pushButton2.clicked.connect(self._up_func)
        self.pushButton3 = QPushButton(self)
        self.pushButton3.setText("Apply")
        self.pushButton3.clicked.connect(self._apply_func)
        self.pushButton4 = QPushButton(self)
        self.pushButton4.setText("Clean")
        self.pushButton4.clicked.connect(self._clean_func)
        self.pushButton5 = QPushButton(self)
        self.pushButton5.setText("Output")
        self.pushButton5.clicked.connect(self._output_func)

        if args.mode == "multi":
            self.class_text_height = 30 * self.scale_factor
            self.class_text_width = 100 * self.scale_factor
            self.class_text_label = QLabel(self)
            self.class_text_label.setAlignment(Qt.AlignCenter)
            self.class_text_label.setText('Class ID:')
            self.setup_class_id = QLineEdit(self)
            self.setup_class_id.setFocus()
            self.setup_class_id.setFocusPolicy(Qt.ClickFocus)
            self.setup_class_id.installEventFilter(self)
            self.setup_class_id.editingFinished.connect(
                self._setup_class_id_func)
        else:
            self.setup_class_id = QLabel(self)
            self.setup_class_id.setFocus()
            self.setup_class_id.setFocusPolicy(Qt.ClickFocus)
            self.setup_class_id.installEventFilter(self)
        self.setWindowTitle('Simple 2D Object Annotator')
        self._init_window()