def main(): args = parse_args() infile = InputFile(args.input_file) infile.channel = args.c total_byte_size = np.asscalar(np.prod(infile.shape) * infile.dtype.itemsize) bigtiff = total_byte_size > 2 ** 31 - 1 n = int(total_byte_size // (psutil.virtual_memory().available * 0.9)) + 1 try: os.remove(args.output_file) except FileNotFoundError: pass curr_z = 0 part_height = infile.nfrms // n end_loop = False while True: end_z = curr_z + part_height if end_z >= infile.shape[0]: end_z = infile.shape[0] end_loop = True logger.info('loading \tz=[{}:{}]'.format(curr_z, end_z)) img = infile[curr_z:end_z] logger.info('saving to {}'.format(args.output_file)) tiff.imsave(args.output_file, img, append=True, bigtiff=bigtiff) curr_z = end_z if end_loop: break
def main(): args = parse_args() infile = InputFile(args.input_file) if args.channel is not None: infile.channel = args.channel total_byte_size = np.asscalar(np.prod(infile.shape) * infile.dtype.itemsize) bigtiff = total_byte_size > 2 ** 31 - 1 ram = psutil.virtual_memory().available * 0.5 n_of_parts = ceil(total_byte_size / ram) try: os.remove(args.output_file) except FileNotFoundError: pass curr_z = 0 part_height = infile.nfrms // n_of_parts end_loop = False mip = np.zeros(infile.shape[1:], dtype=infile.dtype) tiff.imsave(args.output_file, mip) while True: end_z = curr_z + part_height if end_z >= infile.shape[0]: end_z = infile.shape[0] end_loop = True logger.info('loading \tz=[{}:{}]'.format(curr_z, end_z)) img = infile[curr_z:end_z] logger.info('Computing MIP...') mip = np.maximum(np.max(img, axis=0), mip) del img curr_z = end_z if end_loop: break logger.info('saving to {}'.format(args.output_file)) if args.channel is None and infile.nchannels > 1: mip = np.moveaxis(mip, -3, -1) tiff.imsave(args.output_file, mip)
def main(): args = parse_args() infile = InputFile(args.input_file) if args.channel != -1: infile.channel = args.channel os.makedirs(args.output_directory, exist_ok=True) n_of_digits = math.ceil(math.log10(infile.nfrms)) output_filename_fmt = '{:0' + str(n_of_digits) + '}.tiff' for z in range(infile.nfrms): a = infile[z] if infile.nchannels != 1 and infile.channel == -1: a = np.moveaxis(a, -3, -1) output_filename = os.path.join(args.output_directory, output_filename_fmt.format(z)) logger.info('saving to {}'.format(output_filename)) tiff.imsave(output_filename, a, compress=args.compression)