API Reference
add_north_arrow(ax, relative_position=(0.05, 0.05), arrow_length=0.05, text_offset=-0.02)
Add a north arrow to the axis.
Source code in ShallowLearn/ImageHelper.py
apply_mask(data, mask, fill_value=0)
Applies a mask to the data array.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
ndarray
|
The input data array. |
required |
mask
|
ndarray
|
The mask array. |
required |
fill_value
|
float
|
The value to use where the mask is False. |
0
|
Returns:
Type | Description |
---|---|
numpy.ndarray: The masked data array. |
Source code in ShallowLearn/ImageHelper.py
clip_array(arr)
Clips an input multiband array to values between 0 and 10,000, removing any negative values.
Parameters: arr (np.ndarray): A NumPy array of any shape.
Returns: np.ndarray: A clipped NumPy array with the same shape as input, where all values are >= 0 and <= 10,000.
Source code in ShallowLearn/ImageHelper.py
gen_mask(img, mask=9)
Generates a mask for the input image based on the predicted mask.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
img
|
ndarray
|
The input image array. |
required |
mask
|
int
|
The mask value to consider. Default is 9. |
9
|
Returns:
Type | Description |
---|---|
numpy.ndarray: The mask array. |
Source code in ShallowLearn/ImageHelper.py
generate_multichannel_mask(img, mask=None, mask_val=9)
Generates a multichannel mask for the input image based on the predicted mask. Can also be used to generate a multichannel mask for a given mask.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
img
|
ndarray
|
The input image array. |
required |
mask
|
int
|
The mask value to consider. Default is 9. |
None
|
Returns:
Type | Description |
---|---|
numpy.ndarray: The multichannel mask array. |
Source code in ShallowLearn/ImageHelper.py
load_img(path, return_meta=False, clip=True)
Loads an image from the specified path.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path
|
str
|
The path to the image file. |
required |
Returns:
Type | Description |
---|---|
numpy.ndarray: The loaded image array. |
Source code in ShallowLearn/ImageHelper.py
median_without_zeros_or_nans(images)
Computes the median of each band in each image, excluding zeros and NaN values.
- images: numpy array, shape (i, x, y, z) The input 4D array of images.
- medians: numpy array, shape (i, z) The median values for each band in each image, excluding zeros and NaNs.
Source code in ShallowLearn/ImageHelper.py
plot_geotiff(image_data, bounds, title='Map with coordinates', ax=None)
Plot GeoTIFF with UTM Coordinates and a scale bar.
Parameters: - image_data: 2D or 3D array containing the raster data - bounds: Tuple containing the bounding coordinates (left, right, bottom, top)
Source code in ShallowLearn/ImageHelper.py
plot_histogram(img, plot=True, bins=50, min_value=1, title=None)
Plots histogram for a specific channel in the input image.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
img
|
ndarray
|
The input image array. |
required |
channel
|
int
|
The index of the channel to be plotted. Default is 0. |
required |
plot
|
bool
|
Flag to indicate whether to plot the histogram or not. Default is True. |
True
|
bins
|
int
|
The number of bins for the histogram. Default is 50. |
50
|
min_value
|
int
|
The minimum value to consider for the histogram. Values below this threshold will be removed. Default is 1. |
1
|
title
|
str
|
Title of the plot. Default is None. |
None
|
Returns:
Type | Description |
---|---|
None |
Source code in ShallowLearn/ImageHelper.py
plot_histograms(img, plot=True, bins=50, min_value=1, channel_legend=None, title=None, return_fig=False)
Plots histograms for each channel in the input image using line plots.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
img
|
ndarray
|
The input image array. |
required |
plot
|
bool
|
Flag to indicate whether to plot the histograms or not. Default is True. |
True
|
bins
|
int
|
The number of bins for the histograms. Default is 50. |
50
|
min_value
|
int
|
The minimum value to consider for the histograms. Values below this threshold will be removed. Default is 1. |
1
|
channel_legend
|
dict
|
Dictionary for channel legend. Keys are channel indices and values are channel names. Default is None. |
None
|
Returns:
Type | Description |
---|---|
None |
Source code in ShallowLearn/ImageHelper.py
plot_hsv(img, plot=False)
Converts the input image to the HSV color space and optionally plots the H channel.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
img
|
ndarray
|
The input image array. |
required |
plot
|
bool
|
Flag to indicate whether to plot the H channel or not. Default is False. |
False
|
Returns:
Type | Description |
---|---|
numpy.ndarray or None: The hsv array if plot=False, otherwise None. |
Source code in ShallowLearn/ImageHelper.py
plot_lab(img, plot=False)
Converts the input image to the LAB color space and optionally plots the L channel.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
img
|
ndarray
|
The input image array. |
required |
plot
|
bool
|
Flag to indicate whether to plot the L channel or not. Default is False. |
False
|
Returns:
Type | Description |
---|---|
numpy.ndarray or None: The lab array if plot=False, otherwise None. |
Source code in ShallowLearn/ImageHelper.py
plot_rgb(img, bands=None, plot=False)
Plots the RGB image using the specified bands.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
img
|
ndarray
|
The input image array. |
required |
bands
|
list
|
The list of band codes to use for the RGB channels. Default is ['B04', 'B03', 'B02']. |
None
|
plot
|
bool
|
Whether to display the image plot using matplotlib. Default is False. |
False
|
Returns:
Type | Description |
---|---|
numpy array with selected bands: The RGB image array if plot is set to False. |
Source code in ShallowLearn/ImageHelper.py
plot_with_legend(array, value_dict)
Plots a 2D array with a legend using distinct colors for discrete class labels.
Parameters: array (2D numpy array): The array to be plotted. value_dict (dict): A dictionary mapping values in the array to labels.
Source code in ShallowLearn/ImageHelper.py
plot_ycbcr(img, plot=False)
Converts the input image to the YCbCr color space and optionally plots the Y channel.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
img
|
ndarray
|
The input image array. |
required |
plot
|
bool
|
Flag to indicate whether to plot the Y channel or not. Default is False. |
False
|
Returns:
Type | Description |
---|---|
numpy.ndarray or None: The ycbcr array if plot=False, otherwise None. |
Source code in ShallowLearn/ImageHelper.py
predict_mask(img, model=None, mask_val=None, estimator=None)
Predicts the mask for the input image using a pre-trained model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
img
|
ndarray
|
The input image array. |
required |
model
|
str
|
The path to the pre-trained model. Default is None and uses all 13 bands. |
None
|
mask_val
|
int
|
The mask value to consider. Default is 9. |
None
|
Returns:
Type | Description |
---|---|
numpy.ndarray: The predicted mask for the image. |
Source code in ShallowLearn/ImageHelper.py
remove_channel(img, channel)
Removes a specified channel from a 3D image array.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
img
|
ndarray
|
The 3D image array with shape (height, width, channels). |
required |
channel
|
int
|
The index of the channel to remove. |
required |
Returns:
Type | Description |
---|---|
numpy.ndarray: The image array with the specified channel removed. |
Raises:
Type | Description |
---|---|
ValueError
|
If the channel index is out of bounds. |
Source code in ShallowLearn/ImageHelper.py
select_channels(arr, indices)
Selects specific channels based on the given indices from a 3D numpy array.
:param arr: A numpy array of shape (x, y, z). :param indices: A list or array-like containing the indices of channels to be selected. Its length must be 3 or it will raise a ValueError. :return: A numpy array of shape (x, y, 3).
Source code in ShallowLearn/ImageHelper.py
add_nan_buffer(arr, dilation_size=3)
Adds a buffer around NaN values in the given array using morphological dilation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
arr
|
ndarray
|
The input array. |
required |
dilation_size
|
int
|
Size of the dilation structure. This controls the thickness of the NaN buffer. |
3
|
Returns:
Type | Description |
---|---|
np.ndarray: The modified array with a buffer around NaN values. |
Source code in ShallowLearn/CloudDetector.py
detect_clouds(datacube, threshold=0.0, window_size=8)
Detects clouds in a time series of images by comparing each pixel to the mean of the surrounding window.
Parameters: - datacube: 4D numpy array (time, x, y, channels) - window_size: number of images in the sliding window
Returns: - cloud_mask: 4D boolean numpy array (time, x, y, channels) indicating cloud presence for each image
Source code in ShallowLearn/CloudDetector.py
color_histogram(image, bins=32)
Computes the color histogram for each channel in the image.
Purpose: Color histograms represent the distribution of colors in an image and can be used for color-based image analysis.
- image: numpy array, shape (height, width, num_channels) The input image array.
- bins: int, optional Number of bins for the histogram (default is 32).
- hist: numpy array, shape (num_channels, bins) The computed color histograms for each channel.
Source code in ShallowLearn/ComputerVisionFeatures.py
edge_density(image)
Computes the edge density using the Canny Edge Detector.
Purpose: Edge density can be used to quantify the amount of texture or detail in an image, which can be useful in various image processing tasks.
- image: numpy array, shape (height, width, num_channels) The input image array.
- edge_density_map: numpy array, shape (height, width) The computed edge density.
Source code in ShallowLearn/ComputerVisionFeatures.py
gabor_features(image, frequency=0.6)
Applies Gabor filter to an image.
- image: numpy array, shape (height, width, num_channels) The input image array.
- frequency: float The frequency of the sinusoidal function.
- gabor_response: numpy array, shape (height, width) The filtered image.
Source code in ShallowLearn/ComputerVisionFeatures.py
histogram_of_oriented_gradients(image, pixels_per_cell=(16, 16), cells_per_block=(4, 4), orientations=9)
Computes the Histogram of Oriented Gradients (HOG) feature descriptor.
- image: numpy array, shape (height, width, num_channels) The input image array.
- pixels_per_cell: tuple of int Size (in pixels) of a cell.
- cells_per_block: tuple of int Number of cells in each block.
- orientations: int Number of orientation bins.
- hog_features: numpy array The HOG feature descriptor for the image.
Source code in ShallowLearn/ComputerVisionFeatures.py
sobel_edge_detection(image)
Applies Sobel edge detection to an image.
- image: numpy array, shape (height, width, num_channels) The input image array.
- edge_image: numpy array, shape (height, width) The edge-detected image.
Source code in ShallowLearn/ComputerVisionFeatures.py
texture_features(image, P=8, R=1)
Computes texture features using Local Binary Pattern (LBP).
Purpose: LBP is a powerful texture descriptor and can be used for texture classification.
- image: numpy array, shape (height, width, num_channels) The input image array.
- P: int, optional Number of circularly symmetric neighbor set points (default is 8).
- R: int, optional Radius of circle (default is 1).
- lbp_texture: numpy array, shape (height, width) The computed texture features using LBP.
Source code in ShallowLearn/ComputerVisionFeatures.py
extract_point_spectra(array, x, y)
Extracts the spectra of a single point (x, y) across all time slices.
Parameters: - array: numpy array of shape (t, x, y, z) - x: x-coordinate of the point - y: y-coordinate of the point
Returns: - spectra: numpy array of shape (t, z)
Source code in ShallowLearn/PointExtraction.py
BCET(image, min_value=0, max_value=255, desired_mean=110)
Applies a Bias Correction and Enhancement Technique (BCET) to an image.
This technique stretches the image data with a parabolic function, which transforms the pixel intensity values to a specified range (default: 0 to 255) with a specified mean (default: 110).
Parameters: - image: The input image as a numpy array. - min_value: The minimum pixel intensity value in the output image. - max_value: The maximum pixel intensity value in the output image. - desired_mean: The mean pixel intensity value for the output image.
Returns: - The transformed image as a numpy array with dtype 'int'.
Source code in ShallowLearn/Transform.py
BCET_multi(image, min_value=0, max_value=255, desired_mean=110)
Applies BCET to each channel of a multi-channel image separately.
Source code in ShallowLearn/Transform.py
LCE_multi(image)
Applies linear contrast enhancement to each channel of a multi-channel image separately.
Source code in ShallowLearn/Transform.py
hsi_to_rgb(array)
Convert an array of HSI (Hue, Saturation, Intensity) values to an array of RGB values.
Source code in ShallowLearn/Transform.py
linear_contrast_enhancement(image, max_value=255)
Applies a Linear Contrast Enhancement (LCE) to an image.
This technique linearly rescales the image pixel intensity values to the full range of possible values (0-255).
Parameters: - image: The input image as a numpy array.
Returns: - The rescaled image as a numpy array.
Raises: - ValueError: If all valid pixel values in the image are the same.
Source code in ShallowLearn/Transform.py
transform_hsv_stretch(array, max_value=100)
Transform an Image into HSV space and stretch the contrast of the S channel.
Source code in ShallowLearn/Transform.py
transform_lab_stretch(array)
Transform an Image into LAB space and stretch the contrast of the L channel.
Source code in ShallowLearn/Transform.py
transform_multiband_hsv(arr, bands=None, max_value=100, mask=None)
Reindex the bands of a multiband image to match the order of the HSV color space. Input is a multiband array If bands is None, the default is [3,2,1] - where 3 is the Red band, 2 is the Green band, and 1 is the Blue band.
Source code in ShallowLearn/Transform.py
transform_multiband_lab(arr, bands=None)
Reindex the bands of a multiband image to match the order of the LAB color space. Input is a multiband array If bands is None, the default is [3,2,1] - where 3 is the Red band, 2 is the Green band, and 1 is the Blue band.
Source code in ShallowLearn/Transform.py
histogram_matching(source_img, reference_img)
Match the histogram of the source_img to the histogram of the reference_img.
Source code in ShallowLearn/RadiometricNormalisation.py
histogram_matching_with_plot(source_img, reference_img)
Match the histogram of the source_img to the histogram of the reference_img. Returns the matched image.
Source code in ShallowLearn/RadiometricNormalisation.py
pca_based_normalization(source_img, reference_img)
Radiometric normalization of a source image based on a reference image using PCA. The function takes in two numpy arrays (source_img and reference_img) and returns the normalized source image.
Source code in ShallowLearn/RadiometricNormalisation.py
pca_based_normalization_with_points(source_img, reference_img)
Radiometric normalization of a source image based on a reference image using PCA. Returns the normalized source image and an array marking the points used for PCA.
Source code in ShallowLearn/RadiometricNormalisation.py
pca_filter_and_normalize(source_img, reference_img, threshold=1.0)
Radiometric normalization based on a reference image using PCA, but only for the pixels that are close to the major principal component.
- source_img : numpy array Source image to be normalized.
- reference_img : numpy array Reference image.
- threshold : float (optional) Threshold for filtering pixels based on their position relative to the major principal component. Default is 1.0.
Returns: - numpy array : Normalized source image.
Source code in ShallowLearn/RadiometricNormalisation.py
pca_filter_and_normalize_b8(source_img, reference_img, band_8, threshold=1.0)
Radiometric normalization based on a reference image using PCA, but only for the pixels that are close to the major principal component.
- source_img : numpy array Source image to be normalized.
- reference_img : numpy array Reference image.
- threshold : float (optional) Threshold for filtering pixels based on their position relative to the major principal component. Default is 1.0.
Returns: - numpy array : Normalized source image.
Source code in ShallowLearn/RadiometricNormalisation.py
remove_zeros_from_pair(source_band, reference_band)
Masks zeros from source_band and reference_band. Returns arrays without zero values.
Source code in ShallowLearn/RadiometricNormalisation.py
QuickLookArea
Bases: QuickLookModel
Source code in ShallowLearn/QuickLook.py
287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 |
|
filter_dataframe_by_file_path(df, valid_file_paths)
Drops rows from a DataFrame based on values in the 'FILE_PATH' column that are not present in the provided list of valid file paths.
Parameters: - df: The DataFrame to filter. - valid_file_paths: A list of valid file paths. Rows with 'FILE_PATH' not in this list will be dropped.
Returns: - A filtered DataFrame with only rows that have 'FILE_PATH' values in the valid_file_paths list.
Source code in ShallowLearn/QuickLook.py
QuickLookModel
Abstract base class implementation do not use
Source code in ShallowLearn/QuickLook.py
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 |
|
create_custom_pastel_cmap(labels)
Create a custom colormap using a pastel theme for the given labels.
Parameters: - labels: array-like of unique labels
Returns: - custom_cmap: ListedColormap with tab20c colors
Source code in ShallowLearn/QuickLook.py
plot_images_on_pca(transformed_data, original_images, zoom=0.1, figsize=(10, 10), title='Visualization of Transformed Imagery')
Plots images on their respective PCA-transformed coordinates.
Parameters: - transformed_data: numpy array of shape (n_samples, 2) containing PCA-transformed coordinates. - original_images: numpy array of shape (n_samples, height, width, 3) containing the original images. - zoom: float, the zoom level of the images on the plot. - figsize: tuple, the size of the figure.
Source code in ShallowLearn/QuickLook.py
clip_image(image, clip_percent=1)
Apply a 2% clip on either side of the pixel value distribution for a single image.
Parameters: - image: numpy array representing the image - clip_percent: percentage to clip on each side of the pixel value distribution (default is 2%)
Returns: - clipped_image: numpy array with clipped pixel values
Source code in ShallowLearn/Util.py
convert_data_types(df)
Convert columns in a DataFrame from string to the most appropriate datatype (numeric, datetime, or string) by checking if the content fits known date formats, then checking for numeric values, and defaulting to string if neither fits. Also, consolidates columns with 'FLAG' in their name with corresponding columns without 'FLAG'.
:param df: pandas DataFrame with all columns as strings :return: DataFrame with converted datatypes
Source code in ShallowLearn/Util.py
plot_cloud_coverage_over_time(df)
Plot cloud coverage assessment over time.
:param df: DataFrame containing the cloud coverage and date of data take.
Source code in ShallowLearn/Util.py
plot_cloud_coverage_over_time_with_baseline(df)
Plot cloud coverage over time, color-coded by processing baseline.
:param df: DataFrame containing the cloud coverage, date of data take, and processing baseline.
Source code in ShallowLearn/Util.py
plot_images_on_scatter(transformed_data, imagery, image_fraction=0.11, title='Images on scatter')
Plots images on a scatter plot at specified coordinates.
Parameters: - transformed_data: np.array, an array of coordinates (shape [n, 2]). - imagery: list, a list of images in ndarray format. - image_fraction: float, the fraction of the plot range to determine the size of the images.
Source code in ShallowLearn/Util.py
plot_images_with_info(all_images, band_order=[0, 1, 2])
Plots 10 random images and their coordinates info on subplots from a larger list of images.
- all_images: list of lists, where each inner list contains [image_data, x, y, z] image_data is an ndarray representing the image, x and y are coordinates, and z is the number of channels.
Source code in ShallowLearn/Util.py
plot_quality_over_time(df)
Plot various quality flags over time using a 4-axis subplot.
:param df: DataFrame containing the quality flags and date of data take.
Source code in ShallowLearn/Util.py
plot_quality_over_time_side_by_side(df)
Plot various quality flags over time using side-by-side subplots, enhanced for publication quality.
:param df: DataFrame containing the quality flags and date of data take.