def build_items():
    x = np.linspace(-10, 10, 200)
    y = np.sin(np.sin(np.sin(x)))
    filename = osp.join(osp.dirname(__file__), "brain.png")
    items = [ 
              make.curve(x, y, color="b"),
              make.image(filename=filename),
              make.trimage(filename=filename),
              make.maskedimage(filename=filename, colormap='gray',
                               show_mask=True, xdata=[0, 40], ydata=[0, 50]),
              make.label("Relative position <b>outside</b>",
                         (x[0], y[0]), (-10, -10), "BR"),
              make.label("Relative position <i>inside</i>",
                         (x[0], y[0]), (10, 10), "TL"),
              make.label("Absolute position", "R", (0, 0), "R"),
              make.legend("TR"),
              make.rectangle(-3, -0.8, -0.5, -1., "rc1"),
              make.segment(-3, -0.8, -0.5, -1., "se1"),
              make.ellipse(-10, 0.0, 0, 0, "el1"),
              make.annotated_rectangle(0.5, 0.8, 3, 1., "rc1", "tutu"),
              make.annotated_segment(-1, -1, 1, 1., "rc1", "tutu"),
              Axes( (0, 0), (1, 0), (0, 1) ),
              PolygonShape(np.array([[150., 330.],
                                     [270., 520.],
                                     [470., 480.],
                                     [520., 360.],
                                     [460., 200.],
                                     [250., 240.]])),
              ]
    return items
Exemple #2
0
def imshow(data, interpolation=None, mask=None):
    """
    Display the image in *data* to current axes
    interpolation: 'nearest', 'linear' (default), 'antialiasing'
    
    Example:
        
    import numpy as np
    x = np.linspace(-5, 5, 1000)
    img = np.fromfunction(lambda x, y:
                          np.sin((x/200.)*(y/200.)**2), (1000, 1000))
    gray()
    imshow(img)
    show()
    """
    axe = gca()
    import numpy as np
    if isinstance(data, np.ma.MaskedArray) and mask is None:
        mask = data.mask
        data = data.data
    if mask is None:
        img = make.image(data)
    else:
        img = make.maskedimage(data, mask, show_mask=True)
    if interpolation is not None:
        interp_dict = {'nearest': INTERP_NEAREST,
                       'linear': INTERP_LINEAR,
                       'antialiasing': INTERP_AA}
        assert interpolation in interp_dict, "invalid interpolation option"
        img.set_interpolation(interp_dict[interpolation], size=5)
    axe.add_image(img)
    axe.yreverse = True
    _show_if_interactive()
    return [img]
def build_items():
    x = np.linspace(-10, 10, 200)
    y = np.sin(np.sin(np.sin(x)))
    filename = osp.join(osp.dirname(__file__), "brain.png")
    items = [
        make.curve(x, y, color="b"),
        make.image(filename=filename),
        make.trimage(filename=filename),
        make.maskedimage(filename=filename,
                         colormap='gray',
                         show_mask=True,
                         xdata=[0, 40],
                         ydata=[0, 50]),
        make.label("Relative position <b>outside</b>", (x[0], y[0]),
                   (-10, -10), "BR"),
        make.label("Relative position <i>inside</i>", (x[0], y[0]), (10, 10),
                   "TL"),
        make.label("Absolute position", "R", (0, 0), "R"),
        make.legend("TR"),
        make.rectangle(-3, -0.8, -0.5, -1., "rc1"),
        make.segment(-3, -0.8, -0.5, -1., "se1"),
        make.ellipse(-10, 0.0, 0, 0, "el1"),
        make.annotated_rectangle(0.5, 0.8, 3, 1., "rc1", "tutu"),
        make.annotated_segment(-1, -1, 1, 1., "rc1", "tutu"),
        Axes((0, 0), (1, 0), (0, 1)),
        PolygonShape(
            np.array([[150., 330.], [270., 520.], [470., 480.], [520., 360.],
                      [460., 200.], [250., 240.]])),
    ]
    return items
Exemple #4
0
def imshow(data, interpolation=None, mask=None):
    """
    Display the image in *data* to current axes
    interpolation: 'nearest', 'linear' (default), 'antialiasing'
    
    Example::
        
        import numpy as np
        x = np.linspace(-5, 5, 1000)
        img = np.fromfunction(lambda x, y: np.sin((x/200.)*(y/200.)**2), (1000, 1000))
        gray()
        imshow(img)
        show()
    """
    axe = gca()
    import numpy as np
    if isinstance(data, np.ma.MaskedArray) and mask is None:
        mask = data.mask
        data = data.data
    if mask is None:
        img = make.image(data)
    else:
        img = make.maskedimage(data, mask, show_mask=True)
    if interpolation is not None:
        interp_dict = {
            'nearest': INTERP_NEAREST,
            'linear': INTERP_LINEAR,
            'antialiasing': INTERP_AA
        }
        assert interpolation in interp_dict, "invalid interpolation option"
        img.set_interpolation(interp_dict[interpolation], size=5)
    axe.add_image(img)
    axe.yreverse = True
    _show_if_interactive()
    return [img]
def test():
    """Test"""
    # -- Create QApplication
    import guidata

    _app = guidata.qapplication()
    # --
    win = OCSImageDialog(toolbar=True, wintitle="Oblique averaged cross section test")
    win.resize(600, 600)

    #    from guiqwt.tests.image import compute_image
    #    data = np.array((compute_image(4000, grid=False)+1)*32e3, dtype=np.uint16)
    #    image = make.maskedimage(data, colormap="bone", show_mask=True)

    filename = osp.join(osp.dirname(__file__), "brain_cylinder.png")
    image = make.maskedimage(filename=filename, colormap="bone")

    plot = win.get_plot()
    plot.add_item(image)
    win.exec_()
def test():
    """Test"""
    # -- Create QApplication
    import guidata
    _app = guidata.qapplication()
    # --
    win = OCSImageDialog(toolbar=True,
                         wintitle="Oblique averaged cross section test")
    win.resize(600, 600)

    #    from guiqwt.tests.image import compute_image
    #    data = np.array((compute_image(4000, grid=False)+1)*32e3, dtype=np.uint16)
    #    image = make.maskedimage(data, colormap="bone", show_mask=True)

    filename = osp.join(osp.dirname(__file__), "brain_cylinder.png")
    image = make.maskedimage(filename=filename, colormap="bone")

    plot = win.get_plot()
    plot.add_item(image)
    win.exec_()
Exemple #7
0
import os, os.path as osp, pickle

from guiqwt.plot import ImageDialog
from guiqwt.tools import ImageMaskTool
from guiqwt.builder import make

SHOW = True  # Show test in GUI-based test launcher

FNAME = "image_masked.pickle"

if __name__ == "__main__":
    import guidata

    _app = guidata.qapplication()
    win = ImageDialog(toolbar=True, wintitle="Masked image item test")
    win.add_tool(ImageMaskTool)
    if os.access(FNAME, os.R_OK):
        print("Restoring mask...", end=" ")
        iofile = open(FNAME, "rb")
        image = pickle.load(iofile)
        iofile.close()
        print("OK")
    else:
        fname = osp.join(osp.abspath(osp.dirname(__file__)), "brain.png")
        image = make.maskedimage(filename=fname, colormap="gray", show_mask=True, xdata=[0, 20], ydata=[0, 25])
    win.get_plot().add_item(image)
    win.show()
    win.exec_()
    iofile = open(FNAME, "wb")
    pickle.dump(image, iofile)
Exemple #8
0
SHOW = True  # Show test in GUI-based test launcher

FNAME = "image_masked.pickle"

if __name__ == "__main__":
    import guidata

    _app = guidata.qapplication()
    win = ImageDialog(toolbar=True, wintitle="Masked image item test")
    win.add_tool(ImageMaskTool)
    if os.access(FNAME, os.R_OK):
        print("Restoring mask...", end=" ")
        iofile = open(FNAME, "rb")
        image = pickle.load(iofile)
        iofile.close()
        print("OK")
    else:
        fname = osp.join(osp.abspath(osp.dirname(__file__)), "brain.png")
        image = make.maskedimage(
            filename=fname,
            colormap="gray",
            show_mask=True,
            xdata=[0, 20],
            ydata=[0, 25],
        )
    win.get_plot().add_item(image)
    win.show()
    win.exec_()
    iofile = open(FNAME, "wb")
    pickle.dump(image, iofile)