filtration package

Submodules

filtration.filter module

class filtration.filter.Filter

Bases: abc.ABC

A abstract base class for all Filters

abstract filter(region) bool

details of the behavior of the Filter

class filtration.filter.FilterBlackAndWhite(filter_threshold=0.5, binarization_threshold=0.85, rgb_weights=[0.2989, 0.587, 0.114])

Bases: filtration.filter.Filter

Filters out regions with too much whitespace

convert_rgb_to_greyscale(region)

convert_rgb_to_greyscale Convert an RGB region of image to greyscale

Parameters

region (np.ndarray) – numpy array representing the region, region consists of RGB values

Returns

a numpy array representing the region, region is in greyscale

Return type

np.ndarray

filter(region) bool

filter Perform filtration to a region

Parameters

region (np.ndarray) – numpy array representing the region

Returns

True if the average of the binary region is less than the filter threshold, else False

Return type

bool

class filtration.filter.FilterFocusMeasure(threshold=65.0)

Bases: filtration.filter.Filter

Filters out regions that are sufficiently out-of-focus

filter(region) bool

filter Perform filtration to a region by determining whether it is focused or blurry

Parameters

region (np.ndarray) – numpy array representing the region

Returns

True if the focus measure is greater than the supplied threshold (image is not considered blurry), else False (image is considered blurry)

Return type

bool

variance_of_laplacian(region) float

variance_of_laplacian Computes the Laplacian of the region

Parameters

region (np.ndarray) – numpy array representing the region

Returns

The focus measure which is the variance of the Laplacian

Return type

float

class filtration.filter.FilterHSV(threshold: numbers.Number = 100)

Bases: filtration.filter.Filter

Filters out regions according to average hue

convert_rgb_to_hsv(region) numpy.ndarray

convert_rgb_to_hsv Converts RGB region of image to HSV

Parameters

region (np.ndarray) – numpy array representing the region, region consists of RGB values

Returns

a numpy array representing the region, region consists of HSV values

Return type

np.ndarray

filter(region) bool

filter Perform filtration to a region

Parameters

region (np.ndarray) – numpy array representing the region

Returns

True if the mean of the hues in the hsv region is greather than the threshold, else False

Return type

bool

class filtration.filter.FilterHistolab(tissue_percentage: float = 0.8)

Bases: filtration.filter.Filter

Applies basic tissue filtration from the Histolab PyPi package

filter(region) bool

filter filters regions based on the histolab package’s Tile.has_enough_tissue()

Parameters

region (np.ndarray) – the region to which filtration will be applied

class filtration.filter.FilterRandom(p: numbers.Number = 0.5)

Bases: filtration.filter.Filter

Decides whether a region passes randomly

filter(region) bool

filter filters based on a random number being greater than the set threshold

Parameters

region (np.ndarray) – unused region of an image

Returns

Returns a boolean depending on whether RNG picks a number greater than the set threshold

Return type

bool

filtration.filter_manager module

class filtration.filter_manager.FilterManager(filters: Union[filtration.filter.Filter, str, list])

Bases: object

add_filter(filter: Union[filtration.filter.Filter, str])

add_filter Appends the input filter to the list of filters in state

Parameters

filter (Union[Filter, str]) – Either a Filter subclass or a str representing the filter’s type

Raises
  • Exception – This filter does not exist.

  • TypeError – This is not a filter.

filter(region: numpy.ndarray) bool

filter Filters the region based on the input filters

Parameters

region (np.ndarray) – A region of the image to be filtered.

Returns

True if the region passes all of the filters, and false if not.

Return type

bool