Esempio n. 1
0
def read_image(filename, index=None):
    '''
    '''

    qimg = QtGui.QImage()
    if qimg.load(filename): return qimg
    return ndimage_utility.normalize_min_max(
        ndimage_file.read_image(filename, index))
Esempio n. 2
0
def iter_images(files, index, template=None, average=False):
    ''' Wrapper for iterate images that support color PNG files
    
    :Parameters:
    
    filename : str
               Input filename
    
    :Returns:
    
    img : array
          Image array
    '''

    qimg = QtGui.QImage()
    if template is not None:
        filename = spider_utility.spider_filename(template, files[0])
    else:
        filename = files[0]
    header = {}
    if qimg.load(filename):
        if isinstance(index[0], str): files = index
        else: files = [files[i[0]] for i in index]
        for filename in files:
            qimg = QtGui.QImage()
            if template is not None:
                filename = spider_utility.spider_filename(template, filename)
            if not qimg.load(filename):
                qimg = QtGui.QPixmap(":/mini/mini/cross.png").toImage()
                _logger.warn("Unable to read image - %s" % filename)
                #raise IOError, "Unable to read image - %s"%filename
            yield (filename, 0), qimg, 1.0
    else:
        # todo reorganize with
        '''
        for img in itertools.imap(ndimage_utility.normalize_min_max, ndimage_file.iter_images(filename, index)):
        '''
        if isinstance(index[0], str):
            for f in index:
                avg = None
                if template is not None:
                    f1 = spider_utility.spider_filename(template, f)
                    if os.path.exists(f1): f = f1
                    else:
                        _logger.warn("Unabled to find alternate image: %s" %
                                     f1)
                for img in ndimage_file.iter_images(f, header=header):
                    if avg is None: avg = img
                    else: avg += img
                try:
                    img = ndimage_utility.normalize_min_max(avg)
                except:
                    img = avg
                yield (f, 0), img, header.get('apix', 1.0)
        else:
            for idx in index:
                f, i = idx[:2]
                filename = files[f]
                if template is not None:
                    filename = spider_utility.spider_filename(
                        template, filename)
                try:
                    img = ndimage_file.read_image(filename, i, header=header)
                except:
                    _logger.exception("Error while reading!")
                    img = ndimage_file.read_image(filename, header=header)
                    #print f, i, len(files), files[f], template, filename
                    #raise
                try:
                    img = ndimage_utility.normalize_min_max(img)
                except:
                    pass
                yield (filename, i), img, header.get('apix', 1.0)
        '''