def fromFile(filename, **kwargs): """fromFile(filename, [background='' or True]): Load Image from filename with optional background file or constant to subtract. fromFile('image.img', background = 'filename') => load background file and subtract (SLOW!) fromFile('background.img', background=True, [filter='median']) => load background.img as background file fromFile('image.img', background=100) => subtract 100 from image as background level """ bg = kwargs.pop('background', False) roi = kwargs.pop('roi', None) try: img = Stack(fileIO.add_img_ext(filename), **kwargs) except IOError: raise IOError("File %s can't be found/loaded" % filename) if bg is True: return img.toBackground(**kwargs) elif isinstance(bg,str): bg = Stack(bg) bg.toBackground(**kwargs) result = img - bg if roi is not None: rois = ROI.fromFile(roi) result.addROI(*rois) return result
def fromFile(filename, background=None, **kwargs): """fromFile(filename, [background='' or True]): Load Image from filename with optional background file or constant to subtract. fromFile('image.img', background = 'filename') => load background file and subtract (SLOW!) fromFile('image.img', background=100) => subtract 100 from image as background level """ roi = kwargs.pop('roi', None) img = Stack.fromfile(fileIO.add_img_ext(filename)) bgimg = fromBackground(background) bg_exposure = bgimg.metadata['exposurems'] if not isinstance(bgimg, ConstantStack) and bg_exposure != img.metadata['exposurems']: print '''WARNING Trying to subtract background with exposure time {} from image with exposure time {}'''.format( bg_exposure, img.metadata['exposurems']) img.metadata['background'] = bgimg.metadata['filename'] or background img -= bgimg if roi is not None: if isinstance(roi, basestring): roi = ROI.fromFile(roi) img.addROI(*roi) return img
def loadimg(p, directory='.', **kwargs): '''Return the Stack image using ROI and background stored in experiment metadata. Must be in current or specified directory. ''' filename = p.filename if directory=='.' else opath.join(directory, p.filename) meta = p.fret.metadata if 'roi' not in kwargs: # If keyword roi= is not specified, # get the ROIs from the experiment metadata rois = [ meta[roi_key] for roi_key in ('roi_donor', 'roi_acceptor') if roi_key in meta ] kwargs['roi'] = map(ROI.fromDict, rois) kwargs.setdefault('background', meta.get('background', '') ) return image.fromFile(fileIO.add_img_ext(filename), **kwargs)
def loadimg(self, path='.', **kwargs): filename = self.filename return image.Stack(fileIO.add_img_ext(filename)) return image.fromFile(filename, **kwargs)