Shortcuts

mmagic.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.

mmagic.datasets.transforms.matlab_like_resize.get_size_from_scale(input_size, scale_factor)[源代码]

Get the output size given input size and scale factor.

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

  • scale_factor (float) – The resize factor.

返回

The size of the output image.

返回类型

output_shape (list[int])

mmagic.datasets.transforms.matlab_like_resize.get_scale_from_size(input_size, output_size)[源代码]

Get the scale factor given input size and output size.

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

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

返回

The scale factor of each dimension.

返回类型

scale (list[float])

mmagic.datasets.transforms.matlab_like_resize._cubic(x)[源代码]

Cubic function.

参数

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

返回

The weight corresponding to a particular distance.

返回类型

np.ndarray

mmagic.datasets.transforms.matlab_like_resize.get_weights_indices(input_length, output_length, scale, kernel, kernel_width)[源代码]

Get weights and indices for interpolation.

参数
  • 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.

返回

The weights and the indices

for interpolation.

返回类型

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

mmagic.datasets.transforms.matlab_like_resize.resize_along_dim(img_in, weights, indices, dim)[源代码]

Resize along a specific dimension.

参数
  • 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.

返回

Interpolated (along one dimension) image.

返回类型

np.ndarray

class mmagic.datasets.transforms.matlab_like_resize.MATLABLikeResize(keys, scale=None, output_shape=None, kernel='bicubic', kernel_width=4.0)[源代码]

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”.

参数
  • 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)[源代码]

resize an image to the require size.

参数

img (np.ndarray) – The original image.

返回

The resized image.

返回类型

output (np.ndarray)

transform(results)[源代码]

transform function.

参数

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

返回

A dict containing the processed data and information.

返回类型

dict

__repr__()[源代码]

Return repr(self).

Read the Docs v: latest
Versions
latest
stable
0.x
Downloads
pdf
epub
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.