ImageUtils#

class astropathdb.shared.utils.image.ImageUtils#

basic image utilities class.

ImageUtils Methods#

imsize_filter(im[, size])

Perform a size filter on an image.

structuring_element([element_size_1, element_size_2])

Get a cv structuring ellipse element.

get_ellipse_kernel([kernel, element_size_1, ...])

Get an ellipse kernel, useful for optionally providing a kernel to other functions.

imdilate(image[, kernel, element_size_1, element_size_2])

Performs a dilate operation on an image.

imerode(image[, kernel, element_size_1, element_size_2])

Performs an erode operation on an image.

imopen(image[, kernel, element_size_1, element_size_2])

Performs an open operation on an image, an erosion followed by a dilation.

imclose(image[, kernel, element_size_1, element_size_2])

Performs a close operation on an image, a dilation followed by an erosion.

im_grouped_noise_reduction(mask[, params])

Performing some basic image noise reduction techniques.

imthreshold_max(image, threshold)

Return an image thresholded by a value of 0 to 1 relative to the max.

imthreshold_median(image, threshold)

Return an image thresholded by a value relative to the median.

imthreshold_image(image, threshold)

Return an image thresholded by a value relative to the image itself.

immask(image)

Convert an image to a mask, where image is > 0.

threshold_mask(image[, threshold, threshold_method])

Build a threholded mask from an image.

ImageUtils References#

Method Reference#

static imsize_filter(im, size=500)#

Perform a size filter on an image.

https://www.geeksforgeeks.org/python-opencv-connected-component-labeling-and-analysis/.

Parameters:
  • im (ndarray) – the image

  • size (int) – the minimum size of objects allowed

Return type:

ndarray

static structuring_element(element_size_1=9, element_size_2=None)#

Get a cv structuring ellipse element.

Parameters:
  • element_size_1 (int) – the first dimension for the kernel

  • element_size_2 (int | None) – the second dimension for the kernel

Return type:

ndarray

method get_ellipse_kernel(kernel=None, element_size_1=None, element_size_2=None)#

Get an ellipse kernel, useful for optionally providing a kernel to other functions.

Parameters:
  • kernel (ndarray | None) – if provided returns the kernel

  • element_size_1 (int | None) – the first dimension for the kernel

  • element_size_2 (int | None) – the second dimension for the kernel

Return type:

ndarray

method imdilate(image, kernel=None, element_size_1=None, element_size_2=None)#

Performs a dilate operation on an image.

Parameters:
  • image (ndarray) – the image to dilate

  • kernel (ndarray | None) – if provided dilates using the kernel

  • element_size_1 (int | None) – the first dimension for the kernel

  • element_size_2 (int | None) – the second dimension for the kernel

Return type:

ndarray

method imerode(image, kernel=None, element_size_1=None, element_size_2=None)#

Performs an erode operation on an image.

Parameters:
  • image (ndarray) – the image to erode

  • kernel (ndarray | None) – if provided dilates using the kernel

  • element_size_1 (int | None) – the first dimension for the kernel

  • element_size_2 (int | None) – the second dimension for the kernel

Return type:

ndarray

method imopen(image, kernel=None, element_size_1=None, element_size_2=None)#

Performs an open operation on an image, an erosion followed by a dilation.

Parameters:
  • image (ndarray) – the image to open

  • kernel (ndarray | None) – if provided dilates using the kernel

  • element_size_1 (int | None) – the first dimension for the kernel

  • element_size_2 (int | None) – the second dimension for the kernel

Return type:

ndarray

method imclose(image, kernel=None, element_size_1=None, element_size_2=None)#

Performs a close operation on an image, a dilation followed by an erosion.

Parameters:
  • image (ndarray) – the image to open

  • kernel (ndarray | None) – if provided dilates using the kernel

  • element_size_1 (int | None) – the first dimension for the kernel

  • element_size_2 (int | None) – the second dimension for the kernel

Return type:

ndarray

method im_grouped_noise_reduction(mask, params=ImageOperationParams, **_)#

Performing some basic image noise reduction techniques.

Use a value of None to skip an operation, the operation order is dilate (9), erode (9), open (None), close (None) – defaults in parens.

Parameters:
Return type:

ndarray

static imthreshold_max(image, threshold)#

Return an image thresholded by a value of 0 to 1 relative to the max.

Parameters:
  • image (ndarray) – the image

  • threshold (float) – the threshold to use of 0 to 1 (relative to the max)

Return type:

ndarray

static imthreshold_median(image, threshold)#

Return an image thresholded by a value relative to the median.

Parameters:
  • image (ndarray) – the image

  • threshold (float) – the threshold to use

Return type:

ndarray

static imthreshold_image(image, threshold)#

Return an image thresholded by a value relative to the image itself.

Parameters:
  • image (ndarray) – the image

  • threshold (float) – the threshold to use

Return type:

ndarray

static immask(image)#

Convert an image to a mask, where image is > 0.

Parameters:

image (ndarray) – the image

Return type:

ndarray

method threshold_mask(image, threshold=0.2, threshold_method='max', **_)#

Build a threholded mask from an image.

Parameters:
  • image (ndarray) – the image to threshold

  • threshold (float) – the threshold to use

  • threshold_method (str) – should the threshold be relative to the ‘max’, ‘median’, or the ‘image’

Return type:

ndarray