Image.Squares#

classmethod Image.Squares(number: int, *, size: int | Sequence[int] | None = None, fg: Any = 1, bg: Any = 0, dtype: Dtype | None = None, colororder: str | None = None, like=None) Self[source]#

Create image containing grid of squares

Parameters:
  • number (int) – number of squares horizontally and vertically

  • size (int or 2-tuple, optional) – image size; scalar gives a square image, defaults to 256

  • fg (int, float, optional) – pixel value of the squares, defaults to 1

  • bg (int, optional) – pixel value of the background, defaults to 0

  • dtype (str or NumPy dtype, optional) – NumPy datatype, defaults to ‘uint8’

  • colororder (str or None, optional) – color plane names for the output image, defaults to None

  • like (Image or None, optional) – template image supplying default size, dtype and colororder when those are not given explicitly

Returns:

grid of squares

Return type:

Image

The image background is set to bg and the circles are filled with fg.

Example:

>>> from machinevisiontoolbox import Image
>>> img = Image.Squares(2, size=14, bg=1, fg=9)
>>> img.print()
   1 1 1 1 1 1 1 1 1 1 1 1 1 1
   1 1 1 1 1 1 1 1 1 1 1 1 1 1
   1 1 9 9 9 9 1 1 9 9 9 9 1 1
   1 1 9 9 9 9 1 1 9 9 9 9 1 1
   1 1 9 9 9 9 1 1 9 9 9 9 1 1
   1 1 9 9 9 9 1 1 9 9 9 9 1 1
   1 1 1 1 1 1 1 1 1 1 1 1 1 1
   1 1 1 1 1 1 1 1 1 1 1 1 1 1
   1 1 9 9 9 9 1 1 9 9 9 9 1 1
   1 1 9 9 9 9 1 1 9 9 9 9 1 1
   1 1 9 9 9 9 1 1 9 9 9 9 1 1
   1 1 9 9 9 9 1 1 9 9 9 9 1 1
   1 1 1 1 1 1 1 1 1 1 1 1 1 1
   1 1 1 1 1 1 1 1 1 1 1 1 1 1

number equal to 1, 2 and 8:

(Source code, png, hires.png, pdf)

../_images/machinevisiontoolbox-Image-Squares-1.png

Note

Image is square.