imresize¶

imresize(img, scale_factor=None, output_size=None, interpolation='optimise')[source]¶

Resize input image.

Parameters:
  • img (numpy.ndarray) – Input image, assumed to be in HxWxC or HxW format.

  • scale_factor (float or Tuple[float, float]) – Scaling factor to resize the input image.

  • output_size (tuple(int)) – Output image size, (width, height).

  • interpolation (str or int) – Interpolation method used to interpolate the image using opencv interpolation flags default=’optimise’, uses cv2.INTER_AREA for scale_factor <1.0 otherwise uses cv2.INTER_CUBIC.

Returns:

Resized image. The image may be of different np.dtype

compared to the input image. However, the numeric precision is ensured.

Return type:

numpy.ndarray

Examples

>>> from tiatoolbox.wsicore import wsireader
>>> from tiatoolbox.utils import transforms
>>> wsi = wsireader.WSIReader(input_path="./CMU-1.ndpi")
>>> slide_thumbnail = wsi.slide_thumbnail()
>>> # Resize the image to half size using scale_factor 0.5
>>> transforms.imresize(slide_thumbnail, scale_factor=0.5)