mapchete_eo.image_operations package
Submodules
mapchete_eo.image_operations.blend_functions module
Original LICENSE:
MIT License
Copyright (c) 2016 Florian Roscheck
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation th rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- mapchete_eo.image_operations.blend_functions.addition(fg: ndarray, bg: ndarray, opacity: float)[source]
Apply addition blending mode of a layer on an image.
See also
Find more information on Wikipedia.
- Parameters:
fg (3-dimensional numpy array of floats (r/g/b/a) in range 0-255.0) – Image to be blended upon
bg (3-dimensional numpy array of floats (r/g/b/a) in range 0.0-255.0) – Layer to be blended with image
opacity (float) – Desired opacity of layer for blending
disable_type_checks (bool) – Whether type checks within the function should be disabled. Disabling the checks may yield a slight performance improvement, but comes at the cost of user experience. If you are certain that you are passing in the right arguments, you may set this argument to ‘True’. Defaults to ‘False’.
- Returns:
Blended image
- Return type:
3-dimensional numpy array of floats (r/g/b/a) in range 0.0-255.0
- mapchete_eo.image_operations.blend_functions.darken_only(fg: ndarray, bg: ndarray, opacity: float)[source]
Apply darken only blending mode of a layer on an image.
See also
Find more information on Wikipedia.
- Parameters:
fg (3-dimensional numpy array of floats (r/g/b/a) in range 0-255.0) – Image to be blended upon
bg (3-dimensional numpy array of floats (r/g/b/a) in range 0.0-255.0) – Layer to be blended with image
opacity (float) – Desired opacity of layer for blending
disable_type_checks (bool) – Whether type checks within the function should be disabled. Disabling the checks may yield a slight performance improvement, but comes at the cost of user experience. If you are certain that you are passing in the right arguments, you may set this argument to ‘True’. Defaults to ‘False’.
- Returns:
Blended image
- Return type:
3-dimensional numpy array of floats (r/g/b/a) in range 0.0-255.0
- mapchete_eo.image_operations.blend_functions.difference(fg: ndarray, bg: ndarray, opacity: float)[source]
Apply difference blending mode of a layer on an image.
See also
Find more information on Wikipedia.
- Parameters:
fg (3-dimensional numpy array of floats (r/g/b/a) in range 0-255.0) – Image to be blended upon
bg (3-dimensional numpy array of floats (r/g/b/a) in range 0.0-255.0) – Layer to be blended with image
opacity (float) – Desired opacity of layer for blending
disable_type_checks (bool) – Whether type checks within the function should be disabled. Disabling the checks may yield a slight performance improvement, but comes at the cost of user experience. If you are certain that you are passing in the right arguments, you may set this argument to ‘True’. Defaults to ‘False’.
- Returns:
Blended image
- Return type:
3-dimensional numpy array of floats (r/g/b/a) in range 0.0-255.0
- mapchete_eo.image_operations.blend_functions.divide(fg: ndarray, bg: ndarray, opacity: float)[source]
Apply divide blending mode of a layer on an image.
See also
Find more information on Wikipedia.
- Parameters:
fg (3-dimensional numpy array of floats (r/g/b/a) in range 0-255.0) – Image to be blended upon
bg (3-dimensional numpy array of floats (r/g/b/a) in range 0.0-255.0) – Layer to be blended with image
opacity (float) – Desired opacity of layer for blending
disable_type_checks (bool) – Whether type checks within the function should be disabled. Disabling the checks may yield a slight performance improvement, but comes at the cost of user experience. If you are certain that you are passing in the right arguments, you may set this argument to ‘True’. Defaults to ‘False’.
- Returns:
Blended image
- Return type:
3-dimensional numpy array of floats (r/g/b/a) in range 0.0-255.0
- mapchete_eo.image_operations.blend_functions.dodge(fg: ndarray, bg: ndarray, opacity: float)[source]
Apply dodge blending mode of a layer on an image.
See also
Find more information on Wikipedia.
- Parameters:
fg (3-dimensional numpy array of floats (r/g/b/a) in range 0-255.0) – Image to be blended upon
bg (3-dimensional numpy array of floats (r/g/b/a) in range 0.0-255.0) – Layer to be blended with image
opacity (float) – Desired opacity of layer for blending
disable_type_checks (bool) – Whether type checks within the function should be disabled. Disabling the checks may yield a slight performance improvement, but comes at the cost of user experience. If you are certain that you are passing in the right arguments, you may set this argument to ‘True’. Defaults to ‘False’.
- Returns:
Blended image
- Return type:
3-dimensional numpy array of floats (r/g/b/a) in range 0.0-255.0
- mapchete_eo.image_operations.blend_functions.grain_extract(fg: ndarray, bg: ndarray, opacity: float)[source]
Apply grain extract blending mode of a layer on an image.
See also
Find more information in the GIMP Documentation.
- Parameters:
fg (3-dimensional numpy array of floats (r/g/b/a) in range 0-255.0) – Image to be blended upon
bg (3-dimensional numpy array of floats (r/g/b/a) in range 0.0-255.0) – Layer to be blended with image
opacity (float) – Desired opacity of layer for blending
disable_type_checks (bool) – Whether type checks within the function should be disabled. Disabling the checks may yield a slight performance improvement, but comes at the cost of user experience. If you are certain that you are passing in the right arguments, you may set this argument to ‘True’. Defaults to ‘False’.
- Returns:
Blended image
- Return type:
3-dimensional numpy array of floats (r/g/b/a) in range 0.0-255.0
- mapchete_eo.image_operations.blend_functions.grain_merge(fg: ndarray, bg: ndarray, opacity: float)[source]
Apply grain merge blending mode of a layer on an image.
See also
Find more information in the GIMP Documentation.
- Parameters:
fg (3-dimensional numpy array of floats (r/g/b/a) in range 0-255.0) – Image to be blended upon
bg (3-dimensional numpy array of floats (r/g/b/a) in range 0.0-255.0) – Layer to be blended with image
opacity (float) – Desired opacity of layer for blending
disable_type_checks (bool) – Whether type checks within the function should be disabled. Disabling the checks may yield a slight performance improvement, but comes at the cost of user experience. If you are certain that you are passing in the right arguments, you may set this argument to ‘True’. Defaults to ‘False’.
- Returns:
Blended image
- Return type:
3-dimensional numpy array of floats (r/g/b/a) in range 0.0-255.0
- mapchete_eo.image_operations.blend_functions.hard_light(fg: ndarray, bg: ndarray, opacity: float)[source]
Apply hard light blending mode of a layer on an image.
See also
Find more information on Wikipedia.
- Parameters:
fg (3-dimensional numpy array of floats (r/g/b/a) in range 0-255.0) – Image to be blended upon
bg (3-dimensional numpy array of floats (r/g/b/a) in range 0.0-255.0) – Layer to be blended with image
opacity (float) – Desired opacity of layer for blending
disable_type_checks (bool) – Whether type checks within the function should be disabled. Disabling the checks may yield a slight performance improvement, but comes at the cost of user experience. If you are certain that you are passing in the right arguments, you may set this argument to ‘True’. Defaults to ‘False’.
- Returns:
Blended image
- Return type:
3-dimensional numpy array of floats (r/g/b/a) in range 0.0-255.0
- mapchete_eo.image_operations.blend_functions.lighten_only(fg: ndarray, bg: ndarray, opacity: float)[source]
Apply lighten only blending mode of a layer on an image.
See also
Find more information on Wikipedia.
- Parameters:
fg (3-dimensional numpy array of floats (r/g/b/a) in range 0-255.0) – Image to be blended upon
bg (3-dimensional numpy array of floats (r/g/b/a) in range 0.0-255.0) – Layer to be blended with image
opacity (float) – Desired opacity of layer for blending
disable_type_checks (bool) – Whether type checks within the function should be disabled. Disabling the checks may yield a slight performance improvement, but comes at the cost of user experience. If you are certain that you are passing in the right arguments, you may set this argument to ‘True’. Defaults to ‘False’.
- Returns:
Blended image
- Return type:
3-dimensional numpy array of floats (r/g/b/a) in range 0.0-255.0
- mapchete_eo.image_operations.blend_functions.multiply(fg: ndarray, bg: ndarray, opacity: float)[source]
Apply multiply blending mode of a layer on an image.
See also
Find more information on Wikipedia.
- Parameters:
fg (3-dimensional numpy array of floats (r/g/b/a) in range 0-255.0) – Image to be blended upon
bg (3-dimensional numpy array of floats (r/g/b/a) in range 0.0-255.0) – Layer to be blended with image
opacity (float) – Desired opacity of layer for blending
disable_type_checks (bool) – Whether type checks within the function should be disabled. Disabling the checks may yield a slight performance improvement, but comes at the cost of user experience. If you are certain that you are passing in the right arguments, you may set this argument to ‘True’. Defaults to ‘False’.
- Returns:
Blended image
- Return type:
3-dimensional numpy array of floats (r/g/b/a) in range 0.0-255.0
- mapchete_eo.image_operations.blend_functions.normal(fg: ndarray, bg: ndarray, opacity: float)[source]
Apply “normal” blending mode of a layer on an image.
See also
Find more information on Wikipedia.
- Parameters:
fg (3-dimensional numpy array of floats (r/g/b/a) in range 0.0-255.0) – Layer to be blended with image
bg (3-dimensional numpy array of floats (r/g/b/a) in range 0-255.0) – Image to be blended upon
opacity (float) – Desired opacity of layer for blending
disable_type_checks (bool) – Whether type checks within the function should be disabled. Disabling the checks may yield a slight performance improvement, but comes at the cost of user experience. If you are certain that you are passing in the right arguments, you may set this argument to ‘True’. Defaults to ‘False’.
- Returns:
Blended image
- Return type:
3-dimensional numpy array of floats (r/g/b/a) in range 0.0-255.0
- mapchete_eo.image_operations.blend_functions.overlay(fg: ndarray, bg: ndarray, opacity: float)[source]
Apply overlay blending mode of a layer on an image.
Note
The implementation of this method was changed in version 2.0.0. Previously, it would be identical to the soft light blending mode. Now, it resembles the implementation on Wikipedia. You can still use the soft light blending mode if you are looking for backwards compatibility.
See also
Find more information on Wikipedia.
- Parameters:
fg (3-dimensional numpy array of floats (r/g/b/a) in range 0-255.0) – Image to be blended upon
bg (3-dimensional numpy array of floats (r/g/b/a) in range 0.0-255.0) – Layer to be blended with image
opacity (float) – Desired opacity of layer for blending
disable_type_checks (bool) – Whether type checks within the function should be disabled. Disabling the checks may yield a slight performance improvement, but comes at the cost of user experience. If you are certain that you are passing in the right arguments, you may set this argument to ‘True’. Defaults to ‘False’.
- Returns:
Blended image
- Return type:
3-dimensional numpy array of floats (r/g/b/a) in range 0.0-255.0
- mapchete_eo.image_operations.blend_functions.screen(fg: ndarray, bg: ndarray, opacity: float)[source]
Apply screen blending mode of a layer on an image.
See also
Find more information on Wikipedia.
- Parameters:
fg (3-dimensional numpy array of floats (r/g/b/a) in range 0-255.0) – Image to be blended upon
bg (3-dimensional numpy array of floats (r/g/b/a) in range 0.0-255.0) – Layer to be blended with image
opacity (float) – Desired opacity of layer for blending
disable_type_checks (bool) – Whether type checks within the function should be disabled. Disabling the checks may yield a slight performance improvement, but comes at the cost of user experience. If you are certain that you are passing in the right arguments, you may set this argument to ‘True’. Defaults to ‘False’.
- Returns:
Blended image
- Return type:
3-dimensional numpy array of floats (r/g/b/a) in range 0.0-255.0
- mapchete_eo.image_operations.blend_functions.soft_light(fg: ndarray, bg: ndarray, opacity: float)[source]
Apply soft light blending mode of a layer on an image.
See also
Find more information on Wikipedia.
- Parameters:
fg (3-dimensional numpy array of floats (r/g/b/a) in range 0-255.0) – Image to be blended upon
bg (3-dimensional numpy array of floats (r/g/b/a) in range 0.0-255.0) – Layer to be blended with image
opacity (float) – Desired opacity of layer for blending
disable_type_checks (bool) – Whether type checks within the function should be disabled. Disabling the checks may yield a slight performance improvement, but comes at the cost of user experience. If you are certain that you are passing in the right arguments, you may set this argument to ‘True’. Defaults to ‘False’.
- Returns:
Blended image
- Return type:
3-dimensional numpy array of floats (r/g/b/a) in range 0.0-255.0
- mapchete_eo.image_operations.blend_functions.subtract(fg: ndarray, bg: ndarray, opacity: float)[source]
Apply subtract blending mode of a layer on an image.
See also
Find more information on Wikipedia.
- Parameters:
fg (3-dimensional numpy array of floats (r/g/b/a) in range 0-255.0) – Image to be blended upon
bg (3-dimensional numpy array of floats (r/g/b/a) in range 0.0-255.0) – Layer to be blended with image
opacity (float) – Desired opacity of layer for blending
disable_type_checks (bool) – Whether type checks within the function should be disabled. Disabling the checks may yield a slight performance improvement, but comes at the cost of user experience. If you are certain that you are passing in the right arguments, you may set this argument to ‘True’. Defaults to ‘False’.
- Returns:
Blended image
- Return type:
3-dimensional numpy array of floats (r/g/b/a) in range 0.0-255.0
mapchete_eo.image_operations.color_correction module
- mapchete_eo.image_operations.color_correction.color_correct(rgb: ~numpy.ma.MaskedArray, gamma: float = 1.15, clahe_flag: bool = True, clahe_clip_limit: float = 1.25, clahe_tile_grid_size: ~typing.Tuple[int, int] = (32, 32), sigmoidal_flag: bool = False, sigmoidal_constrast: int = 0, sigmoidal_bias: float = 0.0, saturation: float = 3.2, calculations_dtype: ~numpy.dtype[~typing.Any] | None | type[~typing.Any] | ~numpy._typing._dtype_like._SupportsDType[~numpy.dtype[~typing.Any]] | str | tuple[~typing.Any, int] | tuple[~typing.Any, ~typing.SupportsIndex | ~collections.abc.Sequence[~typing.SupportsIndex]] | list[~typing.Any] | ~numpy._typing._dtype_like._DTypeDict | tuple[~typing.Any, ~typing.Any] = <class 'numpy.float16'>) MaskedArray[source]
Return color corrected 8 bit RGB array from 8 bit input RGB.
Uses rio-color to apply correction.
- Parameters:
bands (ma.MaskedArray) – Input bands as a 8bit 3D array.
gamma (float) – Apply gamma in HSV color space.
clahe_clip_limit (float) – Common values limit the resulting amplification to between 3 and 4. See “Contrast Limited AHE” at: https://en.wikipedia.org/wiki/Adaptive_histogram_equalization.
saturation (float) – Controls the saturation in HSV color space.
- Returns:
color corrected image
- Return type:
np.ndarray
mapchete_eo.image_operations.compositing module
- class mapchete_eo.image_operations.compositing.GradientPosition(*values)[source]
Bases:
Enum- edge = 'edge'
- inside = 'inside'
- outside = 'outside'
- mapchete_eo.image_operations.compositing.addition(bg: ndarray, fg: ndarray, opacity: float = 1) MaskedArray[source]
- mapchete_eo.image_operations.compositing.composite(method: str, bg: ndarray, fg: ndarray, opacity: float = 1) MaskedArray[source]
Composite two image arrays using a named blending method.
- Parameters:
method – Blending method name (e.g., ‘multiply’, ‘screen’).
bg – Background image array (channels-first).
fg – Foreground image array (channels-first).
opacity – Opacity of the foreground layer (0-1).
- Returns:
Blended RGBA result.
- Return type:
ma.MaskedArray
- mapchete_eo.image_operations.compositing.darken_only(bg: ndarray, fg: ndarray, opacity: float = 1) MaskedArray[source]
- mapchete_eo.image_operations.compositing.difference(bg: ndarray, fg: ndarray, opacity: float = 1) MaskedArray[source]
- mapchete_eo.image_operations.compositing.divide(bg: ndarray, fg: ndarray, opacity: float = 1) MaskedArray[source]
- mapchete_eo.image_operations.compositing.dodge(bg: ndarray, fg: ndarray, opacity: float = 1) MaskedArray[source]
- mapchete_eo.image_operations.compositing.fuzzy_alpha_mask(arr: ndarray, mask: ndarray | None = None, radius=0, fill_value=255, gradient_position=GradientPosition.outside) ndarray[source]
Return an RGBA array with a fuzzy alpha mask.
- mapchete_eo.image_operations.compositing.fuzzy_mask(arr: ndarray, fill_value: float, radius: int = 0, invert: bool = True, dilate: bool = True) ndarray[source]
Create fuzzy mask from binary mask.
- mapchete_eo.image_operations.compositing.grain_extract(bg: ndarray, fg: ndarray, opacity: float = 1) MaskedArray[source]
- mapchete_eo.image_operations.compositing.grain_merge(bg: ndarray, fg: ndarray, opacity: float = 1) MaskedArray[source]
- mapchete_eo.image_operations.compositing.hard_light(bg: ndarray, fg: ndarray, opacity: float = 1) MaskedArray[source]
- mapchete_eo.image_operations.compositing.lighten_only(bg: ndarray, fg: ndarray, opacity: float = 1) MaskedArray[source]
- mapchete_eo.image_operations.compositing.multiply(bg: ndarray, fg: ndarray, opacity: float = 1) MaskedArray[source]
- mapchete_eo.image_operations.compositing.normal(bg: ndarray, fg: ndarray, opacity: float = 1) MaskedArray[source]
- mapchete_eo.image_operations.compositing.overlay(bg: ndarray, fg: ndarray, opacity: float = 1) MaskedArray[source]
- mapchete_eo.image_operations.compositing.screen(bg: ndarray, fg: ndarray, opacity: float = 1) MaskedArray[source]
- mapchete_eo.image_operations.compositing.soft_light(bg: ndarray, fg: ndarray, opacity: float = 1) MaskedArray[source]
mapchete_eo.image_operations.dtype_scale module
- mapchete_eo.image_operations.dtype_scale.dtype_scale(bands: ~numpy.ma.MaskedArray, nodata: float | None = None, out_dtype: ~numpy.dtype[~typing.Any] | None | type[~typing.Any] | ~numpy._typing._dtype_like._SupportsDType[~numpy.dtype[~typing.Any]] | str | tuple[~typing.Any, int] | tuple[~typing.Any, ~typing.SupportsIndex | ~collections.abc.Sequence[~typing.SupportsIndex]] | list[~typing.Any] | ~numpy._typing._dtype_like._DTypeDict | tuple[~typing.Any, ~typing.Any] = <class 'numpy.uint8'>, max_source_value: float = 10000.0, max_output_value: float | None = None) MaskedArray[source]
normalize array from range [0:max_value] to range [0:1]
multiply with out_values to create range [0:out_values]
(3) clip to [1:out_values] to avoid rounding errors where band value can accidentally become nodata (0) (4) create masked array with burnt in nodata values and original nodata mask
mapchete_eo.image_operations.fillnodata module
- class mapchete_eo.image_operations.fillnodata.FillSelectionMethod(*values)[source]
-
- all = 'all'
- nodata_neighbors = 'nodata_neighbors'
- patch_size = 'patch_size'
- mapchete_eo.image_operations.fillnodata.fillnodata(bands: MaskedArray, method: FillSelectionMethod = FillSelectionMethod.patch_size, max_patch_size: int = 2, max_nodata_neighbors: int = 0, max_search_distance: float = 10, smoothing_iterations: int = 0) MaskedArray[source]
Interpolate nodata areas up to a given size.
This function uses the nodata mask to determine contingent nodata areas. Patches up to a certain size are then interpolated using rasterio.fill.fillnodata.
- Parameters:
bands (ma.MaskedArray) – Input bands as a 3D array.
method (str) –
- Method how to select areas to interpolate. (default: patch_size)
all: interpolate all nodata areas
- patch_size: only interpolate areas up to a certain size. (defined by
max_patch_size)
nodata_neighbors: only interpolate single nodata pixel.
max_patch_size (int) – Maximum patch size in pixels which is going to be interpolated in “patch_size” method.
max_nodata_neighbors (int) – Maximum number of nodata neighbor pixels in “nodata_neighbors” method.
max_search_distance (float) – The maxmimum number of pixels to search in all directions to find values to interpolate from.
smoothing_iterations (int) – The number of 3x3 smoothing filter passes to run.
- Returns:
filled bands
- Return type:
ma.MaskedArray
mapchete_eo.image_operations.filters module
- mapchete_eo.image_operations.filters.blur(arr: ndarray) ndarray[source]
Apply PIL blur filter to array and return.
- Parameters:
arr (3-dimensional uint8 NumPy array)
- Return type:
NumPy array
- mapchete_eo.image_operations.filters.contour(arr: ndarray) ndarray[source]
Apply PIL contour filter to array and return.
- Parameters:
arr (3-dimensional uint8 NumPy array)
- Return type:
NumPy array
- mapchete_eo.image_operations.filters.detail(arr: ndarray) ndarray[source]
Apply PIL detail filter to array and return.
- Parameters:
arr (3-dimensional uint8 NumPy array)
- Return type:
NumPy array
- mapchete_eo.image_operations.filters.edge_enhance(arr: ndarray) ndarray[source]
Apply PIL edge_enhance filter to array and return.
- Parameters:
arr (3-dimensional uint8 NumPy array)
- Return type:
NumPy array
- mapchete_eo.image_operations.filters.edge_enhance_more(arr: ndarray) ndarray[source]
Apply PIL edge_enhance_more filter to array and return.
- Parameters:
arr (3-dimensional uint8 NumPy array)
- Return type:
NumPy array
- mapchete_eo.image_operations.filters.emboss(arr: ndarray) ndarray[source]
Apply PIL emboss filter to array and return.
- Parameters:
arr (3-dimensional uint8 NumPy array)
- Return type:
NumPy array
- mapchete_eo.image_operations.filters.find_edges(arr: ndarray) ndarray[source]
Apply PIL find_edges filter to array and return.
- Parameters:
arr (3-dimensional uint8 NumPy array)
- Return type:
NumPy array
- mapchete_eo.image_operations.filters.gaussian_blur(arr: ndarray, radius: int = 2) ndarray[source]
Apply PIL GaussianBlur to array and return.
- Parameters:
arr (3-dimensional uint8 NumPy array)
- Return type:
NumPy array
- mapchete_eo.image_operations.filters.median(arr: ndarray, size: int = 3) ndarray[source]
Apply PIL MedianFilter to array and return.
- Parameters:
arr (3-dimensional uint8 NumPy array)
- Return type:
NumPy array
- mapchete_eo.image_operations.filters.sharpen(arr: ndarray) ndarray[source]
Apply PIL sharpen filter to array and return.
- Parameters:
arr (3-dimensional uint8 NumPy array)
- Return type:
NumPy array
- mapchete_eo.image_operations.filters.smooth(arr: ndarray) ndarray[source]
Apply PIL smooth filter to array and return.
- Parameters:
arr (3-dimensional uint8 NumPy array)
- Return type:
NumPy array
mapchete_eo.image_operations.linear_normalization module
- mapchete_eo.image_operations.linear_normalization.linear_normalization(bands: ~numpy.ma.MaskedArray, bands_minmax_values: ~typing.Tuple[~typing.Tuple[int, int], ~typing.Tuple[int, int], ~typing.Tuple[int, int]] = ((5, 3350), (0, 3150), (0, 3200)), out_dtype: ~numpy.dtype[~typing.Any] | None | type[~typing.Any] | ~numpy._typing._dtype_like._SupportsDType[~numpy.dtype[~typing.Any]] | str | tuple[~typing.Any, int] | tuple[~typing.Any, ~typing.SupportsIndex | ~collections.abc.Sequence[~typing.SupportsIndex]] | list[~typing.Any] | ~numpy._typing._dtype_like._DTypeDict | tuple[~typing.Any, ~typing.Any] = <class 'numpy.uint8'>, out_min: int | None = None) MaskedArray[source]
Scale and normalize bands to individual minimum and maximum values.
From eox_preprocessing.image_utils
See: https://en.wikipedia.org/wiki/Normalization_(image_processing)
- Parameters:
bands (np.ndarray) – Input bands as a 3D array.
bands_minmax_values (list of lists) – Individual minimum and maximum values for each band. Must have the same length as number of bands.
out_min (float or int) – Override dtype minimum. Useful when nodata value is equal to dtype minimum (e.g. 0 at uint8). In that case out_min can be set to 1.
- Returns:
scaled bands
- Return type:
ma.MaskedArray
mapchete_eo.image_operations.sigmoidal module
- mapchete_eo.image_operations.sigmoidal.sigmoidal(arr: ~numpy.ndarray, contrast: int, bias: float, out_dtype: ~numpy.dtype[~typing.Any] | None | type[~typing.Any] | ~numpy._typing._dtype_like._SupportsDType[~numpy.dtype[~typing.Any]] | str | tuple[~typing.Any, int] | tuple[~typing.Any, ~typing.SupportsIndex | ~collections.abc.Sequence[~typing.SupportsIndex]] | list[~typing.Any] | ~numpy._typing._dtype_like._DTypeDict | tuple[~typing.Any, ~typing.Any] = <class 'numpy.float16'>)[source]
Taken from rio-color (consult sevcikp for changes)
Sigmoidal contrast is type of contrast control that adjusts the contrast without saturating highlights or shadows. It allows control over two factors: the contrast range from light to dark, and where the middle value of the mid-tones falls. The result is a non-linear and smooth contrast change.
- Parameters:
arr (ndarray, float, 0 .. 1) – Array of color values to adjust
contrast (integer) – Enhances the intensity differences between the lighter and darker elements of the image. For example, 0 is none, 3 is typical and 20 is a lot.
bias (float, between 0 and 1) – Threshold level for the contrast function to center on (typically centered at 0.5)
Notes
Sigmoidal contrast is based on the sigmoidal transfer function:
\[g(u) = ( 1/(1 + e^{- lpha * u + eta)})\]This sigmoid function is scaled so that the output is bound by the interval [0, 1].
\[( 1/(1 + e^(eta * (lpha - u))) - 1/(1 + e^(eta * lpha)))/ ( 1/(1 + e^(eta*(lpha - 1))) - 1/(1 + e^(eta * lpha)) )\]Where :math: lpha is the threshold level, and :math: eta the contrast factor to be applied.
References
[CT]Hany Farid “Fundamentals of Image Processing” http://www.cs.dartmouth.edu/farid/downloads/tutorials/fip.pdf
Module contents
- class mapchete_eo.image_operations.FillSelectionMethod(*values)[source]
-
- all = 'all'
- nodata_neighbors = 'nodata_neighbors'
- patch_size = 'patch_size'
- mapchete_eo.image_operations.color_correct(rgb: ~numpy.ma.MaskedArray, gamma: float = 1.15, clahe_flag: bool = True, clahe_clip_limit: float = 1.25, clahe_tile_grid_size: ~typing.Tuple[int, int] = (32, 32), sigmoidal_flag: bool = False, sigmoidal_constrast: int = 0, sigmoidal_bias: float = 0.0, saturation: float = 3.2, calculations_dtype: ~numpy.dtype[~typing.Any] | None | type[~typing.Any] | ~numpy._typing._dtype_like._SupportsDType[~numpy.dtype[~typing.Any]] | str | tuple[~typing.Any, int] | tuple[~typing.Any, ~typing.SupportsIndex | ~collections.abc.Sequence[~typing.SupportsIndex]] | list[~typing.Any] | ~numpy._typing._dtype_like._DTypeDict | tuple[~typing.Any, ~typing.Any] = <class 'numpy.float16'>) MaskedArray[source]
Return color corrected 8 bit RGB array from 8 bit input RGB.
Uses rio-color to apply correction.
- Parameters:
bands (ma.MaskedArray) – Input bands as a 8bit 3D array.
gamma (float) – Apply gamma in HSV color space.
clahe_clip_limit (float) – Common values limit the resulting amplification to between 3 and 4. See “Contrast Limited AHE” at: https://en.wikipedia.org/wiki/Adaptive_histogram_equalization.
saturation (float) – Controls the saturation in HSV color space.
- Returns:
color corrected image
- Return type:
np.ndarray
- mapchete_eo.image_operations.dtype_scale(bands: ~numpy.ma.MaskedArray, nodata: float | None = None, out_dtype: ~numpy.dtype[~typing.Any] | None | type[~typing.Any] | ~numpy._typing._dtype_like._SupportsDType[~numpy.dtype[~typing.Any]] | str | tuple[~typing.Any, int] | tuple[~typing.Any, ~typing.SupportsIndex | ~collections.abc.Sequence[~typing.SupportsIndex]] | list[~typing.Any] | ~numpy._typing._dtype_like._DTypeDict | tuple[~typing.Any, ~typing.Any] = <class 'numpy.uint8'>, max_source_value: float = 10000.0, max_output_value: float | None = None) MaskedArray[source]
normalize array from range [0:max_value] to range [0:1]
multiply with out_values to create range [0:out_values]
(3) clip to [1:out_values] to avoid rounding errors where band value can accidentally become nodata (0) (4) create masked array with burnt in nodata values and original nodata mask
- mapchete_eo.image_operations.fillnodata(bands: MaskedArray, method: FillSelectionMethod = FillSelectionMethod.patch_size, max_patch_size: int = 2, max_nodata_neighbors: int = 0, max_search_distance: float = 10, smoothing_iterations: int = 0) MaskedArray[source]
Interpolate nodata areas up to a given size.
This function uses the nodata mask to determine contingent nodata areas. Patches up to a certain size are then interpolated using rasterio.fill.fillnodata.
- Parameters:
bands (ma.MaskedArray) – Input bands as a 3D array.
method (str) –
- Method how to select areas to interpolate. (default: patch_size)
all: interpolate all nodata areas
- patch_size: only interpolate areas up to a certain size. (defined by
max_patch_size)
nodata_neighbors: only interpolate single nodata pixel.
max_patch_size (int) – Maximum patch size in pixels which is going to be interpolated in “patch_size” method.
max_nodata_neighbors (int) – Maximum number of nodata neighbor pixels in “nodata_neighbors” method.
max_search_distance (float) – The maxmimum number of pixels to search in all directions to find values to interpolate from.
smoothing_iterations (int) – The number of 3x3 smoothing filter passes to run.
- Returns:
filled bands
- Return type:
ma.MaskedArray
- mapchete_eo.image_operations.linear_normalization(bands: ~numpy.ma.MaskedArray, bands_minmax_values: ~typing.Tuple[~typing.Tuple[int, int], ~typing.Tuple[int, int], ~typing.Tuple[int, int]] = ((5, 3350), (0, 3150), (0, 3200)), out_dtype: ~numpy.dtype[~typing.Any] | None | type[~typing.Any] | ~numpy._typing._dtype_like._SupportsDType[~numpy.dtype[~typing.Any]] | str | tuple[~typing.Any, int] | tuple[~typing.Any, ~typing.SupportsIndex | ~collections.abc.Sequence[~typing.SupportsIndex]] | list[~typing.Any] | ~numpy._typing._dtype_like._DTypeDict | tuple[~typing.Any, ~typing.Any] = <class 'numpy.uint8'>, out_min: int | None = None) MaskedArray[source]
Scale and normalize bands to individual minimum and maximum values.
From eox_preprocessing.image_utils
See: https://en.wikipedia.org/wiki/Normalization_(image_processing)
- Parameters:
bands (np.ndarray) – Input bands as a 3D array.
bands_minmax_values (list of lists) – Individual minimum and maximum values for each band. Must have the same length as number of bands.
out_min (float or int) – Override dtype minimum. Useful when nodata value is equal to dtype minimum (e.g. 0 at uint8). In that case out_min can be set to 1.
- Returns:
scaled bands
- Return type:
ma.MaskedArray