eolearn.features.utils

Utilities for EOPatch feature modification

class eolearn.features.utils.ResizeParam(value)[source]

Bases: enum.Enum

Descriptors of spatial-resizing parameter options.

NEW_SIZE = 'new_size'
SCALE_FACTORS = 'scale_factors'
RESOLUTION = 'resolution'
class eolearn.features.utils.ResizeMethod(value)[source]

Bases: enum.Enum

Methods available for spatial resizing of data.

NEAREST = 'nearest'
LINEAR = 'linear'
CUBIC = 'cubic'
get_cv2_method(dtype)[source]

Obtain the constant specifying the interpolation method for the CV2 library.

Parameters

dtype (Union[numpy.dtype, type]) –

Return type

int

get_pil_method()[source]

Obtain the constant specifying the interpolation method for the PIL library.

Return type

PIL.Image.Resampling

class eolearn.features.utils.ResizeLib(value)[source]

Bases: enum.Enum

Backends available for spatial resizing of data.

PIL = 'PIL'
CV2 = 'cv2'
get_compatible_dtype(dtype)[source]

Returns a suitable dtype with which the library can work. Warns if information loss could occur.

Parameters

dtype (Union[numpy.dtype, type]) –

Return type

numpy.dtype

eolearn.features.utils.spatially_resize_image(data, new_size=None, scale_factors=None, spatial_axes=None, resize_method=ResizeMethod.LINEAR, resize_library=ResizeLib.PIL)[source]

Resizes the image(s) according to given size or scale factors.

To specify the new scale use one of new_size or scale_factors parameters.

Parameters
  • data (numpy.ndarray) – input image array

  • new_size (Optional[Tuple[int, int]]) – New size of the data (height, width)

  • scale_factors (Optional[Tuple[float, float]]) – Factors (f_height, f_width) by which to resize the image

  • spatial_axes (Optional[Tuple[int, int]]) – Which two axes of input data represent height and width. If left as None they are selected according to standards of eo-learn features.

  • resize_method (eolearn.features.utils.ResizeMethod) – Interpolation method used for resizing.

  • resize_library (eolearn.features.utils.ResizeLib) – Which Python library to use for resizing. Default is PIL, as it supports all dtypes and features anti-aliasing. For cases where execution speed is crucial one can use CV2.

Return type

numpy.ndarray