コード例 #1
0
def test_image_contrast_tool():

    s = hs.signals.Signal2D(np.random.random(10000).reshape((100, 100)))
    s.plot()

    ceditor = ImageContrastEditor(s._plot.signal_plot)
    ceditor.gui(**KWARGS)

    vmin = 5
    ceditor.vmin_percentile = vmin
    assert ceditor.vmin_percentile == vmin

    vmax = 95
    ceditor.vmax_percentile = vmax
    assert ceditor.vmax_percentile == vmax
    
    auto = False
    ceditor.auto = auto
    assert ceditor.auto == auto

    for norm in ['Linear', 'Power', 'Log', 'Symlog']:
        ceditor.norm = norm
        assert ceditor.norm == norm
コード例 #2
0
ファイル: image.py プロジェクト: katrinleinweber/hyperspy
 def gui_adjust_contrast(self, display=True, toolkit=None):
     ceditor = ImageContrastEditor(self)
     return ceditor.gui(display=display, toolkit=toolkit)
コード例 #3
0
 def gui_adjust_contrast(self, display=True, toolkit=None):
     if self._is_rgb:
         raise NotImplementedError(
             "Constrast adjustment of RGB images is not implemented")
     ceditor = ImageContrastEditor(self)
     return ceditor.gui(display=display, toolkit=toolkit)
コード例 #4
0
    def test_constrast_editor(self):
        # To get this test to work, matplotlib backend needs to set to 'Agg'
        np.random.seed(1)
        im = hs.signals.Signal2D(np.random.random((32, 32)))
        im.plot()
        ceditor = ImageContrastEditor(im._plot.signal_plot)
        ceditor.ax.figure.canvas.draw_idle()
        wd = ceditor.gui(**KWARGS)["ipywidgets"]["wdict"]
        assert wd["linthresh"].layout.display == "none"  # not visible
        assert wd["linscale"].layout.display == "none"  # not visible
        assert wd["gamma"].layout.display == "none"  # not visible
        wd["bins"].value = 50
        assert ceditor.bins == 50
        wd["norm"].value = 'Log'
        assert ceditor.norm == 'Log'
        assert wd["linthresh"].layout.display == "none"  # not visible
        assert wd["linscale"].layout.display == "none"  # not visible
        wd["norm"].value = 'Symlog'
        assert ceditor.norm == 'Symlog'
        assert wd["linthresh"].layout.display == ""  # visible
        assert wd["linscale"].layout.display == ""  # visible
        assert wd["linthresh"].value == 0.01  # default value
        assert wd["linscale"].value == 0.1  # default value

        wd["linthresh"].value = 0.1
        assert ceditor.linthresh == 0.1
        wd["linscale"].value = 0.2
        assert ceditor.linscale == 0.2

        wd["norm"].value = 'Linear'
        percentile = [1.0, 99.0]
        wd["percentile"].value = percentile
        assert ceditor.vmin_percentile == percentile[0]
        assert ceditor.vmax_percentile == percentile[1]
        assert im._plot.signal_plot.vmin == f'{percentile[0]}th'
        assert im._plot.signal_plot.vmax == f'{percentile[1]}th'

        wd["norm"].value = 'Power'
        assert ceditor.norm == 'Power'
        assert wd["gamma"].layout.display == ""  # visible
        assert wd["gamma"].value == 1.0  # default value
        wd["gamma"].value = 0.1
        assert ceditor.gamma == 0.1

        assert wd["auto"].value is True  # default value
        wd["auto"].value = False
        assert ceditor.auto is False

        wd["left"].value = 0.2
        assert ceditor.ss_left_value == 0.2
        wd["right"].value = 0.5
        assert ceditor.ss_right_value == 0.5
        # Setting the span selector programmatically from the widgets will
        # need to be implemented properly
        wd["apply_button"]._click_handlers(wd["apply_button"])  # Trigger it
        # assert im._plot.signal_plot.vmin == 0.2
        # assert im._plot.signal_plot.vmax == 0.5

        # Reset to default values
        wd["reset_button"]._click_handlers(wd["reset_button"])  # Trigger it
        assert im._plot.signal_plot.vmin == '0.0th'
        assert im._plot.signal_plot.vmax == '100.0th'