Priciple of operation

The Spim and its stages

A Spim is the object holding the images and metadata. It has methods, that return a Spim of the next stage. For example, a blank, empty Spim can be created and is then in the stage SpimStage.new. It contains only the information where to find the image file. If Spim.read(Writer) is called, a new Spim is returned, which contains the image data and is at stage SpimStage.loaded.

Here is a list of the stages that a Spim can be in and in between, the methods that return a Spim of the next stage.

strict digraph { node [shape=box, width=2] 0 [label="new", target="_top"]; 1 [label="loaded"]; 2 [label="converted"]; 3 [label="preprocessed", below=2]; 4 [label="binarized", below=1]; 5 [label="postprocessed", below=0]; 6 [label="features_extracted"]; 7 [label="features_filtered"]; 8 [label="analyzed"]; 9 [label="stored"]; {rank=same; 0 -> 1 [label="read"]; 1 -> 2 [label="convert"]; } 2 -> 3 [label="preprocess"]; {rank=same; 4 -> 3 [label="binarize", dir="back"]; 5 -> 4 [label="postprocess", dir="back"]; } 5 -> 6 [label="extract_features"]; {rank=same; 6 -> 7 [label="filter_features"]; 7 -> 8 [label="analyze"]; } 8 -> 9 [label="store"]; }

With every step, information is collected. A spim at a later stage does not duplicate the image data from former stages. However, if this data is still needed, it can contain a reference to its predecessors.

The processes

The detection of features within an image with spotlob is split up into an abstract but fixed sequence of processes. Any of these process steps is applied onto a Spim and returns a new Spim. The new Spim contains the information added by the process step.

digraph seq { rankdir="LR"; "spim1" -> "spim2" [label="spim1.function(process)"]; }

For example, a Spim at stage SpimStage.loaded can be converted, using a concrete subclass of Converter, named process_opencv.GreyscaleConverter in the following way:

from spotlob.defaults import load_image
from spotlob.process_opencv import GreyscaleConverter

loaded_spim = load_image("color_image.jpg")
my_converter = GreyscaleConverter()
converted_spim = loaded_spim.convert(my_converter)

Any process step corresponds to one input stage and one method of Spim to use it with

input stage Spim method SpotlobProcessStep subclass
new read Reader
loaded convert Converter
converted preprocess Preprocessor
preprocessed binarize Binarization
binarized postprocess Postprocessor
postprocessed extract_features FeatureExtractor
features_extracted filter_features FeatureFilter
features_filtered analyze Analysis
analyzed store Writer
stored    

For every function of Spim that returns another Spim at a further stage, there is a subclass of SpotlobProcessStep, that can be used as super class for an concrete implementation of that step. The return type of a SpotlobProcessStep.apply call is different depending on the type of process. The Spim internally passes the modified data to the new Spim created through the process.

class spotlob.process_steps.Reader(function, parameters, add_to_register=True)[source]

A reader loads the image data from storage into memory. apply returns an image

class spotlob.process_steps.Converter(function, parameters, add_to_register=True)[source]

A converter converts a color image to a greyscale image. apply returns a greyscale image

class spotlob.process_steps.Preprocessor(function, parameters, add_to_register=True)[source]

Preprocessing is applied onto a grey image to prepare for binarization, for example by cleaning the image from unwanted features. apply returns a greyscale image

class spotlob.process_steps.Binarization(function, parameters, add_to_register=True)[source]

Turns a greyscale image into a black-and-white or binary image. apply returns a greyscale image

class spotlob.process_steps.Postprocessor(function, parameters, add_to_register=True)[source]

Postprocessing is done on a binary image to facilitate the detection. apply returns a greyscale image

class spotlob.process_steps.FeatureFinder(function, parameters, add_to_register=True)[source]

The FeatureFinder tries to find contours in a binary image.

apply returns contours

class spotlob.process_steps.FeatureFilter(function, parameters, add_to_register=True)[source]

The FeatureFilter can reduce the number of detected features by analyzing them.

apply returns contours

class spotlob.process_steps.Analysis(function, parameters, add_to_register=True, extended_output=True)[source]

An Analysis class evaluates the metadata (including contours) and yields its results as a dataframe.

apply returns DataFrame

The spotlob pipeline

The pipeline structure is used to define a sequence of processes to be applied one after another onto a spim, to automate a detection task consisting of multiple process steps.

class spotlob.pipeline.Pipeline(processes)[source]

A pipeline is a sequence of processes, that can be applied one after another. The processes are stored in a Dictionary, along with the SpimStage at which they can be applied. The pipeline can be applied completely using the apply_all_steps method or partially using the apply_from_stage_to_stage method.