Skip to main content

taichi.tools.image#

taichi.tools.image.imread(filename, channels=0)#

Load image from a specific file.

Parameters:
  • filename (str) – An image filename to load from.

  • channels (int, optional) – The channels hint of input image, Default to 0.

Returns:

An output image loaded from given filename.

Return type:

np.ndarray

taichi.tools.image.imresize(img, w, h=None)#

Resize an image to a specific size.

Parameters:
  • img (Union[ti.field, np.ndarray]) – A field of of array with shape (width, height, …)

  • w (int) – The output width after resize.

  • h (int, optional) – The output height after resize, will be the same as width if not set. Default to None.

Returns:

An output image after resize input.

Return type:

np.ndarray

taichi.tools.image.imshow(img, title='imshow')#

Display a taichi.field or a numpy.ndarray in a Taichi GUI window or an interactive Ipython notebook. For an interactive Ipython environment, the image will be shown in the notebook.

Parameters:
  • img (Union[ti.field, np.ndarray]) – A field of of array with shape (width, height) or (height, width, 3) or (height, width, 4).

  • title (str, optional) – The title of GUI window. Default to imshow.

taichi.tools.image.imwrite(img, filename)#

Save a field to a a specific file.

Parameters:
  • img (Union[ti.field, np.ndarray]) – A field of shape (height, width) or (height, width, 3) or (height, width, 4), if dtype is float-type (ti.f16, ti.f32, np.float32 etc), the value of each pixel should be float between [0.0, 1.0]. Otherwise ti.tools.imwrite will first clip them into [0.0, 1.0] if dtype is int-type (ti.u8, ti.u16, np.uint8 etc), , the value of each pixel can be any valid integer in its own bounds. These integers in this field will be scaled to [0, 255] by being divided over the upper bound of its basic type accordingly.

  • filename (str) – The filename to save to.