Beispiel #1
0
def exec_image_open_dialog(parent,
                           basedir='',
                           app_name=None,
                           to_grayscale=True,
                           dtype=None):
    """
    Executes an image open dialog box (QFileDialog.getOpenFileName)
        * parent: parent widget (None means no parent)
        * basedir: base directory ('' means current directory)
        * app_name (opt.): application name (used as a title for an eventual 
          error message box in case something goes wrong when saving image)
        * to_grayscale (default=True): convert image to grayscale
    
    Returns (filename, data) tuple if dialog is accepted, None otherwise
    """
    saved_in, saved_out, saved_err = sys.stdin, sys.stdout, sys.stderr
    sys.stdout = None
    filename, _filter = getopenfilename(
        parent, _("Open"), basedir,
        io.iohandler.get_filters('load', dtype=dtype))
    sys.stdin, sys.stdout, sys.stderr = saved_in, saved_out, saved_err
    filename = to_text_string(filename)
    try:
        data = io.imread(filename, to_grayscale=to_grayscale)
    except Exception as msg:
        import traceback
        traceback.print_exc()
        QMessageBox.critical(parent,
             _('Error') if app_name is None else app_name,
             (_("%s could not be opened:") % osp.basename(filename))+\
             "\n"+str(msg))
        return
    return filename, data
Beispiel #2
0
def exec_image_open_dialog(parent, basedir='', app_name=None,
                           to_grayscale=True, dtype=None):
    """
    Executes an image open dialog box (QFileDialog.getOpenFileName)
        * parent: parent widget (None means no parent)
        * basedir: base directory ('' means current directory)
        * app_name (opt.): application name (used as a title for an eventual 
          error message box in case something goes wrong when saving image)
        * to_grayscale (default=True): convert image to grayscale
    
    Returns (filename, data) tuple if dialog is accepted, None otherwise
    """
    saved_in, saved_out, saved_err = sys.stdin, sys.stdout, sys.stderr
    sys.stdout = None
    filename, _filter = getopenfilename(parent, _("Open"), basedir,
                                io.iohandler.get_filters('load', dtype=dtype))
    sys.stdin, sys.stdout, sys.stderr = saved_in, saved_out, saved_err
    filename = to_text_string(filename)
    try:
        data = io.imread(filename, to_grayscale=to_grayscale)
    except Exception as msg:
        import traceback
        traceback.print_exc()
        QMessageBox.critical(parent,
             _('Error') if app_name is None else app_name,
             (_("%s could not be opened:") % osp.basename(filename))+\
             "\n"+str(msg))
        return
    return filename, data
Beispiel #3
0
def create_test_data(fname, func=None):
    array0 = io.imread(osp.join(osp.dirname(__file__), fname),
                       to_grayscale=True)
    if func is not None:
        array0 = func(array0)
    item0 = make.trimage(array0, dx=.1, dy=.1)
    return array0, item0
Beispiel #4
0
 def _get_image_data(self, data, filename, title, to_grayscale):
     if data is None:
         assert filename is not None
         from guiqwt import io
         data = io.imread(filename, to_grayscale=to_grayscale)
     if title is None and filename is not None:
         title = osp.basename(filename)
     return data, filename, title
Beispiel #5
0
 def open_image(self, filename):
     """Opening image *filename*"""
     self.data = io.imread(filename, to_grayscale=True)
     self.show_data(self.data)
     param = ImageParam()
     param.title = filename
     param.height, param.width = self.data.shape
     update_dataset(self.param_gbox.dataset, param)
     self.param_gbox.get()
     self.filter_gbox.setEnabled(True)
Beispiel #6
0
 def open_image(self, filename):
     """Opening image *filename*"""
     self.data = io.imread(filename, to_grayscale=True)
     self.show_data(self.data)
     param = ImageParam()
     param.title = filename
     param.height, param.width = self.data.shape
     update_dataset(self.param_gbox.dataset, param)
     self.param_gbox.get()
     self.filter_gbox.setEnabled(True)
Beispiel #7
0
def test():
    """Test"""
    import os.path as osp
    from guiqwt import io, scaler, pyplot as plt

    filename = osp.join(osp.dirname(__file__), "brain.png")
    data = io.imread(filename)
    dst_image = scaler.resize(data, (2000, 3000))

    plt.imshow(dst_image, interpolation='nearest')
    plt.show()
Beispiel #8
0
def test():
    """Test"""
    import os.path as osp
    from guiqwt import io, scaler, pyplot as plt

    filename = osp.join(osp.dirname(__file__), "brain.png")
    data = io.imread(filename)
    dst_image = scaler.resize(data, (2000, 3000))

    plt.imshow(dst_image, interpolation='nearest')
    plt.show()
Beispiel #9
0
def test():
    """Test"""
    # -- Create QApplication
    import guidata
    _app = guidata.qapplication()
    # --
    from guiqwt.tests.imagexy import compute_image
    x, y, data = compute_image()
    imshow(x, y, data, filter_area=(-3., -1., 0., 2.), yreverse=False)
    # --
    import os.path as osp, numpy as np
    from guiqwt import io
    filename = osp.join(osp.dirname(__file__), "brain.png")
    data = io.imread(filename, to_grayscale=True)
    x = np.linspace(0, 30., data.shape[1])
    y = np.linspace(0, 30., data.shape[0])
    imshow(x, y, data, filter_area=(10, 20, 5, 15))
Beispiel #10
0
def test():
    """Test"""
    # -- Create QApplication
    import guidata
    _app = guidata.qapplication()
    # --
    from guiqwt.tests.imagexy import compute_image
    x, y, data = compute_image()
    imshow(x, y, data, filter_area=(-3., -1., 0., 2.), yreverse=False)
    # --
    import os.path as osp, numpy as np
    from guiqwt import io
    filename = osp.join(osp.dirname(__file__), "brain.png")
    data = io.imread(filename, to_grayscale=True)
    x = np.linspace(0, 30., data.shape[1])
    y = np.linspace(0, 30., data.shape[0])
    imshow(x, y, data, filter_area=(10, 20, 5, 15))
Beispiel #11
0
def imread(fname, to_grayscale=False):
    """Read data from *fname*"""
    from guiqwt import io
    return io.imread(fname, to_grayscale=to_grayscale)
Beispiel #12
0
 def add_image_from_file(self, filename):
     image = ImageParam()
     image.title = to_text_string(filename)
     image.data = io.imread(filename, to_grayscale=True)
     image.height, image.width = image.data.shape
     self.add_image(image)
Beispiel #13
0
 def add_image_from_file(self, filename):
     image = ImageParam()
     image.title = to_text_string(filename)
     image.data = io.imread(filename, to_grayscale=True)
     image.height, image.width = image.data.shape
     self.add_image(image)
Beispiel #14
0
def imread(fname, to_grayscale=False):
    """Read data from *fname*"""
    from guiqwt import io
    return io.imread(fname, to_grayscale=to_grayscale)