def test_image_view_integration_filter(self, qtbot, tmp_path,
                                           filter_value):
        settings = BaseSettings(tmp_path)
        ch_property = ChannelProperty(settings, "test")
        image_view = ImageView(settings, ch_property, "test")
        # image_view.show()
        qtbot.addWidget(image_view)
        qtbot.addWidget(ch_property)
        image = TiffImageReader.read_image(
            PartSegData.segmentation_analysis_default_image)
        with qtbot.waitSignal(image_view.image_added, timeout=10**6):
            settings.image = image

        image_view.channel_control.set_active(1)

        def check_parameters(name, index):
            return name == "test" and index == 1

        if filter_value is NoiseFilterType.No:
            with qtbot.waitSignal(
                    image_view.channel_control.coloring_update
            ), qtbot.waitSignal(image_view.channel_control.change_channel,
                                check_params_cb=check_parameters):
                ch_property.use_filter.setCurrentEnum(NoiseFilterType.Gauss)
        with qtbot.waitSignal(
                image_view.channel_control.coloring_update), qtbot.waitSignal(
                    image_view.channel_control.change_channel,
                    check_params_cb=check_parameters):
            ch_property.use_filter.setCurrentEnum(filter_value)
        image4 = image_view.viewer_widget.screenshot()
        assert (filter_value != NoiseFilterType.No and
                np.any(image4 != 255)) or (filter_value == NoiseFilterType.No
                                           and np.any(image4 == 255))
Exemple #2
0
    def __init__(self, settings: BaseSettings, parent=None):
        super().__init__(parent)
        self.settings = settings
        self.file_list = QListWidget()
        self.file_list.setSelectionMode(QAbstractItemView.ExtendedSelection)
        self.cancel_btn = QPushButton("Cancel", clicked=self.reject)
        self.load_btn = QPushButton("Load", clicked=self.accept)

        for name_list, method in settings.get_last_files_multiple():
            entry = f"{name_list[0]} {method}"
            item = QListWidgetItem(entry, self.file_list)
            item.setData(Qt.UserRole, (name_list, method))

        last_set = {(tuple(x), y)
                    for x, y in settings.get_last_files_multiple()}
        for name_list, method in settings.get_last_files():
            if (tuple(name_list), method) in last_set:
                continue
            entry = f"{name_list[0]} {method}"
            item = QListWidgetItem(entry, self.file_list)
            item.setData(Qt.UserRole, (name_list, method))

        layout = QGridLayout()
        layout.addWidget(QLabel("Select files"))
        layout.addWidget(self.file_list, 1, 0, 1, 2)
        layout.addWidget(self.cancel_btn, 2, 0)
        layout.addWidget(self.load_btn, 2, 1)

        self.setLayout(layout)
        self.resize(
            *self.settings.get_from_profile("multiple_files_dialog_size", (
                self.size().width(), self.size().height())))
Exemple #3
0
 def test_channels(self, tmp_path, qtbot):
     settings = BaseSettings(tmp_path)
     assert not settings.has_channels
     assert settings.channels == 0
     settings.image = Image(np.zeros((10, 10, 2), dtype=np.uint8), (1, 1), axes_order="XYC")
     assert settings.has_channels
     assert settings.channels == 2
     settings.image = Image(np.zeros((10, 10, 1), dtype=np.uint8), (1, 1), axes_order="XYC")
     assert not settings.has_channels
     assert settings.channels == 1
Exemple #4
0
    def test_empty_history(self, tmp_path):
        settings = BaseSettings(tmp_path)
        assert settings.history_size() == 0
        assert settings.history_redo_size() == 0

        with pytest.raises(IndexError):
            settings.history_current_element()

        with pytest.raises(IndexError):
            settings.history_next_element()

        settings.history_pop()
        assert settings.history_index == -1
Exemple #5
0
 def test_image_view_integration(self, qtbot, tmp_path):
     settings = BaseSettings(tmp_path)
     channel_property = ChannelProperty(settings, "test")
     image_view = ImageView(settings, channel_property, "test")
     qtbot.addWidget(channel_property)
     qtbot.addWidget(image_view)
     color_list = PColormapList(settings, ["test"])
     qtbot.addWidget(color_list)
     image = TiffImageReader.read_image(
         PartSegData.segmentation_analysis_default_image)
     with qtbot.wait_signal(image_view.image_added, timeout=10**6):
         settings.image = image
     color_list.refresh()
     assert image_view.channel_control.channels_count == image.channels
     assert len(color_list.blocked()) == image.channels
     block_count = 0
     for el in settings.colormap_dict.keys():
         widget = color_list.get_colormap_widget(el)
         assert widget.is_checked or el not in starting_colors
         if not widget.checked.isEnabled():
             block_count += 1
     assert block_count == image.channels
     image_view.channel_control.change_selected_color(0, "Grayscale")
     assert len(color_list.blocked()) == image.channels
     assert "Grayscale" in color_list.blocked()
     color_list.refresh()
     assert color_list.get_colormap_widget(
         "Grayscale").checked.isEnabled() is False
     # this lines test if after refresh of widget checkbox stays checkable
     block_count = 0
     for el in settings.colormap_dict.keys():
         widget = color_list.get_colormap_widget(el)
         assert widget.is_checked or el not in starting_colors
         if not widget.checked.isEnabled():
             block_count += 1
     assert block_count == image.channels
Exemple #6
0
 def test_verify_image(self):
     assert BaseSettings.verify_image(Image(np.zeros((10, 10, 2), dtype=np.uint8), (1, 1), axes_order="XYC"))
     with pytest.raises(SwapTimeStackException):
         BaseSettings.verify_image(
             Image(np.zeros((2, 10, 10), dtype=np.uint8), (1, 1, 1), axes_order="TXY"), silent=False
         )
     im = BaseSettings.verify_image(Image(np.zeros((2, 10, 10), dtype=np.uint8), (1, 1, 1), axes_order="TXY"))
     assert not im.is_time
     assert im.times == 1
     assert im.is_stack
     assert im.layers == 2
     with pytest.raises(TimeAndStackException):
         BaseSettings.verify_image(Image(np.zeros((2, 2, 10, 10), dtype=np.uint8), (1, 1, 1), axes_order="TZXY"))
Exemple #7
0
    def test_set_roi(self, tmp_path, qtbot):
        settings = BaseSettings(tmp_path)
        roi = np.zeros((10, 10), dtype=np.uint8)
        settings.image = Image(roi, (1, 1), axes_order="XY")
        roi[1:5, 1:5] = 1
        roi[5:-1, 5:-1] = 3
        with qtbot.waitSignal(settings.roi_changed):
            settings.roi = roi
        assert len(settings.roi_info.bound_info) == 2
        assert set(settings.roi_info.bound_info) == {1, 3}
        assert settings.roi_info.alternative == {}
        assert settings.roi_info.annotations == {}

        with qtbot.waitSignal(settings.roi_clean):
            settings.roi = None
        assert settings.roi is None

        settings.image = None
        assert settings.image is not None
Exemple #8
0
 def test_clean_redo(self, tmp_path):
     settings = BaseSettings(tmp_path)
     for i in range(10):
         settings.add_history_element(i)
     for _ in range(5):
         settings.history_pop()
     settings.history_current_element()
     settings.history_redo_clean()
     settings.history_current_element()
Exemple #9
0
    def test_modifying_history(self, tmp_path):
        settings = BaseSettings(tmp_path)
        for i in range(10):
            settings.add_history_element(i)

        assert settings.history_size() == 10
        assert settings.history_redo_size() == 0

        with pytest.raises(IndexError):
            settings.history_next_element()

        for i in range(9, 5, -1):
            assert settings.history_current_element() == i
            assert settings.history_pop() == i

        assert settings.history_current_element() == 5
        assert settings.history_size() == 6
        assert settings.history_redo_size() == 4
        settings.add_history_element(7)
        assert settings.history_size() == 7
        assert settings.history_redo_size() == 0
Exemple #10
0
def base_settings(image, tmp_path, measurement_profiles):
    settings = BaseSettings(tmp_path)
    settings.image = image
    return settings
Exemple #11
0
 def test_shape(self, tmp_path):
     settings = BaseSettings(tmp_path)
     assert settings.image_shape == ()
     settings.image = Image(np.zeros((10, 10, 2), dtype=np.uint8), (1, 1), axes_order="XYC")
     assert settings.image_shape == (1, 1, 10, 10, 2)
Exemple #12
0
 def test_add_point(self, tmp_path, qtbot):
     settings = BaseSettings(tmp_path)
     with qtbot.waitSignal(settings.points_changed):
         settings.points = [1, 2, 3]
Exemple #13
0
    def test_image_view_integration(self, qtbot, tmp_path):
        settings = BaseSettings(tmp_path)
        ch_property = ChannelProperty(settings, "test")
        image_view = ImageView(settings, ch_property, "test")
        # image_view.show()
        qtbot.addWidget(image_view)
        qtbot.addWidget(ch_property)
        image = TiffImageReader.read_image(
            PartSegData.segmentation_analysis_default_image)
        with qtbot.waitSignals(
            [settings.image_changed, image_view.image_added], timeout=10**6):
            settings.image = image
        channels_num = image.channels
        assert image_view.channel_control.channels_count == channels_num

        image_view.viewer_widget.screenshot()
        image1 = image_view.viewer_widget.canvas.render()
        assert np.any(image1 != 255)
        image_view.channel_control.set_active(1)
        ch_property.minimum_value.setValue(100)
        ch_property.maximum_value.setValue(10000)
        ch_property.filter_radius.setValue(0.5)
        image2 = image_view.viewer_widget.canvas.render()
        assert np.any(image2 != 255)

        assert np.all(image1 == image2)

        def check_parameters(name, index):
            return name == "test" and index == 1

        # Test fixed range
        with qtbot.waitSignal(
                image_view.channel_control.coloring_update), qtbot.waitSignal(
                    image_view.channel_control.change_channel,
                    check_params_cb=check_parameters):
            ch_property.fixed.setChecked(True)

        image1 = image_view.viewer_widget.canvas.render()
        assert np.any(image1 != 255)
        with qtbot.waitSignal(
                image_view.channel_control.coloring_update), qtbot.waitSignal(
                    image_view.channel_control.change_channel,
                    check_params_cb=check_parameters):
            ch_property.minimum_value.setValue(20)
        image2 = image_view.viewer_widget.canvas.render()
        assert np.any(image2 != 255)
        assert np.any(image1 != image2)

        with qtbot.waitSignal(
                image_view.channel_control.coloring_update), qtbot.waitSignal(
                    image_view.channel_control.change_channel,
                    check_params_cb=check_parameters):
            ch_property.maximum_value.setValue(11000)
        image3 = image_view.viewer_widget.screenshot()
        assert np.any(image3 != 255)
        assert np.any(image2 != image3)
        assert np.any(image1 != image3)

        with qtbot.waitSignal(
                image_view.channel_control.coloring_update), qtbot.waitSignal(
                    image_view.channel_control.change_channel,
                    check_params_cb=check_parameters):
            ch_property.fixed.setChecked(False)

        image1 = image_view.viewer_widget.screenshot()
        assert np.any(image1 != 255)
        assert np.any(image1 != image2)
        assert np.any(image1 != image3)
        # Test gauss
        with qtbot.waitSignal(
                image_view.channel_control.coloring_update), qtbot.waitSignal(
                    image_view.channel_control.change_channel,
                    check_params_cb=check_parameters):
            ch_property.use_filter.set_value(NoiseFilterType.Gauss)
        image4 = image_view.viewer_widget.screenshot()
        assert np.any(image4 != 255)
        assert np.any(image1 != image4)
        assert np.any(image2 != image4)
        assert np.any(image3 != image4)
        with qtbot.waitSignal(
                image_view.channel_control.coloring_update), qtbot.waitSignal(
                    image_view.channel_control.change_channel,
                    check_params_cb=check_parameters):
            ch_property.filter_radius.setValue(1)
        image5 = image_view.viewer_widget.screenshot()
        assert np.any(image5 != 255)
        assert np.any(image1 != image5)
        assert np.any(image2 != image5)
        assert np.any(image3 != image5)
        assert np.any(image4 != image5)
        # Test gauss and fixed range
        ch_property.minimum_value.setValue(100)
        ch_property.maximum_value.setValue(10000)
        with qtbot.waitSignal(
                image_view.channel_control.coloring_update), qtbot.waitSignal(
                    image_view.channel_control.change_channel,
                    check_params_cb=check_parameters):
            ch_property.fixed.setChecked(True)

        image1 = image_view.viewer_widget.screenshot()
        with qtbot.waitSignal(
                image_view.channel_control.coloring_update), qtbot.waitSignal(
                    image_view.channel_control.change_channel,
                    check_params_cb=check_parameters):
            ch_property.minimum_value.setValue(10)
        image2 = image_view.viewer_widget.screenshot()
        assert np.any(image2 != 255)
        assert np.any(image1 != image2)

        with qtbot.waitSignal(
                image_view.channel_control.coloring_update), qtbot.waitSignal(
                    image_view.channel_control.change_channel,
                    check_params_cb=check_parameters):
            ch_property.maximum_value.setValue(11000)
        image3 = image_view.viewer_widget.screenshot()
        assert np.any(image3 != 255)
        assert np.any(image2 != image3)
        assert np.any(image1 != image3)

        with qtbot.waitSignal(
                image_view.channel_control.coloring_update), qtbot.waitSignal(
                    image_view.channel_control.change_channel,
                    check_params_cb=check_parameters):
            ch_property.fixed.setChecked(False)

        image1 = image_view.viewer_widget.screenshot()
        assert np.any(image1 != 255)
        assert np.any(image1 != image2)
        assert np.any(image1 != image3)