mmagic.datasets.transforms.matlab_like_resize
¶
Module Contents¶
Classes¶
Resize the input image using MATLAB-like downsampling. |
Functions¶
|
Get the output size given input size and scale factor. |
|
Get the scale factor given input size and output size. |
|
Cubic function. |
|
Get weights and indices for interpolation. |
|
Resize along a specific dimension. |
- mmagic.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])
- mmagic.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])
- mmagic.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
- mmagic.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])
- mmagic.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 mmagic.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)