def _get_resized_image_stack(flist): """ Load all images in a list and resize to OPTIONS['size'] When files are parsed, the variables are used in an index to provide a method to reference a specific file name by its dimensions. This function returns the variable index based on the input filename pattern. Inputs:ed th flist - Paths of list of images to load and resize Outputs: img_stack - A 3D stack of 2D images X - width of image Y - height of image """ #Initialize the output br = BioReader(str(flist[0])) X = br.num_x() Y = br.num_y() C = len(flist) img_stack = np.zeros((OPTIONS['size'], OPTIONS['size'], C), dtype=np.float32) # Load every image as a z-slice for ind, fname in zip(range(len(flist)), flist): br = BioReader(str(fname)) I = np.squeeze(br.read_image()) img_stack[:, :, ind] = cv2.resize( I, (OPTIONS['size'], OPTIONS['size']), interpolation=cv2.INTER_LINEAR).astype(np.float32) return img_stack, X, Y
def buffer_image(self, image_path, Xi, Yi, Xt, Yt, color=False): """buffer_image Load and image and store in buffer This method loads an image and stores it in the appropriate position based on the stitching vector coordinates within a large tile of the output image. It is intended to be used as a thread to increase the reading component to assembling the image. Args: image_path ([str]): Path to image to load Xi ([list]): Xmin and Xmax of pixels to load from the image Yi ([list]): Ymin and Ymax of pixels to load from the image Xt ([list]): X position within the buffer to store the image Yt ([list]): Y position within the buffer to store the image """ # Load the image br = BioReader(image_path, max_workers=2) image = br.read_image(X=Xi, Y=Yi) # only get the first z,c,t layer # Put the image in the buffer if color != None: image_temp = ( 255 * (image[..., 0, 0].astype(np.float32) - self.bounds[0]) / (self.bounds[1] - self.bounds[0])) image_temp[image_temp > 255] = 255 image_temp[image_temp < 0] = 0 image_temp = image_temp.astype(np.uint8) self._image[Yt[0]:Yt[1], Xt[0]:Xt[1], ...] = 0 self._image[Yt[0]:Yt[1], Xt[0]:Xt[1], self.color] = image_temp else: self._image[Yt[0]:Yt[1], Xt[0]:Xt[1], ...] = image[:, :, :, 0, 0]
def _merge_layers(input_dir, input_files, output_dir, output_file): zs = [z for z in input_files.keys()] # sorted list of filenames by z-value zs.sort() # Initialize the output file br = BioReader( str(Path(input_dir).joinpath(input_files[zs[0]][0]).absolute())) bw = BioWriter(str(Path(output_dir).joinpath(output_file).absolute()), metadata=br.read_metadata()) bw.num_z(Z=len(zs)) del br # Load each image and save to the volume file for z, i in zip(zs, range(len(zs))): br = BioReader( str(Path(input_dir).joinpath(input_files[z][0]).absolute())) bw.write_image(br.read_image(), Z=[i, i + 1]) del br # Close the output image and delete bw.close_image() del bw
jutil.start_vm(args=["-Dlog4j.configuration=file:{}".format(str(log_config.absolute()))],class_path=bioformats.JARS) {% endif -%} {% for inp,val in cookiecutter._inputs|dictsort -%} {% if val.type=="collection" -%} # Get all file names in {{ inp }} image collection {{ inp }}_files = [f.name for f in Path({{ inp }}).iterdir() if f.is_file() and "".join(f.suffixes)=='.ome.tif'] {% endif %} {% endfor -%} {% for inp,val in cookiecutter._inputs|dictsort -%} {% for out,n in cookiecutter._outputs|dictsort -%} {% if val.type=="collection" and cookiecutter.use_bfio -%} # Loop through files in {{ inp }} image collection and process for i,f in enumerate({{ inp }}_files): # Load an image br = BioReader(Path({{ inp }}).joinpath(f)) image = np.squeeze(br.read_image()) # initialize the output out_image = np.zeros(image.shape,dtype=br._pix['type']) """ Do some math and science - you should replace this """ logger.info('Processing image ({}/{}): {}'.format(i,len({{ inp }}_files),f)) out_image = awesome_math_and_science_function(image) # Write the output bw = BioWriter(Path({{ out }}).joinpath(f),metadata=br.read_metadata()) bw.write_image(np.reshape(out_image,(br.num_y(),br.num_x(),br.num_z(),1,1))) {%- endif %}{% endfor %}{% endfor %} finally: {%- if cookiecutter.use_bfio %}
logger = logging.getLogger("do_flat") logger.setLevel(logging.INFO) # Set up the FilePattern object images = FilePattern(inpDir, filepattern) ''' Start the javabridge ''' logger.info("Starting the javabridge...") log_config = Path(__file__).parent.joinpath("log4j.properties") jutil.start_vm(args=[ "-Dlog4j.configuration=file:{}".format(str(log_config.absolute())) ], class_path=bioformats.JARS) ''' Load the flatfielding data ''' logger.info("Loading the flatfield data...") flat_br = BioReader(brightfield) flat_image = np.squeeze(flat_br.read_image()) del flat_br # Normalize the brightfield image if it isn't done already flat_image = flat_image.astype(np.float32) flat_image = np.divide(flat_image, np.mean(flat_image)) # Load the darkfield and photobleach offsets if they are specified if darkfield != None: dark_br = BioReader(darkfield) dark_image = np.squeeze(dark_br.read_image()) del dark_br else: dark_image = np.zeros(flat_image.shape, dtype=np.float32) if photobleach != None: with open(photobleach, 'r') as f: