Process Image#

Extract the Fourier components of all the granules in a time series.

Outline#

The first step calculates the rough shape and position of the granules in the frame, from this we score the granules and rank them.

Of the granules that pass, we then extract the border and use this to generate the Fourier terms.

Method#

We use the frame_gen object to return the image frame by frame, this is required in order to properly handle metadata and the proprietary microscope formats (and the resultant JavaVM).

For each frame we isolate the granules from the background image using granule_locator, by default this is uses a Difference of Gassian method. From each of these granules we draw the boundary around it using the methods in boundary_extraction. The final step is then to track the granules across the frames, accounting for both the creation and deletion of granules.

There is the option to create plots of both the granule detection and the boundary drawing, which is configured in the config file. We store all of the Fourier terms, into a .hdf5 database, along with links to any images created and metadata for each frame.

Multiprocessing#

The combination of multiprocessing and javabridge often lead to large memory leaks, particularly when initialising the worker pool. This means that only a single core can be used to analyse a single microscope image. However, the analysis is typically fast enough that only using a single core on a single microscope image is not a problem.

Parallelisation can be achieved by passing a directory of images into main() and setting the number of cores to use with the -c flag. This will analyse each image in a separate process and save the results as normal. Resources are allocated dynamically so only the required number of cores are used, up to a maximum of the number specified with the -c flag.

flickerprint.workflow.process_image.consolidate_fourier_terms(fourier_frame: DataFrame) DataFrame#

Merge the Fourier terms into a pivot table.

In theory this is a much more compact way of representing the data, but for some reason it is poorly behaved with pivot tables.

This would also require some conversion step to melt it back into the table.

flickerprint.workflow.process_image.main(input_image: Path | str | None = None, output_dir: Path | str = '.', quiet: bool = False, max_frame: int | None = None, cores=1)#

Takes an image or a directory of images and processes them to extract the granule boundaries and Fourier terms. These are retruned as a .h5 file in the experiment’s ‘fourier’ directory.

Parameters:#

input_image: Path | str

The path to the image or directory of images to be processed. If a directory is provided, all images in the directory will be processed. If ‘default_images’ is provided, the default images in the ‘images’ directory will be processed. If no input is provided, the default image directory set in the config file will be used.

output_dir: Path | str

The directory to save the output files to. If no output directory is provided, the current directory will be used.

quiet: bool

If True, the progress bar will be suppressed. Default is False.

max_frame: int

The maximum number of frames to process. Default is None which processes all frames.

cores: int

The number of cores to use for multiprocessing. Default is 1. Only required if a directory of images is provided. If the number of cores requested exceeds the number of available cores, the number of available cores will be used instead.

Debugging images to show the location and boundary of the detected granules. These images are saved in the ‘tracking’ directory in the ‘detection’ and ‘outline’ subdirectories. Debugging images can be configured using the ‘granule_images’ parameter in the config file.

flickerprint.workflow.process_image.write_hdf(save_path: Path, fourier_frames: DataFrame, frame_data)#

Write the data out as hdf5 files.

This is more stable and portable than the previous pickle method. It also allows storage of metadata in a more sane manner.