tmas.preprocessing
Module Contents
- tmas.preprocessing.convert_image_to_colour(image)[source]
Convert a grayscale image to a color image by replicating the grayscale values across the RGB channels.
This function takes a single-channel grayscale image and converts it into a 3-channel color image by assigning the grayscale values to each of the Red, Green, and Blue channels.
- Parameters:
image (numpy.ndarray) – The input grayscale image.
- Returns:
The converted color image with the same height and width as the input image, but with 3 color channels (RGB).
- Return type:
numpy.ndarray
- tmas.preprocessing.convert_image_to_grey(image)[source]
Convert a color image to a grayscale image.
This function takes a color image with three channels (typically in BGR format) and converts it into a single-channel grayscale image.
- Parameters:
image (numpy.ndarray) – The input color image, expected to be in BGR format.
- Returns:
The converted grayscale image.
- Return type:
numpy.ndarray
- tmas.preprocessing.mean_shift_filter(image, spatial_radius=10, colour_radius=10)[source]
Apply a mean shift filter to an image
This function applies a mean shift filter to the input image. If the input image is not already a 3-channel color image, it will first be converted to color. The mean shift filter is then applied using the specified spatial and color radii.
- Parameters:
image (numpy.ndarray) – The input image, which can be either a grayscale or color image.
spatial_radius (int, optional) – The spatial radius of the mean shift filter. Default is 10.
colour_radius (int, optional) – The color radius of the mean shift filter. Default is 10.
- Returns:
The filtered image after applying the mean shift filter.
- Return type:
numpy.ndarray
- tmas.preprocessing.equalise_histograms_locally(image, well_dimensions=(8, 12))[source]
Perform local histogram equalization on an image using CLAHE (Contrast Limited Adaptive Histogram Equalization).
This function applies local histogram equalization to an image to enhance contrast. If the input image is a color image (3 channels), it will first be converted to grayscale.
- Parameters:
image (numpy.ndarray) – The input image, which can be either grayscale or color.
well_dimensions (tuple[int, int], optional) – The dimensions of the grid used for local histogram equalization. Default is (8, 12).
- Returns:
The image after applying local histogram equalization.
- Return type:
numpy.ndarray
- tmas.preprocessing.stretch_histogram(image)[source]
Stretch the histogram of an image by adjusting its pixel intensity values.
This function stretches the histogram of an image by calculating the mode, subtracting it from the image, and then scaling the pixel values based on lower and upper percentiles.
- Parameters:
image (numpy.ndarray) – The input image, typically in grayscale, whose histogram will be stretched.
- Returns:
The image with a stretched histogram, with pixel values adjusted to enhance contrast.
- Return type:
numpy.ndarray
- tmas.preprocessing.preprocess_images(image)[source]
Preprocess an image by applying a series of filtering and histogram adjustment techniques.
This function preprocesses an input image by sequentially applying multiple preprocessing steps:
- Parameters:
image (numpy.ndarray) – The input image, which can be either grayscale or color.
- Returns:
The image after applying preprocessing steps
- Return type:
numpy.ndarray