Preprocessing

particletracker.preprocess.preprocessing_methods.absolute_diff(frame, parameters=None, call_num=None)

Calculates the absolute difference of pixels from a reference value

Notes

This function returns the magnitude of the difference in intensity of a pixel relative to a specified value. This is often useful in brightfield microscopy if you have objects slightly above and below the focal plane as one set will look darker than the background and the other set will look brighted than the background.

value

The value to take the absolute difference relative to

normalise

Stretch the intensity values to the full range 0-255, True or False

Parameters
  • frame – This is must be a grayscale / single colour channel image

  • parameters – Nested dictionary like object (same as .param files or output from general.param_file_creator.py

  • call_num – Usually None but if multiple calls are made modifies method name with get_method_key

Return type

grayscale image

particletracker.preprocess.preprocessing_methods.adaptive_threshold(frame, parameters=None, call_num=None)

Perform an adaptive threshold on a grayscale image

Notes

This applies OpenCVs adaptive threshold. This differs from global threshold in that for each pixel the cutoff threshold is defined based on a block of local pixels around it. This enables you to cope with gradual changes in illumination across the image etc.

block_size

Size of local block of pixels to calculate threshold on

C

The mean-c value see here: http://homepages.inf.ed.ac.uk/rbf/HIPR2/adpthrsh.htm

ad_mode

Inverts behaviour (True or False)

Parameters
  • frame – This is must be a grayscale / single colour channel image

  • parameters – Nested dictionary like object (same as .param files or output from general.param_file_creator.py

  • call_num – Usually None but if multiple calls are made modifies method name with get_method_key

Return type

binary image with 255 above threshold else 0.

particletracker.preprocess.preprocessing_methods.blur(frame, parameters=None, call_num=None)

Performs a gaussian blur on the image

Notes

This applies OpenCVs gaussian blur to the image (https://en.wikipedia.org/wiki/Gaussian_blur) Usually useful to apply before subtracting 2 images.

blur_kernel

single integer n specifying the size of kernel (n,n)

Parameters
  • frame – This must be a grayscale / single colour channel image

  • parameters – Nested dictionary like object (same as .param files or output from general.param_file_creator.py

  • call_num – Usually None but if multiple calls are made modifies method name with get_method_key

Return type

single colour channel image.

particletracker.preprocess.preprocessing_methods.colour_channel(frame, parameters=None, call_num=None)

This selects the specified colour channel of a colour image

colour

options are ‘red’, ‘green’, ‘blue’, We assume frame has (blue, green, red) format which is OpenCVs default.

Parameters
  • frame – This must be a colour / single colour channel image

  • parameters – Nested dictionary like object (same as .param files or output from general.param_file_creator.py

  • call_num – Usually None but if multiple calls are made modifies method name with get_method_key

Return type

Single colour channel image

particletracker.preprocess.preprocessing_methods.dilation(frame, parameters=None, call_num=None)

Dilate a binary image

This performs a dilation operation on a binary image. Dilation adds pixels to the edge of white regions according to the kernel and is useful for closing small holes or gaps. See an explanation - https://en.wikipedia.org/wiki/Dilation_(morphology)

dilation_kernel

single integer n specifying dimension of kernel (n,n)

iterations

how many times to apply the operation

Parameters
  • frame – This must be a binary image (8 bit)

  • parameters – Nested dictionary like object (same as .param files or output from general.param_file_creator.py

  • call_num – Usually None but if multiple calls are made modifies method name with get_method_key

Return type

binary image

particletracker.preprocess.preprocessing_methods.distance(frame, parameters=None, call_num=None)

Perform a distance transform on a binary image

Notes

Implements the opencv distance transform. This transform operates on a binary image. For each chosen white pixel it calculates the distance to the nearest black pixel. This distance is the value of the chosen pixel. Thus if operating on a white circle the distance transform is a maximum at the middle and 1 at the perimeter.

See here for explanation : https://en.wikipedia.org/wiki/Distance_transform

Parameters
  • frame – This must be a binary image (8 bit)

  • parameters – Nested dictionary like object (same as .param files or output from general.param_file_creator.py

  • call_num – Usually None but if multiple calls are made modifies method name with get_method_key

Return type

Grayscale image

particletracker.preprocess.preprocessing_methods.erosion(frame, parameters=None, call_num=None)

Perform an erosion operation on a binary image

Notes

This performs an erosion operation on a binary image. This means pixels are set to zero based on their connectivity with neighbours Useful for separating objects and removing small pepper noise.

See an explanation - https://en.wikipedia.org/wiki/Erosion_(morphology)

Parameters:

erosion_kernel : single integer n specifying dimension of kernel (n,n) iterations : how many times to apply the operation

Parameters
  • frame – This must be a binary image (8 bit)

  • parameters – Nested dictionary like object (same as .param files or output from general.param_file_creator.py

  • call_num – Usually None but if multiple calls are made modifies method name with get_method_key

Return type

binary image with 255 above threshold else 0.

particletracker.preprocess.preprocessing_methods.fill_holes(frame, parameters=None, call_num=None)

Fills holes in a binary image.

Notes

This function uses a combination of flood fills to fill in enclosed holes in objects in a binary image.

Parameters
  • frame – This is must be a binary image

  • parameters – Nested dictionary like object (same as .param files or output from general.param_file_creator.py

  • call_num – Usually None but if multiple calls are made modifies method name with get_method_key

Return type

binary image

particletracker.preprocess.preprocessing_methods.gamma(image, parameters=None, call_num=None)

Apply look up table to image with power gamma

Notes

This generates a lookup table which maps the values 0-255 to 0-255 however not in a linear way. The mapping follows a power law with exponent gamma/100.0.

gamma

single float can be positive or negative. The true value applied is the displayed value / 100.

Parameters
  • frame – This is must be a grayscale / single colour channel image

  • parameters – Nested dictionary like object (same as .param files or output from general.param_file_creator.py

  • call_num – Usually None but if multiple calls are made modifies method name with get_method_key

Return type

grayscale image

particletracker.preprocess.preprocessing_methods.grayscale(frame, parameters=None, call_num=None)

This converts a colour image to a grayscale image

Parameters
  • frame – This should be a colour image though won’t error if given grayscale

  • parameters – Nested dictionary like object (same as .param files or output from general.param_file_creator.py

  • call_num – Usually None but if multiple calls are made modifies method name with get_method_key

Return type

grayscale image

particletracker.preprocess.preprocessing_methods.invert(frame, parameters=None, call_num=None)

Invert image

Notes

This inverts the supplied image. It will work with any kind of image (colour, grayscale, binary). The result for an 8bit image at each pixel is just 255 - currentvalue.

Parameters
  • frame – will receive any type of image

  • parameters – Nested dictionary like object (same as .param files or output from general.param_file_creator.py

  • call_num – Usually None but if multiple calls are made modifies method name with get_method_key

Return type

same as input image

particletracker.preprocess.preprocessing_methods.medianblur(frame, parameters=None, call_num=None)

Performs a medianblur on the image.

Notes

Setting each pixel to median value in the area specified by the kernel.

kernel

An integer value n that specifies kernel shape (n,n)

Parameters
  • frame – This is must be a grayscale / single colour channel image

  • parameters – Nested dictionary like object (same as .param files or output from general.param_file_creator.py

  • call_num – Usually None but if multiple calls are made modifies method name with get_method_key

Return type

grayscale image

particletracker.preprocess.preprocessing_methods.subtract_bkg(frame, parameters=None, call_num=None)

Subtract a background

Notes

This function will subtract a background from the image. It has several options: mean will subtract the average value from the image. img will subtract a preprepared background img from the img. Before subtracting the background image it is blurred according to the settings.

N.B. You must apply either a grayscale or color_channel method before the subtract_bkg method. The software subtracts the mean image value, grayscale or color_channel version of the background image which you select from the current image.

subtract_bkg_type

Type of background substraction to be performed. Options are are ‘mean’ or ‘grayscale’,’red’,’green’,’blue’.

subtract_bkg_filename

filename of background image. If None it will look for a file named moviefilename_bkgimg.png. Otherwise it looks for the filename specified. The filename is assumed to be in the same directory as the movie. Alternatively specify the full path to the file.

subtract_bkg_blur_kernel

An integer n specifying the kernel size (n,n) to be used in blurring bkg image

subtract_bkg_invert

Subtract bkg from image or image from background.

subtract_bkg_norm

Stretch range of outputted intensities on resultant image to fill 0-255 - True or False

Parameters
  • frame – This must be a grayscale / single colour channel image

  • parameters – Nested dictionary like object (same as .param files or output from general.param_file_creator.py

  • call_num – Usually None but if multiple calls are made modifies method name with get_method_key

Return type

grayscale image

particletracker.preprocess.preprocessing_methods.threshold(frame, parameters=None, call_num=None)

Apply a global threshold

This applies OpenCVs threshold. This sets pixels to 255 or 0 depending on whether they are above or below the given value.

threshold

Threshold value to determine whether pixels are black or white

th_mode

True or False to specify whether above threshold is white or black.

Parameters
  • frame – This is must be a grayscale / single colour channel image

  • parameters – Nested dictionary like object (same as .param files or output from general.param_file_creator.py

  • call_num – Usually None but if multiple calls are made modifies method name with get_method_key

Return type

grayscale image