예제 #1
0
    def test_roi_changed_callback(self):
        self.roi_callback_was_called = False
        self.view.roi_updated.connect(self._roi_updated_callback)

        self.view.roi_changed_callback(SensibleROI(1, 2, 3, 4))

        self.assertTrue(self.roi_callback_was_called)
예제 #2
0
 def _update_roi_region_avg(self) -> Optional[SensibleROI]:
     if self.image.ndim != 3:
         return None
     roi_pos, roi_size = self.get_roi()
     # image indices are in order [Z, X, Y]
     left, right = roi_pos.x, roi_pos.x + roi_size.x
     top, bottom = roi_pos.y, roi_pos.y + roi_size.y
     data = self.image[:, top:bottom, left:right]
     if data is not None:
         while data.ndim > 1:
             data = data.mean(axis=1)
         if len(self.roiCurves) == 0:
             self.roiCurves.append(self.ui.roiPlot.plot())
         self.roiCurves[0].setData(y=data, x=self.tVals)
     self.roiString = f"({left}, {top}, {right}, {bottom}) | " \
                      f"region avg={data[int(self.timeLine.value())].mean():.6f}"
     return SensibleROI(left, top, right, bottom)
    def test_copy_roi(self):
        images = generate_images()
        images.record_operation("Test", "Display", 123)
        self.assertFalse(images.is_sinograms)
        cropped_copy = images.copy_roi(SensibleROI(0, 0, 5, 5))

        self.assertEqual(cropped_copy, images.data[:, 0:5, 0:5])

        self.assertEqual(len(cropped_copy.metadata[const.OPERATION_HISTORY]), 2)
        self.assertEqual(cropped_copy.metadata[const.OPERATION_HISTORY][-1][const.OPERATION_DISPLAY_NAME],
                         CropCoordinatesFilter.filter_name)

        # remove the extra crop operation
        cropped_copy.metadata[const.OPERATION_HISTORY].pop(-1)
        # the two metadatas show now be equal again
        self.assertEqual(images.metadata, cropped_copy.metadata)
        self.assertNotEqual(images, cropped_copy)