Beispiel #1
0
def exec_image_save_dialog(parent, data, template=None,
                           basedir='', app_name=None):
    """
    Executes an image save dialog box (QFileDialog.getSaveFileName)
        * parent: parent widget (None means no parent)
        * data: image pixel array data
        * template: image template (pydicom dataset) for DICOM files
        * 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)
    
    Returns filename if dialog is accepted, None otherwise
    """
    saved_in, saved_out, saved_err = sys.stdin, sys.stdout, sys.stderr
    sys.stdout = None
    filename, _filter = getsavefilename(parent, _("Save as"), basedir,
        io.iohandler.get_filters('save', dtype=data.dtype, template=template))
    sys.stdin, sys.stdout, sys.stderr = saved_in, saved_out, saved_err
    if filename:
        filename = to_text_string(filename)
        kwargs = {}
        if osp.splitext(filename)[1].lower() == '.dcm':
            kwargs['template'] = template
        try:
            io.imwrite(filename, data, **kwargs)
            return filename
        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 written:") % osp.basename(filename))+\
                 "\n"+str(msg))
            return
Beispiel #2
0
def save_image(name, data):
    for fname in (name + ".u16.tif", name + ".u8.png"):
        if os.path.exists(fname):
            os.remove(fname)
    print("Saving image: %d x %d (%d KB):" %
          (data.shape[0], data.shape[1], data.nbytes / 1024.0))
    print(" --> uint16")
    io.imwrite(name + ".u16.tif", data, dtype=np.uint16, max_range=True)
    print(" --> uint8")
    io.imwrite(name + ".u8.png", data, dtype=np.uint8, max_range=True)
Beispiel #3
0
def save_image(name, data):
    for fname in (name+".u16.tif", name+".u8.png"):
        if os.path.exists(fname):
            os.remove(fname)
    print("Saving image: %d x %d (%d KB):" % (data.shape[0], data.shape[1],
                                              data.nbytes/1024.))
    print(" --> uint16")
    io.imwrite(name+".u16.tif", data, dtype=np.uint16, max_range=True)
    print(" --> uint8")
    io.imwrite(name+".u8.png", data, dtype=np.uint8, max_range=True)
Beispiel #4
0
def exec_image_save_dialog(parent,
                           data,
                           template=None,
                           basedir="",
                           app_name=None):
    """
    Executes an image save dialog box (QFileDialog.getSaveFileName)
        * parent: parent widget (None means no parent)
        * data: image pixel array data
        * template: image template (pydicom dataset) for DICOM files
        * 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)
    
    Returns filename if dialog is accepted, None otherwise
    """
    saved_in, saved_out, saved_err = sys.stdin, sys.stdout, sys.stderr
    sys.stdout = None
    filename, _filter = getsavefilename(
        parent,
        _("Save as"),
        basedir,
        io.iohandler.get_filters("save", dtype=data.dtype, template=template),
    )
    sys.stdin, sys.stdout, sys.stderr = saved_in, saved_out, saved_err
    if filename:
        filename = to_text_string(filename)
        kwargs = {}
        if osp.splitext(filename)[1].lower() == ".dcm":
            kwargs["template"] = template
        try:
            io.imwrite(filename, data, **kwargs)
            return filename
        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 written:") % osp.basename(filename)) +
                "\n" + str(msg),
            )
            return
Beispiel #5
0
def save_image(name, data):
    io.imwrite(name + ".u16.tif", data, dtype=np.uint16, max_range=True)
    io.imwrite(name + ".u8.png", data, dtype=np.uint8, max_range=True)
Beispiel #6
0
def save_image(name, data):
    io.imwrite(name+".u16.tif", data, dtype=np.uint16, max_range=True)
    io.imwrite(name+".u8.png", data, dtype=np.uint8, max_range=True)