Beispiel #1
0
    def get_roi(
            self,
            ensure_in_image=True) -> Tuple[CloseEnoughPoint, CloseEnoughPoint]:
        roi_pos, roi_size = CloseEnoughPoint(self.roi.pos()), CloseEnoughPoint(
            self.roi.size())

        if ensure_in_image:
            # Don't allow negative point coordinates
            if roi_pos.x < 0 or roi_pos.y < 0:
                getLogger(__name__).info(
                    "Region of Interest starts outside the picture! Clipping to image bounds"
                )
                roi_pos.x = max(roi_pos.x, 0)
                roi_pos.y = max(roi_pos.y, 0)

            if self.image.ndim == 2:
                image_height = self.image.shape[0]
                image_width = self.image.shape[1]
            else:
                image_height = self.image.shape[1]
                image_width = self.image.shape[2]

            roi_right = roi_pos.x + roi_size.x
            roi_bottom = roi_pos.y + roi_size.y

            if roi_right > image_width:
                roi_size.x -= roi_right - image_width
            if roi_bottom > image_height:
                roi_size.y -= roi_bottom - image_height
        return roi_pos, roi_size
def test_get_roi(init_pos: List[int], init_size: List[int], exp_pos: List[int], exp_size: List[int]):
    image = np.zeros((100, 100))
    pres = MIImagePresenter()
    roi_pos = CloseEnoughPoint(init_pos)
    roi_size = CloseEnoughPoint(init_size)

    res_pos, res_size = pres.get_roi(image, roi_pos, roi_size)
    assert res_pos.x == exp_pos[0]
    assert res_pos.y == exp_pos[1]
    assert res_size.x == exp_size[0]
    assert res_size.y == exp_size[1]
Beispiel #3
0
    def __init__(self,
                 parent=None,
                 name="ImageView",
                 view=None,
                 imageItem=None,
                 levelMode='mono',
                 *args):
        super().__init__(parent, name, view, imageItem, levelMode, *args)
        self.details = QLabel("", self.ui.layoutWidget)
        self.details.setStyleSheet(
            "QLabel { color : white; background-color: black}")
        self.ui.gridLayout.addWidget(self.details, 1, 0, 1, 1)

        self.imageItem.hoverEvent = self.image_hover_event
        # disconnect the ROI recalculation on every move
        self.roi.sigRegionChanged.disconnect(self.roiChanged)
        self.view.removeItem(self.roi)

        self.roi = UnrotateablePlotROI(300)
        self.roi.setZValue(30)
        # make ROI red
        self.roi.setPen((255, 0, 0))
        self.view.addItem(self.roi)
        self.roi.hide()
        self.roi.sigRegionChangeFinished.connect(self.roiChanged)
        self.extend_roi_plot_mouse_press_handler()
        self.imageItem.setAutoDownsample(False)

        self._last_mouse_hover_location = CloseEnoughPoint([0, 0])

        self.imageItem.sigImageChanged.connect(self._refresh_message)
Beispiel #4
0
 def mouse_click(self, ev, line: InfiniteLine):
     line.setPos(ev.pos())
     # don't refresh the histogram on click to stop the contrast for re-adjusting for each slice
     # it's much easier to see what's happening to the reconstruction if the slice doesn't
     # reset after every click
     self.parent.presenter.do_reconstruct_slice(slice_idx=CloseEnoughPoint(ev.pos()).y,
                                                refresh_recon_slice_histogram=False)
Beispiel #5
0
 def mouse_over(self, ev, img):
     # Ignore events triggered by leaving window or right clicking
     if ev.exit:
         return
     pos = CloseEnoughPoint(ev.pos())
     if img.image is not None and pos.x < img.image.shape[0] and pos.y < img.image.shape[1]:
         pixel_value = img.image[pos.y, pos.x]
         self.display_formatted_detail[img](pixel_value)
Beispiel #6
0
 def _refresh_message(self):
     # updates the ROI average value
     self._update_roi_region_avg()
     try:
         self._update_message(self._last_mouse_hover_location)
     except IndexError:
         # this happens after the image is cropped, and the last location
         # is outside of the new bounds. To prevent this happening again just reset back to 0, 0
         self._last_mouse_hover_location = CloseEnoughPoint([0, 0])
Beispiel #7
0
    def mouse_over(self, ev):
        # Ignore events triggered by leaving window or right clicking
        if ev.exit:
            return
        pos = CloseEnoughPoint(ev.pos())

        self.show_value(pos)
        for img_view in self.axis_siblings:
            img_view.show_value(pos)
    def set_image(self, image_type: ImageType, recon_data: np.ndarray,
                  title: str):
        if image_type == ImageType.LESS:
            self.less_img.clear()
            self.less_img.setImage(recon_data)
            self.less_label.setText(title)
        elif image_type == ImageType.CURRENT:
            self.current_img.clear()
            self.current_img.setImage(recon_data, autoLevels=False)
            self.current_label.setText(title)
        elif image_type == ImageType.MORE:
            self.more_img.clear()
            self.more_img.setImage(recon_data)
            self.more_label.setText(title)

        self.less_hist.imageChanged(True, True)
        self.more_hist.imageChanged(True, True)
        self.current_hist.sigLevelsChanged.emit(self.current_hist)
        diffs = self._refresh_value_labels(CloseEnoughPoint([0, 0]))
        self.parent.mark_best_recon(diffs)
Beispiel #9
0
    def __init__(self,
                 parent=None,
                 name="ImageView",
                 view=None,
                 imageItem=None,
                 levelMode='mono',
                 detailsSpanAllCols=False,
                 *args):
        super().__init__(parent, name, view, imageItem, levelMode, *args)
        graveyard.append(self)
        self.presenter = MIImagePresenter()
        self.details = QLabel("", self.ui.layoutWidget)
        self.details.setStyleSheet(
            "QLabel { color : white; background-color: black}")
        if detailsSpanAllCols:
            self.ui.gridLayout.addWidget(self.details, 1, 0, 1, 3)
            self.ui.gridLayout.setColumnStretch(0, 8)
            self.ui.gridLayout.setColumnStretch(1, 1)
            self.ui.gridLayout.setColumnStretch(2, 1)
        else:
            self.ui.gridLayout.addWidget(self.details, 1, 0, 1, 1)

        # Hide the norm button as it allows for manual data changes and we don't want users to do that unrecorded.
        self.ui.menuBtn.hide()

        # Construct and add the left and right buttons for the stack
        self.shifting_through_images = False

        self.button_stack_left = QPushButton()
        self.button_stack_left.setText("<")
        self.button_stack_left.setSizePolicy(QSizePolicy.Minimum,
                                             QSizePolicy.Minimum)
        self.button_stack_left.setMaximumSize(40, 40)
        self.button_stack_left.pressed.connect(
            lambda: self.toggle_jumping_frame(-1))
        self.button_stack_left.released.connect(
            lambda: self.toggle_jumping_frame())

        self.button_stack_right = QPushButton()
        self.button_stack_right.setText(">")
        self.button_stack_right.setSizePolicy(QSizePolicy.Minimum,
                                              QSizePolicy.Minimum)
        self.button_stack_right.setMaximumSize(40, 40)
        self.button_stack_right.pressed.connect(
            lambda: self.toggle_jumping_frame(1))
        self.button_stack_right.released.connect(
            lambda: self.toggle_jumping_frame())

        self.vertical_layout = QHBoxLayout()
        self.vertical_layout.addWidget(self.button_stack_left)
        self.vertical_layout.addWidget(self.button_stack_right)
        self.ui.gridLayout.addLayout(self.vertical_layout, 1, 2, 1, 1)

        self.imageItem.hoverEvent = self.image_hover_event
        # disconnect the ROI recalculation on every move
        self.roi.sigRegionChanged.disconnect(self.roiChanged)
        self.view.removeItem(self.roi)

        self.roi = UnrotateablePlotROI(300)
        self.roi.setZValue(30)
        # make ROI red
        self.roi.setPen((255, 0, 0))
        self.view.addItem(self.roi)
        self.roi.hide()
        self.roi.sigRegionChangeFinished.connect(self.roiChanged)
        self.extend_roi_plot_mouse_press_handler()
        self.imageItem.setAutoDownsample(False)

        self._last_mouse_hover_location = CloseEnoughPoint([0, 0])

        self.imageItem.sigImageChanged.connect(self._refresh_message)
        self.imageItem.sigImageChanged.connect(self.set_log_scale)

        self.auto_colour_action = QAction("Auto")
        self.auto_colour_action.triggered.connect(
            self.on_colour_change_palette)

        action = self.ui.histogram.item.gradient.menu.actions()[12]
        self.ui.histogram.item.gradient.menu.insertAction(
            action, self.auto_colour_action)
        self.ui.histogram.item.gradient.menu.insertSeparator(
            self.auto_colour_action)

        # Work around for https://github.com/mantidproject/mantidimaging/issues/565
        self.scene.contextMenu = [
            item for item in self.scene.contextMenu
            if "export" not in item.text().lower()
        ]
Beispiel #10
0
 def image_hover_event(self, event: HoverEvent):
     if event.exit:
         return
     pt = CloseEnoughPoint(event.pos())
     self._last_mouse_hover_location = pt
     self._update_message(pt)
Beispiel #11
0
 def get_roi(self) -> Tuple[CloseEnoughPoint, CloseEnoughPoint]:
     return self.presenter.get_roi(self.image,
                                   roi_pos=CloseEnoughPoint(self.roi.pos()),
                                   roi_size=CloseEnoughPoint(
                                       self.roi.size()))
 def mouse_over(self, ev):
     # Ignore events triggered by leaving window or right clicking
     if ev.exit:
         return
     pos = CloseEnoughPoint(ev.pos())
     self._refresh_value_labels(pos)
Beispiel #13
0
 def mouse_click(self, ev, line: InfiniteLine):
     line.setPos(ev.pos())
     self.slice_changed(CloseEnoughPoint(ev.pos()).y)