Shortcuts

mmedit.utils.img_utils

Module Contents

Functions

tensor2img(tensor[, out_type, min_max])

Convert torch Tensors into image numpy arrays.

reorder_image(img[, input_order])

Reorder images to 'HWC' order.

to_numpy(img[, dtype])

Convert data into numpy arrays of dtype.

get_box_info(pred_bbox, original_shape, final_size)

param pred_bbox

The bounding box for the instance

mmedit.utils.img_utils.tensor2img(tensor, out_type=np.uint8, min_max=(0, 1))[源代码]

Convert torch Tensors into image numpy arrays.

After clamping to (min, max), image values will be normalized to [0, 1].

For different tensor shapes, this function will have different behaviors:

  1. 4D mini-batch Tensor of shape (N x 3/1 x H x W):

    Use make_grid to stitch images in the batch dimension, and then convert it to numpy array.

  2. 3D Tensor of shape (3/1 x H x W) and 2D Tensor of shape (H x W):

    Directly change to numpy array.

Note that the image channel in input tensors should be RGB order. This function will convert it to cv2 convention, i.e., (H x W x C) with BGR order.

参数
  • tensor (Tensor | list[Tensor]) – Input tensors.

  • out_type (numpy type) – Output types. If np.uint8, transform outputs to uint8 type with range [0, 255]; otherwise, float type with range [0, 1]. Default: np.uint8.

  • min_max (tuple) – min and max values for clamp.

返回

3D ndarray of shape (H x W x C) or 2D ndarray of shape (H x W).

返回类型

(Tensor | list[Tensor])

mmedit.utils.img_utils.reorder_image(img, input_order='HWC')[源代码]

Reorder images to ‘HWC’ order.

If the input_order is (h, w), return (h, w, 1); If the input_order is (c, h, w), return (h, w, c); If the input_order is (h, w, c), return as it is.

参数
  • img (np.ndarray) – Input image.

  • input_order (str) – Whether the input order is ‘HWC’ or ‘CHW’. If the input image shape is (h, w), input_order will not have effects. Default: ‘HWC’.

返回

Reordered image.

返回类型

np.ndarray

mmedit.utils.img_utils.to_numpy(img, dtype=np.float64)[源代码]

Convert data into numpy arrays of dtype.

参数
  • img (Tensor | np.ndarray) – Input data.

  • dtype (np.dtype) – Set the data type of the output. Default: np.float64

返回

Converted numpy arrays data.

返回类型

img (np.ndarray)

mmedit.utils.img_utils.get_box_info(pred_bbox, original_shape, final_size)[源代码]
参数
  • pred_bbox – The bounding box for the instance

  • original_shape – Original image shape

  • final_size – Size of the final output

返回

[L_pad, R_pad, T_pad, B_pad, rh, rw]

返回类型

List

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

Free document hosting provided by Read the Docs.