def exec_images_open_dialog(parent, basedir='', app_name=None, to_grayscale=True, dtype=None): """ Executes an image*s* open dialog box (QFileDialog.getOpenFileNames) * 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 Yields (filename, data) tuples if dialog is accepted, None otherwise """ saved_in, saved_out, saved_err = sys.stdin, sys.stdout, sys.stderr sys.stdout = None filenames, _filter = getopenfilenames( parent, _("Open"), basedir, io.iohandler.get_filters('load', dtype=dtype)) sys.stdin, sys.stdout, sys.stderr = saved_in, saved_out, saved_err filenames = [to_text_string(fname) for fname in list(filenames)] for filename in filenames: 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 yield filename, data
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
def exec_images_open_dialog(parent, basedir='', app_name=None, to_grayscale=True, dtype=None): """ Executes an image*s* open dialog box (QFileDialog.getOpenFileNames) * 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 Yields (filename, data) tuples if dialog is accepted, None otherwise """ saved_in, saved_out, saved_err = sys.stdin, sys.stdout, sys.stderr sys.stdout = None filenames, _filter = getopenfilenames(parent, _("Open"), basedir, io.iohandler.get_filters('load', dtype=dtype)) sys.stdin, sys.stdout, sys.stderr = saved_in, saved_out, saved_err filenames = [to_text_string(fname) for fname in list(filenames)] for filename in filenames: 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 yield filename, data
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
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)
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)
def test(): """Test""" import os.path as osp from plotpy 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()
def test(): """Test""" # -- Create QApplication import plotpy _app = plotpy.qapplication() # -- from plotpy.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 plotpy 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))
def imread(fname, to_grayscale=False): """Read data from *fname*""" from plotpy import io return io.imread(fname, to_grayscale=to_grayscale)
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)
def imread(fname, to_grayscale=False): """Read data from *fname*""" from plotpy import io return io.imread(fname, to_grayscale=to_grayscale)