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
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))
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
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
def base_settings(image, tmp_path, measurement_profiles): settings = BaseSettings(tmp_path) settings.image = image return settings
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)
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)