paidiverpy.convert_layer#

__init__.py file for convert_layer module.

Submodules#

Classes#

ConvertLayer

Process the images in the convert layer.

Package Contents#

class paidiverpy.convert_layer.ConvertLayer(parameters: dict[str, Any] | None = None, config_params: dict[str, Any] | paidiverpy.config.config_params.ConfigParams | None = None, config_file_path: str | None = None, config: paidiverpy.config.configuration.Configuration | None = None, metadata: paidiverpy.metadata_parser.MetadataParser | None = None, images: paidiverpy.images_layer.ImagesLayer | None = None, paidiverpy: paidiverpy.Paidiverpy | None = None, step_name: str | None = None, client: dask.distributed.Client | None = None, config_index: int | None = None, logger: logging.Logger | None = None, raise_error: bool = False, verbose: int = 2)[source]#

Bases: paidiverpy.Paidiverpy

Process the images in the convert layer.

This class provides various methods to convert images according to specified configurations, such as resizing, normalizing, bit depth conversion, and channel conversion.

Parameters:
  • config_params (dict | ConfigParams, optional) – The configuration parameters. It can contain the following keys / attributes: - input_path (str): The path to the input files. - output_path (str): The path to the output files. - metadata_path (str): The path to the metadata file. - metadata_type (str): The type of the metadata file. - track_changes (bool): Whether to track changes. - n_jobs (int): The number of n_jobs.

  • config_file_path (str) – The path to the configuration file.

  • config (Configuration) – The configuration object.

  • metadata (MetadataParser) – The metadata object.

  • images (ImagesLayer) – The images object.

  • paidiverpy (Paidiverpy) – The paidiverpy object.

  • step_name (str) – The name of the step.

  • client (Client) – The Dask client.

  • parameters (dict) – The parameters for the step.

  • config_index (int) – The index of the configuration.

  • logger (logging.Logger) – The logger object.

  • raise_error (bool) – Whether to raise an error.

  • verbose (int) – verbose level (0 = none, 1 = errors/warnings, 2 = info).

static convert_bits(image_data: numpy.ndarray[Any, Any], params: paidiverpy.models.convert_params.BitParams | None = None, **_kwargs: dict[str, Any]) numpy.ndarray[Any, Any][source]#

Convert the image to the specified number of bits.

Parameters:
  • image_data (xr.DataArray) – The image data.

  • params (BitParams, optional) – The parameters for the bit conversion.

  • **_kwargs – Additional keyword arguments.

Defaults to BitParams().

Returns:

The updated image.

Return type:

np.ndarray

static channel_convert(image_data: numpy.ndarray[Any, Any], params: paidiverpy.models.convert_params.ToParams | None = None, **_kwargs: dict[str, Any]) numpy.ndarray[Any, Any][source]#

Convert the image to the specified channel.

Parameters:
  • image_data (xr.DataArray) – The image data.

  • params (ToParams, optional) – The parameters for the channel conversion. Defaults to ToParams().

  • **_kwargs – Additional keyword arguments.

Raises:
  • ValueError – The image is already in RGB format.

  • ValueError – The image is already in grayscale.

  • ValueError – Failed to convert the image to {params.to}: {str(e)}

Returns:

The updated image.

Return type:

np.ndarray

static normalize_image(image_data: numpy.ndarray[Any, Any], params: paidiverpy.models.convert_params.NormalizeParams | None = None, **_kwargs: dict[str, Any]) numpy.ndarray[Any, Any][source]#

Normalize the image data.

Parameters:
  • image_data (xr.DataArray) – The image data.

  • params (NormalizeParams, optional) – The parameters for the image normalization. Defaults to NormalizeParams().

  • **_kwargs – Additional keyword arguments.

Defaults to NormalizeParams().

Raises:

ValueError – Failed to normalize the image: {str(e)}

Returns:

The updated image.

Return type:

np.ndarray

static resize(image_data: numpy.ndarray[Any, Any], params: paidiverpy.models.convert_params.ResizeParams | None = None, **_kwargs: dict[str, Any]) numpy.ndarray[Any, Any][source]#

Resize the image data.

Parameters:
  • image_data (xr.DataArray) – The image data.

  • params (ResizeParams, optional) – The parameters for the image resizing. Defaults to ResizeParams().

  • **_kwargs – Additional keyword arguments.

Raises:

ValueError – Failed to resize the image: {str(e)}

Returns:

The updated image.

Return type:

np.ndarray

static crop_images(image_data: numpy.ndarray[Any, Any], params: paidiverpy.models.convert_params.CropParams | None = None, **_kwargs: dict[str, Any]) numpy.ndarray[Any, Any][source]#

Crop the image data.

Parameters:
  • image_data (xr.DataArray) – The image data.

  • params (CropParams, optional) – The parameters for the image cropping. Defaults to CropParams().

  • **_kwargs – Additional keyword arguments.

Raises:
  • ValueError – The crop size is larger than the image size.

  • ValueError – top_left must be provided when mode=’topleft’.

Returns:

The updated image.

Return type:

np.ndarray