neural_de.transformations package

Subpackages

Submodules

neural_de.transformations.brightness_enhancer module

Image brightness enhancement method.

class neural_de.transformations.brightness_enhancer.BrightnessEnhancer(logger=None)[source]

Bases: BaseTransformation

BaseTransformation method for image brightness change. It uses NPLIE-based method for brightness enhancement, and Opencv for transforming the image.

Example :

See the notebook examples/BrightnessEnhancer_example.ipynb for more usage details.

1- Import the class

. code-block:: python

from neural_de.transformations import BrightnessEnhancer

2- Create an instance of BrightnessEnhancer.

. code-block:: python

bright_ehn = BrightnessEnhancer()

3- Apply the brightness change to a batch of images to a given shape

. code-block:: python

out_images = bright_ehn.transform(images)

Parameters:
  • logger (Optional[Logger]) – It is recommended to use the Confiance logger, obtainable with

  • neural_de.utils.get_logger –

  • None (If) –

  • provided. (one logging with stdout will be) –

enhance_brightness(image)[source]
Parameters:

Image – numpy array format with float32 dtype.

Returns:

Image numpy array format with float32 dtype.

transform(images)[source]

Improve brightness a batch of images using a NPLIE-based method.

Parameters:

images (Union[list[ndarray], ndarray]) – Batch of images. Each image should be of a np.ndarray of target_shape (h,w, channels). Images dimensions do not need to be the same across the batch.

Returns:

The same images with improved brightness.

neural_de.transformations.centered_zoom module

Simple wrapper to share experimental results on working params for a CenteredZoom

class neural_de.transformations.centered_zoom.CenteredZoom(keep_ratio, logger=None)[source]

Bases: BaseTransformation

CenteredZoom image transformation based on a numpy implementation. Given a batch of 3-channels image of size width x height, return the centered tile of size width*keep_ratio x height*keep_ratio. This transformation does not perform any resolution enhancement of the returned content. See ResolutionEnhancer to perform both crop and resolution enhancement.

Parameters:
  • keep_ratio (float) – The proportion of the input image we keep. Must be in ]0,1[.

  • logger (Optional[Logger]) – It is recommended to use the Confiance logger, obtainable with neural_de.utils.get_logger(…). If None, one logging with stdout will be provided.

transform(images)[source]

Apply CenteredZoom to a batch of images using numpy slicing method.

Parameters:

images (Union[list[ndarray], ndarray]) – Batch of images. Each image should be of a np.ndarray of target_shape (h,w, channels). Images dimensions do not need to be the same across the batch.

Returns:

The images zoomed to a given ratio in respect to its center.

transform_with_annotations(images, bbox)[source]

Transform bounding boxes to the reference in the new zoomed image. :type images: Union[list[ndarray], ndarray] :param images: Batch of images. Each image should be of a np.ndarray of target_shape (h,w, :param channels). Images dimensions do not need to be the same across the batch.: :type bbox: list :param bbox: list of list of list [batch_dim, nb_object_per_image, [x1, y1, x2, y2]] :param with the x1: :param y1: :param x2: :param y2 bounding box position in the original image.:

Returns:

The images zoomed to a given ratio in respect to its center. The list of np.ndarray with the x1, y1, x2, y2 bounding box position in the zoomed

image.

neural_de.transformations.de_rain_enhancer module

DeRain enhancer

class neural_de.transformations.de_rain_enhancer.DeRainConfig(upsample_mode='bilinear', ngf=64, n_blocks=9, use_dropout=False, input_nc=3, output_nc=3, padding_type='reflect')[source]

Bases: object

Interal configuration of the DeRain enhancer.

input_nc: int = 3
n_blocks: int = 9
ngf: int = 64
output_nc: int = 3
padding_type: str = 'reflect'
upsample_mode: str = 'bilinear'
use_dropout: bool = False
class neural_de.transformations.de_rain_enhancer.DeRainEnhancer(device='cpu', logger=None)[source]

Bases: BaseTransformation

Provides a rain removal image transformation using the GT-Rain Derain Model.

Parameters:
  • device (str) – Any torch-compatible device string.

  • logger (Optional[Logger]) – It is recommended to use the Confiance logger, obtainable with neural_de.utils.get_logger(…). If None, one logging with stdout will be provided.

transform(images)[source]

Removes the rain in a batch of images. It differs from style transfer, as it does not remove pools and ground reflection. The outputs are as β€œas if the rained just stop falling”.

Parameters:

images (Union[list[ndarray], ndarray]) – Batch of images. Each image should be of a np.ndarray of target_shape (h,w, channels). Images dimensions should be identical across one batch.

Return type:

ndarray

Returns:

The same images without rain falling on it.

neural_de.transformations.de_snow_enhancer module

Snow removal enhancer - Prenet Based implementation

class neural_de.transformations.de_snow_enhancer.DeSnowEnhancer(device='cpu', logger=None)[source]

Bases: BaseTransformation

Snow Removal Enhancer, Prenet based implementation.

** WARNING ** : The current method may have bad results on real images. The model had been trained on a simulated dataset, thus if the dataset is so different of the trained dataset, the results are not guaranteed.

Parameters:
  • device – Any torch-compatible device string.

  • logger – It is recommended to use the Confiance logger, obtainable with neural_de.utils.get_logger(…). If None, one logging with stdout will be provided.

transform(images)[source]

Removes the snow in a batch of images.

WARNING : The current method may have bad results on real images.

Parameters:

images (ndarray) – Batch of images. Each image should be of a np.ndarray of target_shape (h,w, channels). Images dimensions should be identical across one batch.

Return type:

ndarray

Returns:

The same images without snow on it.

neural_de.transformations.kernel_deblurring_enhancer module

Simple wrapper to share experimental results on working params for a Deblurring Kernel

class neural_de.transformations.kernel_deblurring_enhancer.KernelDeblurringEnhancer(kernel='high', custom_kernel=None, logger=None)[source]

Bases: BaseTransformation

Kernel Deblurring image transformation based on OpenCv implementation. Provides pre-set filter of medium and high intensity.

Parameters:
  • kernel (str) – high or medium: use a pre-set kernel with high or medium intensity.

  • custom – Optional, custom kernel to use. It can be any non empty 2D matrix. If provided, the value of kernel will not be used.

  • logger (Optional[Logger]) – It is recommended to use the Confiance logger, obtainable with neural_de.utils.get_logger(…). If None, one logging with stdout will be provided.

transform(images)[source]

Deblur a batch of images using a Kernel-based method.

Parameters:

images (Union[list[ndarray], ndarray]) – Batch of images. Each image should be of a np.ndarray of target_shape (h,w, channels). Images dimensions do not need to be the same across the batch.

Returns:

The same images with less blurr.

neural_de.transformations.night_image_enhancer module

Night to day enhancer - Maxim based implementation

class neural_de.transformations.night_image_enhancer.NightConfig(variant='S-2', dropout_rate=0.0, num_outputs=3, use_bias=True, num_supervision_scales=3)[source]

Bases: object

Static Enhancer configuration

dropout_rate: float = 0.0
num_outputs: int = 3
num_supervision_scales: int = 3
use_bias: bool = True
variant: str = 'S-2'
class neural_de.transformations.night_image_enhancer.NightImageEnhancer(device='cpu', logger=None)[source]

Bases: BaseTransformation

Provides Night to Day image transformation using the MAXIM model.

Parameters:

logger (Optional[Logger]) – It is recommended to use the Confiance logger, obtainable with neural_de.utils.get_logger(…). If None, one logging with stdout will be provided.

transform(images)[source]

Transform a batch of night image into β€œday images”, ie the same image but looking as if taken in daylight.

Parameters:

images (Union[list[ndarray], ndarray]) – Batch of images. Each image should be of a np.ndarray of target_shape (h,w, channels).

Returns:

The same images transformed as if taken in daylight.

neural_de.transformations.resolution_enhancer module

Implementation of the ResolutionEnhancer method.

neural_de.transformations.resolution_enhancer.UPSCALE_MODEL

version of the transformer model used for image upscaling

class neural_de.transformations.resolution_enhancer.ResolutionEnhancer(device='cpu', logger=None)[source]

Bases: BaseTransformation

BaseTransformation method for image resolution change. It uses neural-based method for resolution enhancement, and Opencv for diminishing the resolution.

Example :

See the notebook examples/ResolutionEnhancer_example.ipynb for more usage details.

1- Import the class

from neural_de.transformations import ResolutionEnhancer

2- Create an instance of ResolutionEnhancer. device ="Cuda" is recommended if you have a gpu and torch with cuda enabled.

res_shift = ResolutionEnhancer(device= "cpu")

3- Apply the resolution change to a batch of images to a given shape

out_images = res_shift.transform(images, ratio=2)
Parameters:
  • device (str) – Any torch-compatible device string.

  • logger (Optional[Logger]) – It is recommended to use the Confiance logger, obtainable with neural_de.utils.get_logger(…). If None, one logging with stdout will be provided.

transform(images, target_shape, crop_ratio=0.0)[source]

Modify the resolution of a batch of images to a given target_shape.

Parameters:
  • images (Union[list[ndarray], ndarray]) – Batch of images. Each image should be of a np.ndarray of target_shape (h,w, channels)

  • target_shape (Union[list, tuple]) – New resolution (h,w) in pixel.

  • crop_ratio (float) – image cropping ratio (range in [0., 1.[)

Return type:

ndarray

Returns:

Images with new resolution.

neural_de.transformations.transformation module

Parent class for any transformation method.

class neural_de.transformations.transformation.BaseTransformation(logger=None)[source]

Bases: object

Parent class for any transformation methods of the library. Provides the methods for logging and input validation.

Parameters:

logger (Optional[Logger]) – logging.logger. It is recommended to use the Confiance one, obtainable with neural_de.utils.get_logger(…)

check_device_validity(device='cpu')[source]

Check if the selected device is valid. :type device: str :param device: str - cpu / cuda

Returns:

None

neural_de.transformations.transformation_pipeline module

Transformation pipeline for automation of multiple transformations methods

class neural_de.transformations.transformation_pipeline.TransformationPipeline(config, logger=None)[source]

Bases: BaseTransformation

Provides a pipeline object, to facilitate the automation of multiple transformations methods, and/or offer loading from a yaml file.

You can check the example notebook examples/Pipeline_example.ipynb for details on the syntax and usage. An example of valid config file can be found in examples/config/conf_user.yaml

Parameters:
  • config (Union[str, list, Path]) – either a path toward a yaml configuration file, or a list of dict.

  • logger (Optional[Logger]) – It is recommended to use the confiance.ai logger, obtainable with neural_de.utils.get_logger(…). If None, one logging with stdout will be provided.

transform(images)[source]

Sequentially apply every method of the pipeline on a batch of image, and returns the resulting images.

Parameters:

images (Union[list, ndarray]) – Batch of images. Each image should be of a np.ndarray of target_shape (h,w, channels)

Return type:

Union[list, ndarray]

Returns:

Resulting batch of images, one per image provided.

neural_de.transformations.transformation_pipeline.camel_to_snake(s)[source]

This function convert input strings s from Camelcase format to snake case format

Module contents

Module with the main images transformations methods of the neural_de library. You can find more on how to use any of the proposed method in ./examples, or in the method’s class documentation.

List of the available methods :
  • ResolutionEnhancer: enhance image resolution

  • NightImageEnhancer: transform night images into daylight ones

  • KernelDeblurringEnhancer: Improve blurry images

  • DeSnowEnhancer: Removes snow from images

  • DeRainEnhancer: Removes rain from images

  • BrightnessEnhancer: Improves image brightness

  • CenteredZoom: Centered crop of an image at a given ratio

  • DiffusionEnhancer : Enhance the image using diffusion-based denoising

Special methods :
  • TransformationPipeline : Allows the automation of any combination of the previous methods, and loading from file.