Shortcuts

caer.io

Reading Images

imread

caer.io.imread(image_path, rgb=True, target_size=None, resize_factor=None, preserve_aspect_ratio=False, interpolation='bilinear')[source]

Loads in an image from image_path (can be either a system filepath or a URL)

Parameters
  • image_path (str) – Filepath/URL to read the image from.

  • rgb (bool) – Boolean to keep RGB ordering. Default: True

Return type

Tensor

Returns

Tensor with shape (height, width, channels).

Examples:

>> tens = caer.imread(tens_path) # From FilePath
>> tens.shape
(427, 640, 3)

>> tens = caer.imread('https://raw.githubusercontent.com/jasmcaus/caer/master/caer/data/beverages.jpg') # From URL
>> tens.shape
(427, 640, 3)

Saving Images

imsave

caer.io.imsave(path, tens)[source]

Saves a Tensor to path

Parameters

path (str) – Filepath to save the image to

Returns

True; if tens was written to path False; otherwise

Examples:

>> tens = caer.data.audio_mixer()
>> caer.imsave('audio_mixer.png', tens)
True
Return type

bool


Resizing Images

imread

caer.io.resize(tens, target_size=None, resize_factor=None, preserve_aspect_ratio=False, interpolation='bilinear')[source]

Resizes an image to a target_size without aspect ratio distortion.

Your output images will be of size target_size, and will not be distorted. Instead, the parts of the image that do not fit within the target size get cropped out.

The resizing process is: 1. Resize the image as minimally as possible. 2. Take the largest centered crop of the image with dimensions = target_size.

Alternatively, you may use: `python size = (200,200) tens = caer.resize(tens, target_size=size, preserve_aspect_ratio=True) `

Note

caer.imread() comes with an in-built functionality to resize your images, eliminating the need for you to call caer.resize(). This is purely optional and may appeal to certain users.

You may also use caer.smart_resize() for on-the-fly image resizing that preserves the aspect ratio.

Parameters
  • tens (Tensor) – Input Image. Must be in the format (height, width, channels).

  • target_size (tuple) – Target size. Must be a tuple of (width, height) integer.

  • resize_factor (float, tuple) – Resizing Factor to employ. Shrinks the image if resize_factor < 1 Enlarges the image if resize_factor > 1

  • preserve_aspect_ratio (bool) – Prevent aspect ratio distortion (employs center crop).

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

Returns

Tensor of shape (height, width, channels).

Examples:

>> tens = caer.data.sunrise()
>> tens.shape
(427, 640, 3)

>> resized = caer.resize(tens, target_size=(200,200)) # Hard-resize. May distort aspect ratio
>> resized.shape
(200, 200, 3)

>> resized_wf = caer.resize(tens, resize_factor=.5) # Resizes the image to half its dimensions
>> resized_wf.shape
(213, 320, 3)

>> resized = caer.resize(tens, target_size=(200,200), preserve_aspect_ratio=True) # Preserves aspect ratio
>> resized.shape
(200, 200, 3)

Smart Resizing

smart_resize

caer.io.smart_resize(tens, target_size, interpolation='bilinear')[source]

Resizes an image to a target_size without aspect ratio distortion.

Your output images will be of size target_size, and will not be distorted. Instead, the parts of the image that do not fit within the target size get cropped out.

The resizing process is: 1. Resize the image as minimally as possible. 2. Take the largest centered crop of the image with dimensions = target_size.

Alternatively, you may use: `python size = (200,200) tens = caer.resize(tens, target_size=size, preserve_aspect_ratio=True) `

Parameters
  • tens (Tensor) – Input Image. Must be in the format (height, width, channels).

  • target_size (tuple) – Target size. Must be a tuple of (width, height) integer.

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

Returns

Tensor of shape (height, width, channels)

Examples:

>> tens = caer.data.sunrise()
>> tens.shape
(427, 640, 3)
>> resized = caer.smart_resize(tens, target_size=(200,200))
>> resized.shape
(200, 200, 3)
Read the Docs v: latest
Versions
latest
stable
Downloads
pdf
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.