Shortcuts

caer.transforms

caer.transforms consists of position and color-based transforms for use.

caer.transforms.adjust_brightness(tens, coeff, rgb=True)[source]

Adjust the brightness of an image.

Parameters
  • tens (Tensor) – Any regular caer.Tensor.

  • coeff (int) – Coefficient value. - coeff < 1, the image is darkened. - coeff = 1, the image is unchanged. - coeff > 1, the image is lightened.

  • rgb (bool) – Operate on RGB images. Default: True.

Return type

Tensor

Returns

Tensor of shape (height, width, channels).

Examples:

>> tens = caer.data.sunrise(rgb=True)
>> filtered = caer.transforms.adjust_brightness(tens, coeff=1.4, rgb=True)
>> filtered
(427, 640, 3)
caer.transforms.adjust_contrast(tens, contrast_factor)[source]

Adjust contrast of an image.

Parameters
  • tens (Tensor) – Any valid caer.Tensor.

  • contrast_factor (float) – How much to adjust the contrast. Can be any non negative number. 0 gives a solid gray image, 1 gives the original image while 2 increases the contrast by a factor of 2.

Returns

Contrast adjusted image.

Return type

caer.Tensor

caer.transforms.adjust_gamma(tens, gamma, gain=1)[source]

Perform gamma correction on an image.

Also known as Power Law Transform. Intensities in RGB mode are adjusted based on the following equation: .. math:

I_{\text{out}} = 255 \times \text{gain} \times \left(\frac{I_{\text{in}}}{255}\right)^{\gamma}

See `Gamma Correction`_ for more details. .. _Gamma Correction: https://en.wikipedia.org/wiki/Gamma_correction

Parameters
  • tens (Tensor) – Any valid caer.Tensor.

  • gamma (float) – Non negative real number, same as \gamma in the equation. gamma larger than 1 make the shadows darker, while gamma smaller than 1 make dark regions lighter.

  • gain (float) – The constant multiplier.

Examples:

>> tens = caer.data.sunrise(rgb=True)
>> filtered = caer.transforms.adjust_gamma(tens, gamma=1.5, rgb=True)
>> filtered
(427, 640, 3)
Return type

Tensor

caer.transforms.adjust_hue(tens, hue_factor)[source]

Adjust hue of an image.

The image hue is adjusted by converting the image to HSV and cyclically shifting the intensities in the hue channel (H). The image is then converted back to original image mode.

See `Hue`_ for more details. .. _Hue: https://en.wikipedia.org/wiki/Hue

Parameters
  • tens (Tensor) – Any valid caer.Tensor.

  • hue_factor (float) – How much to shift the hue channel. Should be in the range [-0.5, 0.5]. 0.5 and -0.5 give complete reversal of hue channel in HSV space in positive and negative direction respectively. 0 means no shift. Therefore, both -0.5 and 0.5 will give an image with complementary colors while 0 gives the original image.

Return type

Tensor

Returns

Hue adjusted image.

Examples:

>> tens = caer.data.sunrise(rgb=True)
>> filtered = caer.transforms.adjust_hue(tens, hue_factor=1, rgb=True)
>> filtered
(427, 640, 3)
caer.transforms.adjust_saturation(tens, saturation_factor)[source]

Adjust color saturation of an image.

Parameters
  • tens (Tensor) – Any valid caer.Tensor.

  • saturation_factor (float) – How much to adjust the saturation. 0 will give a black and white image, 1 will give the original image while 2 will enhance the saturation by a factor of 2.

Return type

Tensor

Returns

Saturation-adjusted image.

Examples:

>> tens = caer.data.sunrise(rgb=True)
>> filtered = caer.transforms.adjust_saturation(tens, saturation_factor=1.5, rgb=True)
>> filtered
(427, 640, 3)
caer.transforms.affine(tens, angle, translate, scale, shear, interpolation='bilinear', mode=0, fillcolor=0)[source]

Apply affine transformation on the image keeping image center invariant.

Parameters
  • tens (Tensor) – Any valid caer.Tensor.

  • angle (float or int) – Rotation angle in degrees between -180 and 180, clockwise direction.

  • translate (list or tuple of integers) – Horizontal and vertical translations (post-rotation translation)

  • scale (float) – Overall scale

  • shear (float) – Shear angle value in degrees between -180 to 180, clockwise direction.

  • interpolation (int, str) – Interpolation to use for resizing. Defaults to ‘bilinear’. Supports ‘bilinear’, ‘bicubic’, ‘area’, ‘nearest’.

  • mode (int, str) – Method for filling in border regions. Defaults to constant meaning areas outside the image are filled with a value (val, default 0). Supports 'replicate', 'reflect', 'reflect-101'.

  • val (int) – Optional fill color for the area outside the transform in the output image. Default: 0

Return type

Tensor

caer.transforms.brighten(tens, coeff=- 1, rgb=True)[source]

Brighten an image.

Parameters
  • tens (Tensor) – Any regular caer.Tensor.

  • coeff (int) – Coefficient value.

  • rgb (bool) – Operate on RGB images. Default: True.

Return type

Tensor

Returns

Tensor of shape (height, width, channels).

Examples:

>> tens = caer.data.sunrise(rgb=True)
>> filtered = caer.transforms.brighten(tens, coeff=-1, rgb=True)
>> filtered
(427, 640, 3)
caer.transforms.correct_exposure(tens, rgb=True)[source]

Correct the exposure of an image.

Parameters
  • tens (Tensor) – Any regular caer.Tensor.

  • rgb (bool) – Operate on RGB images. Default: True.

Return type

Tensor

Returns

Tensor of shape (height, width, channels).

Examples:

>> tens = caer.data.sunrise(rgb=True)
>> filtered = caer.transforms.correct_exposure(tens, rgb=True)
>> filtered
(427, 640, 3)
caer.transforms.darken(tens, darkness_coeff=- 1)[source]

Darken an image.

Parameters
  • tens (Tensor) – Any regular caer.Tensor.

  • darkness_coeff (int) – Coefficient value.

  • rgb (bool) – Operate on RGB images. Default: True.

Return type

Tensor

Returns

Tensor of shape (height, width, channels).

Examples:

>> tens = caer.data.sunrise(rgb=True)
>> filtered = caer.transforms.darken(tens, coeff=-1, rgb=True)
>> filtered
(427, 640, 3)
caer.transforms.equalize(tens, mask=None, by_channels=True)[source]

Equalize the image histogram.

Parameters
  • tens (Tensor) – RGB or grayscale image.

  • mask (Tensor) – An optional mask. If given, only the pixels selected by the mask are included in the analysis. Maybe 1 channel or 3 channel array.

  • by_channels (bool) – If True, use equalization by channels separately, else convert image to YCbCr representation and use equalization by Y channel.

Return type

Tensor

Returns

Equalized image (Tensor)

Examples:

>> tens = caer.data.beverages()
>> equalized = caer.equalize(tens, mask=None)
>> equalized.shape
(427,640,3)
caer.transforms.hflip(tens)[source]

Flip an image horizontally.

Parameters

tens (Tensor) – Image to be flipped.

Return type

Tensor

Returns

Flipped image.

caer.transforms.hvflip(tens)[source]

Flip an image both horizontally and vertically.

Parameters

tens (Tensor) – Image to be flipped.

Return type

Tensor

Returns

Flipped image.

caer.transforms.pad(tens, padding, fill=0, padding_mode='constant')[source]

Pad the given image on all sides with specified padding mode and fill value.

Parameters
  • tens (Tensor) – image to be padded.

  • padding (int or tuple) – Padding on each border. If a single int is provided this is used to pad all borders. If tuple of length 2 is provided this is the padding on left/right and top/bottom respectively. If a tuple of length 4 is provided this is the padding for the left, top, right and bottom borders respectively.

  • fill – Pixel fill value for constant fill. Default is 0. If a tuple of length 3, it is used to fill R, G, B channels respectively. This value is only used when the padding_mode is constant

  • padding_mode

    Type of padding. Should be: constant, edge, reflect or symmetric. Default is constant. - constant: pads with a constant value, this value is specified with fill - edge: pads with the last value on the edge of the image - reflect: pads with reflection of image (without repeating the last value on the edge)

    padding [1, 2, 3, 4] with 2 elements on both sides in reflect mode will result in [3, 2, 1, 2, 3, 4, 3, 2]

    • symmetric: pads with reflection of image (repeating the last value on the edge)

      padding [1, 2, 3, 4] with 2 elements on both sides in symmetric mode will result in [2, 1, 1, 2, 3, 4, 4, 3]

Return type

Tensor

Returns

Tensor of shape (height, width, channels).

caer.transforms.posterize(tens, bits)[source]

Reduce the number of bits for each color channel in the image.

Parameters
  • tens (Tensor) – Image to posterize.

  • bits (int) – Number of high bits. Must be in range [0, 8]

Return type

Tensor

Returns

Image with reduced color channels (Tensor)

Examples:

>> tens = caer.data.sunrise()
>> posterized = caer.posterize(tens, bits=4)
>> posterized.shape
(427,640,3)
caer.transforms.rand_flip(tens)[source]

Randomly flip an image vertically or horizontally.

Parameters

tens (Tensor) – Image to be flipped.

Return type

Tensor

Returns

Flipped image.

caer.transforms.random_brightness(tens)[source]

Add random brightness to an image.

Parameters

tens (Tensor) – Any regular caer.Tensor.

Return type

Tensor

Returns

Tensor of shape (height, width, channels).

Examples:

>> tens = caer.data.sunrise()
>> filtered = caer.transforms.random_brightness(tens, rgb=True)
>> filtered
(427, 640, 3)
caer.transforms.rotate(tens, angle, rotPoint=None)[source]

Rotates an given image by an angle around a particular rotation point (if provided) or centre otherwise.

Return type

Tensor

caer.transforms.sim_autumn(tens)[source]

Simulate autumn conditions on an image.

Parameters

tens (Tensor) – Any regular caer.Tensor.

Return type

Tensor

Returns

Tensor of shape (height, width, channels).

Examples:

>> tens = caer.data.sunrise
>> filtered = caer.filters.sim_autumn(tens)
>> filtered
(427, 640, 3)
caer.transforms.sim_fog(tens, fog_coeff=- 1)[source]

Simulate foggy conditions on an image.

Parameters
  • tens (Tensor) – Any regular caer.Tensor.

  • fog_coeff (int) – Coefficient value.

Return type

Tensor

Returns

Tensor of shape (height, width, channels).

Examples:

>> tens = caer.data.sunrise
>> filtered = caer.filters.sim_fog(tens, fog_coeff=-1)
>> filtered
(427, 640, 3)
caer.transforms.sim_gravel(tens, rectangular_roi=(- 1, - 1, - 1, - 1), num_patches=8)[source]

Simulate gravelly conditions on an image.

Parameters
  • tens (Tensor) – Any regular caer.Tensor.

  • rectangular_roi (tuple) – Rectanglar co-ordinates of the intended region of interest. Default: (-1,-1,-1,-1).

  • num_patches (int) – Number of patches to operate on.

Return type

Tensor

Returns

Tensor of shape (height, width, channels).

Examples:

>> tens = caer.data.sunrise
>> filtered = caer.filters.sim_gravel(tens)
>> filtered
(427, 640, 3)
caer.transforms.sim_motion_blur(tens, speed_coeff=- 1)[source]

Simulate motion-blur conditions on an image.

Parameters
  • tens (Tensor) – Any regular caer.Tensor.

  • speed_coeff (int, float) – Speed coefficient. Value must be between 0 and 1.

Return type

Tensor

Returns

Tensor of shape (height, width, channels).

Examples:

>> tens = caer.data.sunrise
>> filtered = caer.filters.sim_motion_blur(tens, speed_coeff=-1)
>> filtered
(427, 640, 3)
caer.transforms.sim_rain(tens, slant=- 1, drop_length=20, drop_width=1, drop_color=(200, 200, 200), rain_type='None')[source]

Simulate rainy conditions on an image.

Parameters
  • tens (Tensor) – Any regular caer.Tensor.

  • slant (int) – Slant value.

  • drop_length (int) – Length of the raindrop.

  • drop_width (int) – Width of the raindrop.

  • drop_color (tuple) – Color of the raindrop.

  • rain_type (str) – Type of rain. Can be either ‘drizzle’, ‘heavy’ or ‘torrential’.

Return type

Tensor

Returns

Tensor of shape (height, width, channels).

Examples:

>> tens = caer.data.sunrise
>> filtered = caer.filters.sim_rain(tens)
>> filtered
(427, 640, 3)
caer.transforms.sim_shadow(tens, num_shadows=1, rectangular_roi=(- 1, - 1, - 1, - 1), shadow_dimension=5)[source]

Simulate shadowy conditions on an image.

Parameters
  • tens (Tensor) – Any regular caer.Tensor.

  • num_shadows (int) – Number of shadows to work with. Value must be between 1 and 10.

  • rectangular_roi (tuple) – Rectanglar co-ordinates of the intended region of interest. Default: (-1,-1,-1,-1).

  • shadow_dimensions (int) – Number of shadow dimensions. Value must be > 3.

Return type

Tensor

Returns

Tensor of shape (height, width, channels).

Examples:

>> tens = caer.data.sunrise
>> filtered = caer.filters.sim_shadow(tens)
>> filtered
(427, 640, 3)
caer.transforms.sim_snow(tens, snow_coeff=- 1)[source]

Simulate snowy conditions on an image.

Parameters
  • tens (Tensor) – Any regular caer.Tensor.

  • snow_coeff (int) – Coefficient value.

Return type

Tensor

Returns

Tensor of shape (height, width, channels).

Examples:

>> tens = caer.data.sunrise
>> filtered = caer.filters.sim_snow(tens, snow_coeff=-1)
>> filtered
(427, 640, 3)
caer.transforms.sim_sun_flare(tens, flare_center=- 1, angle=- 1, num_flare_circles=8, src_radius=400, src_color=(255, 255, 255))[source]

Add a source of light (flare) on an specific region of an image.

Parameters
  • tens (Tensor) – Any regular caer.Tensor.

  • flare_center (int) – Center of the flare. Default: -1.

  • angle (int) – Angle of the flare. Default: -1

  • num_flare_circles (int) – Number of flare circles to operate on.

  • src_radius (int) – Intended size of the flare

  • src_color (tuple) – Intended source color of the flare

Return type

Tensor

Returns

Tensor of shape (height, width, channels).

Examples:

>> tens = caer.data.sunrise
>> filtered = caer.filters.sim_sun_flare(tens)
>> filtered
(427, 640, 3)
caer.transforms.solarize(tens, threshold=128)[source]

Invert all pixel values above a threshold.

Parameters
  • tens (Tensor) – The image to solarize.

  • threshold (int) – All pixels above this grayscale level are inverted.

Return type

Tensor

Returns

Solarized image (Tensor)

Examples:

>> tens = caer.data.sunrise()
>> solarized = caer.solarize(tens, threshold=128)
>> solarized.shape
(427,640,3)
caer.transforms.translate(image, x, y)[source]

Translates a given image across the x-axis and the y-axis

Parameters
  • x (int) – shifts the image right (positive) or left (negative)

  • y (int) – shifts the image down (positive) or up (negative)

Return type

Tensor

Returns

The translated image

caer.transforms.vflip(tens)[source]

Flip an image vertically.

Parameters

tens (Tensor) – Image to be flipped.

Return type

Tensor

Returns

Flipped image.

Read the Docs v: stable
Versions
latest
stable
Downloads
pdf
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.