~ubuntu-branches/ubuntu/oneiric/guiqwt/oneiric

« back to all changes in this revision

Viewing changes to guiqwt/tests/imagefilter.py

  • Committer: Bazaar Package Importer
  • Author(s): Picca Frédéric-Emmanuel
  • Date: 2010-11-13 11:26:05 UTC
  • Revision ID: james.westby@ubuntu.com-20101113112605-k2ffx4p80rict966
Tags: upstream-2.0.8.1
Import upstream version 2.0.8.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
#
 
3
# Copyright © 2009-2010 CEA
 
4
# Pierre Raybaut
 
5
# Licensed under the terms of the CECILL License
 
6
# (see guiqwt/__init__.py for details)
 
7
 
 
8
"""Image filter demo"""
 
9
 
 
10
SHOW = True # Show test in GUI-based test launcher
 
11
 
 
12
from scipy.ndimage import gaussian_filter
 
13
 
 
14
from guiqwt.plot import ImageDialog
 
15
from guiqwt.builder import make
 
16
 
 
17
def imshow(x, y, data, filter_area, yreverse=True):
 
18
    win = ImageDialog(edit=False, toolbar=True, wintitle="Image filter demo",
 
19
                      options=dict(xlabel="x (cm)", ylabel="y (cm)",
 
20
                                   yreverse=yreverse))
 
21
    image = make.xyimage(x, y, data)
 
22
    plot = win.get_plot()
 
23
    plot.add_item(image)
 
24
    xmin, xmax, ymin, ymax = filter_area
 
25
    flt = make.imagefilter(xmin, xmax, ymin, ymax, image,
 
26
                           filter=lambda x, y, data: gaussian_filter(data, 5))
 
27
    plot.add_item(flt, z=1)
 
28
    plot.replot()
 
29
    win.show()
 
30
    win.exec_()
 
31
 
 
32
def test():
 
33
    """Test"""
 
34
    # -- Create QApplication
 
35
    import guidata
 
36
    guidata.qapplication()
 
37
    # --
 
38
    from guiqwt.tests.imagexy import compute_image
 
39
    x, y, data = compute_image()
 
40
    imshow(x, y, data, filter_area=(-3., -1., 0., 2.), yreverse=False)
 
41
    # --
 
42
    import os.path as osp, numpy as np
 
43
    from guiqwt.io import imagefile_to_array
 
44
    filename = osp.join(osp.dirname(__file__), "brain.png")
 
45
    data = imagefile_to_array(filename)
 
46
    x = np.linspace(0, 30., data.shape[1])
 
47
    y = np.linspace(0, 30., data.shape[0])
 
48
    imshow(x, y, data, filter_area=(10, 20, 5, 15))
 
49
 
 
50
if __name__ == "__main__":
 
51
    test()