def stack2mrc(stack, mrc, imfilter=lambda im: im): """ Converts an image stack to an MRC file. Returns the new MRC file object. Arguments: stack -- the images to read, an iterable of file names mrc -- the MRC filename to save to Optional Arguments: imfilter -- a function/callable that takes and returns an image """ from mrc import MRC from images import imread stack = iter(stack) try: img = imfilter(imread(stack.next())) except StopIteration: raise ValueError("Must provide at least one image") mrc = MRC(mrc, nx=img.shape[1], ny=img.shape[0], dtype=img.dtype) mrc.append(img) mrc.append_all(imfilter(imread(img)) for img in stack) # will skip the first one mrc.write_header() return mrc
def stack2mrc(stack, mrc, imfilter = lambda im: im): """ Converts an image stack to an MRC file. Returns the new MRC file object. Arguments: stack -- the images to read, an iterable of file names mrc -- the MRC filename to save to Optional Arguments: imfilter -- a function/callable that takes and returns an image """ from mrc import MRC from images import imread stack = iter(stack) try: img = imfilter(imread(stack.next())) except StopIteration: raise ValueError("Must provide at least one image") mrc = MRC(mrc, nx=img.shape[1], ny=img.shape[0], dtype=img.dtype) mrc.append(img) mrc.append_all(imfilter(imread(img)) for img in stack) # will skip the first one mrc.write_header() return mrc