Image.Constant#

classmethod Image.Constant(value: Any = 0, *, colororder: str | None = None, dtype: Dtype | None = None, size: Sequence[int] | None = None, like=None) Self[source]#

Create image with all pixels having same value

Parameters:
  • value (scalar, array_like, str) – value for all pixels, defaults to 0

  • size (int or 2-tuple, optional) – image size, width x height, defaults to like.size if like is given

  • colororder (str) – color plane names, defaults to None

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

The short-name aliases 'int', 'float', 'double', 'half' are also accepted and resolve to the Toolbox’s own defaults (uint8, float32, float64, float16 respectively) – this matters because NumPy’s own np.dtype('float') resolves to float64, not float32. See DTYPE_ALIASES. :param like: template image supplying default size, dtype and

colororder when those are not given explicitly

Returns:

image of constant values

Return type:

Image

Creates a new image initialized to value. If value is iterable then the image has len(value) planes, each initialized to the corresponding element of value.

Example:

>>> from machinevisiontoolbox import Image
>>> Image.Constant(17, size=10).print()
   17 17 17 17 17 17 17 17 17 17
   17 17 17 17 17 17 17 17 17 17
   17 17 17 17 17 17 17 17 17 17
   17 17 17 17 17 17 17 17 17 17
   17 17 17 17 17 17 17 17 17 17
   17 17 17 17 17 17 17 17 17 17
   17 17 17 17 17 17 17 17 17 17
   17 17 17 17 17 17 17 17 17 17
   17 17 17 17 17 17 17 17 17 17
   17 17 17 17 17 17 17 17 17 17
>>> Image.Constant([100, 50, 200], size=(10, 20), colororder='RGB').print()
  plane R:
     100 100 100 100 100 100 100 100 100 100
     100 100 100 100 100 100 100 100 100 100
     100 100 100 100 100 100 100 100 100 100
     100 100 100 100 100 100 100 100 100 100
     100 100 100 100 100 100 100 100 100 100
     100 100 100 100 100 100 100 100 100 100
     100 100 100 100 100 100 100 100 100 100
     100 100 100 100 100 100 100 100 100 100
     100 100 100 100 100 100 100 100 100 100
     100 100 100 100 100 100 100 100 100 100
     100 100 100 100 100 100 100 100 100 100
     100 100 100 100 100 100 100 100 100 100
     100 100 100 100 100 100 100 100 100 100
     100 100 100 100 100 100 100 100 100 100
     100 100 100 100 100 100 100 100 100 100
     100 100 100 100 100 100 100 100 100 100
     100 100 100 100 100 100 100 100 100 100
     100 100 100 100 100 100 100 100 100 100
     100 100 100 100 100 100 100 100 100 100
     100 100 100 100 100 100 100 100 100 100
  plane G:
      50  50  50  50  50  50  50  50  50  50
      50  50  50  50  50  50  50  50  50  50
      50  50  50  50  50  50  50  50  50  50
      50  50  50  50  50  50  50  50  50  50
      50  50  50  50  50  50  50  50  50  50
      50  50  50  50  50  50  50  50  50  50
      50  50  50  50  50  50  50  50  50  50
      50  50  50  50  50  50  50  50  50  50
      50  50  50  50  50  50  50  50  50  50
      50  50  50  50  50  50  50  50  50  50
      50  50  50  50  50  50  50  50  50  50
      50  50  50  50  50  50  50  50  50  50
      50  50  50  50  50  50  50  50  50  50
      50  50  50  50  50  50  50  50  50  50
      50  50  50  50  50  50  50  50  50  50
      50  50  50  50  50  50  50  50  50  50
      50  50  50  50  50  50  50  50  50  50
      50  50  50  50  50  50  50  50  50  50
      50  50  50  50  50  50  50  50  50  50
      50  50  50  50  50  50  50  50  50  50
  plane B:
     200 200 200 200 200 200 200 200 200 200
     200 200 200 200 200 200 200 200 200 200
     200 200 200 200 200 200 200 200 200 200
     200 200 200 200 200 200 200 200 200 200
     200 200 200 200 200 200 200 200 200 200
     200 200 200 200 200 200 200 200 200 200
     200 200 200 200 200 200 200 200 200 200
     200 200 200 200 200 200 200 200 200 200
     200 200 200 200 200 200 200 200 200 200
     200 200 200 200 200 200 200 200 200 200
     200 200 200 200 200 200 200 200 200 200
     200 200 200 200 200 200 200 200 200 200
     200 200 200 200 200 200 200 200 200 200
     200 200 200 200 200 200 200 200 200 200
     200 200 200 200 200 200 200 200 200 200
     200 200 200 200 200 200 200 200 200 200
     200 200 200 200 200 200 200 200 200 200
     200 200 200 200 200 200 200 200 200 200
     200 200 200 200 200 200 200 200 200 200
     200 200 200 200 200 200 200 200 200 200
>>> Image.Constant(range(6), size=10, colororder='ABCDEF').print()
  plane A:
     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 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
     0 0 0 0 0 0 0 0 0 0
  plane B:
     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 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 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 1 1 1 1
  plane C:
     2 2 2 2 2 2 2 2 2 2
     2 2 2 2 2 2 2 2 2 2
     2 2 2 2 2 2 2 2 2 2
     2 2 2 2 2 2 2 2 2 2
     2 2 2 2 2 2 2 2 2 2
     2 2 2 2 2 2 2 2 2 2
     2 2 2 2 2 2 2 2 2 2
     2 2 2 2 2 2 2 2 2 2
     2 2 2 2 2 2 2 2 2 2
     2 2 2 2 2 2 2 2 2 2
  plane D:
     3 3 3 3 3 3 3 3 3 3
     3 3 3 3 3 3 3 3 3 3
     3 3 3 3 3 3 3 3 3 3
     3 3 3 3 3 3 3 3 3 3
     3 3 3 3 3 3 3 3 3 3
     3 3 3 3 3 3 3 3 3 3
     3 3 3 3 3 3 3 3 3 3
     3 3 3 3 3 3 3 3 3 3
     3 3 3 3 3 3 3 3 3 3
     3 3 3 3 3 3 3 3 3 3
  plane E:
     4 4 4 4 4 4 4 4 4 4
     4 4 4 4 4 4 4 4 4 4
     4 4 4 4 4 4 4 4 4 4
     4 4 4 4 4 4 4 4 4 4
     4 4 4 4 4 4 4 4 4 4
     4 4 4 4 4 4 4 4 4 4
     4 4 4 4 4 4 4 4 4 4
     4 4 4 4 4 4 4 4 4 4
     4 4 4 4 4 4 4 4 4 4
     4 4 4 4 4 4 4 4 4 4
  plane F:
     5 5 5 5 5 5 5 5 5 5
     5 5 5 5 5 5 5 5 5 5
     5 5 5 5 5 5 5 5 5 5
     5 5 5 5 5 5 5 5 5 5
     5 5 5 5 5 5 5 5 5 5
     5 5 5 5 5 5 5 5 5 5
     5 5 5 5 5 5 5 5 5 5
     5 5 5 5 5 5 5 5 5 5
     5 5 5 5 5 5 5 5 5 5
     5 5 5 5 5 5 5 5 5 5
>>> Image.Constant('lightgreen', size=10).print()
  plane R:
     144 144 144 144 144 144 144 144 144 144
     144 144 144 144 144 144 144 144 144 144
     144 144 144 144 144 144 144 144 144 144
     144 144 144 144 144 144 144 144 144 144
     144 144 144 144 144 144 144 144 144 144
     144 144 144 144 144 144 144 144 144 144
     144 144 144 144 144 144 144 144 144 144
     144 144 144 144 144 144 144 144 144 144
     144 144 144 144 144 144 144 144 144 144
     144 144 144 144 144 144 144 144 144 144
  plane G:
     238 238 238 238 238 238 238 238 238 238
     238 238 238 238 238 238 238 238 238 238
     238 238 238 238 238 238 238 238 238 238
     238 238 238 238 238 238 238 238 238 238
     238 238 238 238 238 238 238 238 238 238
     238 238 238 238 238 238 238 238 238 238
     238 238 238 238 238 238 238 238 238 238
     238 238 238 238 238 238 238 238 238 238
     238 238 238 238 238 238 238 238 238 238
     238 238 238 238 238 238 238 238 238 238
  plane B:
     144 144 144 144 144 144 144 144 144 144
     144 144 144 144 144 144 144 144 144 144
     144 144 144 144 144 144 144 144 144 144
     144 144 144 144 144 144 144 144 144 144
     144 144 144 144 144 144 144 144 144 144
     144 144 144 144 144 144 144 144 144 144
     144 144 144 144 144 144 144 144 144 144
     144 144 144 144 144 144 144 144 144 144
     144 144 144 144 144 144 144 144 144 144
     144 144 144 144 144 144 144 144 144 144

Note

If len(value) == 3 and colororder is not specified then RGB is assumed.

Seealso:

Zeros