Image.rprint#

Image.rprint(**kwargs) Image[source][source]#

Print image pixels in compact format and return image

Parameters:
  • fmt (str, optional) – format string, defaults to None

  • separator (str, optional) – value separator, defaults to single space

  • precision (int, optional) – precision for floating point pixel values, defaults to 2

  • header (bool, optional) – print image summary header, defaults to True

  • file (file, optional) – file to print to, defaults to None

Returns:

the printed image

Return type:

Image

Very compact display of pixel numerical values in grid layout and return the image itself.

Example:

>>> from machinevisiontoolbox import Image
>>> img = Image.Squares(1, size=10).rprint()
   0 0 0 0 0 0 0 0 0 0
   0 0 0 0 0 0 0 0 0 0
   0 0 1 1 1 1 1 1 0 0
   0 0 1 1 1 1 1 1 0 0
   0 0 1 1 1 1 1 1 0 0
   0 0 1 1 1 1 1 1 0 0
   0 0 1 1 1 1 1 1 0 0
   0 0 1 1 1 1 1 1 0 0
   0 0 0 0 0 0 0 0 0 0
   0 0 0 0 0 0 0 0 0 0
>>> print(img)
Image: 10 x 10 (uint8), 1 anonymous plane
  span=[0, 1]; mean=0.36, 𝜎=0.48; median=0
>>> img = Image.Squares(1, size=10, dtype='float').rprint(precision=1, header=True)
Image: 10 x 10 (float32), 1 anonymous plane
  span=[0, 1]; mean=0.36, 𝜎=0.48; median=0
   0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
   0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
   0.0 0.0 1.0 1.0 1.0 1.0 1.0 1.0 0.0 0.0
   0.0 0.0 1.0 1.0 1.0 1.0 1.0 1.0 0.0 0.0
   0.0 0.0 1.0 1.0 1.0 1.0 1.0 1.0 0.0 0.0
   0.0 0.0 1.0 1.0 1.0 1.0 1.0 1.0 0.0 0.0
   0.0 0.0 1.0 1.0 1.0 1.0 1.0 1.0 0.0 0.0
   0.0 0.0 1.0 1.0 1.0 1.0 1.0 1.0 0.0 0.0
   0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
   0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
>>> print(img)
Image: 10 x 10 (float32), 1 anonymous plane
  span=[0, 1]; mean=0.36, 𝜎=0.48; median=0

The function returns the image, which is why we see the image repr value after the printed pixels in this python intrepreter.

The rprint method is particularly useful in a method chain, for example:

>>> from machinevisiontoolbox import Image
>>> img = Image.Random(size=3).rprint()
    81  82 216
   205  54  16
   197  79 195
>>> print(img) # return result of print() is the image itself
Image: 3 x 3 (uint8), 1 anonymous plane
  span=[16, 216]; mean=125, 𝜎=72.7156; median=82

Note

  • For a boolean image True and False are displayed as 1 and 0 respectively.

  • For a multiplane images the planes are printed sequentially, along with the plane’s name.

Seealso:

print Image.strhcat Image.showpixels