Shortcuts

mmedit.datasets.transforms.matlab_like_resize

Module Contents

Classes

MATLABLikeResize

Resize the input image using MATLAB-like downsampling.

Functions

get_size_from_scale(input_size, scale_factor)

Get the output size given input size and scale factor.

get_scale_from_size(input_size, output_size)

Get the scale factor given input size and output size.

_cubic(x)

Cubic function.

get_weights_indices(input_length, output_length, ...)

Get weights and indices for interpolation.

resize_along_dim(img_in, weights, indices, dim)

Resize along a specific dimension.

mmedit.datasets.transforms.matlab_like_resize.get_size_from_scale(input_size, scale_factor)[source]

Get the output size given input size and scale factor.

Parameters
  • input_size (tuple) – The size of the input image.

  • scale_factor (float) – The resize factor.

Returns

The size of the output image.

Return type

output_shape (list[int])

mmedit.datasets.transforms.matlab_like_resize.get_scale_from_size(input_size, output_size)[source]

Get the scale factor given input size and output size.

Parameters
  • input_size (tuple(int)) – The size of the input image.

  • output_size (tuple(int)) – The size of the output image.

Returns

The scale factor of each dimension.

Return type

scale (list[float])

mmedit.datasets.transforms.matlab_like_resize._cubic(x)[source]

Cubic function.

Parameters

x (np.ndarray) – The distance from the center position.

Returns

The weight corresponding to a particular distance.

Return type

np.ndarray

mmedit.datasets.transforms.matlab_like_resize.get_weights_indices(input_length, output_length, scale, kernel, kernel_width)[source]

Get weights and indices for interpolation.

Parameters
  • input_length (int) – Length of the input sequence.

  • output_length (int) – Length of the output sequence.

  • scale (float) – Scale factor.

  • kernel (func) – The kernel used for resizing.

  • kernel_width (int) – The width of the kernel.

Returns

The weights and the indices

for interpolation.

Return type

tuple(list[np.ndarray], list[np.ndarray])

mmedit.datasets.transforms.matlab_like_resize.resize_along_dim(img_in, weights, indices, dim)[source]

Resize along a specific dimension.

Parameters
  • img_in (np.ndarray) – The input image.

  • weights (ndarray) – The weights used for interpolation, computed from [get_weights_indices].

  • indices (ndarray) – The indices used for interpolation, computed from [get_weights_indices].

  • dim (int) – Which dimension to undergo interpolation.

Returns

Interpolated (along one dimension) image.

Return type

np.ndarray

class mmedit.datasets.transforms.matlab_like_resize.MATLABLikeResize(keys, scale=None, output_shape=None, kernel='bicubic', kernel_width=4.0)[source]

Bases: mmcv.transforms.BaseTransform

Resize the input image using MATLAB-like downsampling.

Currently support bicubic interpolation only. Note that the output of this function is slightly different from the official MATLAB function.

Required keys are the keys in attribute “keys”. Added or modified keys are “scale” and “output_shape”, and the keys in attribute “keys”.

Parameters
  • keys (list[str]) – A list of keys whose values are modified.

  • scale (float | None, optional) – The scale factor of the resize operation. If None, it will be determined by output_shape. Default: None.

  • output_shape (tuple(int) | None, optional) – The size of the output image. If None, it will be determined by scale. Note that if scale is provided, output_shape will not be used. Default: None.

  • kernel (str, optional) – The kernel for the resize operation. Currently support ‘bicubic’ only. Default: ‘bicubic’.

  • kernel_width (float) – The kernel width. Currently support 4.0 only. Default: 4.0.

_resize(img)[source]

resize an image to the require size.

Parameters

img (np.ndarray) – The original image.

Returns

The resized image.

Return type

output (np.ndarray)

transform(results)[source]

transform function.

Parameters

results (dict) – A dict containing the necessary information and data for augmentation.

Returns

A dict containing the processed data and information.

Return type

dict

__repr__()[source]

Return repr(self).

Read the Docs v: latest
Versions
master
latest
stable
zyh-re-docs
zyh-doc-notfound-extend
zyh-api-rendering
Downloads
pdf
epub
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.