machinevisiontoolbox.Image.Random

classmethod Image.Random(w, h=None, value=0, colororder=None, dtype='uint8')

Create image with random pixel values

Parameters:
  • w (int, (int, int)) – width, or (width, height)

  • h (int, optional) – height, defaults to None

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

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

Returns:

image of random values

Return type:

Image

Creates a new image where pixels are initialized to uniformly distributed random values. For an integer image the values span the range 0 to the maximum positive value of the datatype. For a floating image the values span the range 0.0 to 1.0.

Example:

>>> from machinevisiontoolbox import Image
>>> img = Image.Random(5)
>>> img
Image: 5 x 5 (uint8)
>>> img.image
array([[190, 193,  66, 207,  25],
       [ 82, 193, 203, 250, 195],
       [ 12,  81,  88, 252, 102],
       [ 91, 125, 164,  66,  43],
       [220, 157, 249, 138, 114]], dtype=uint8)
>>> img = Image.Random(5, colororder='RGB')
>>> img
Image: 5 x 5 (uint8), R:G:B
>>> img.red().image
array([[181, 105, 153,  23,  29],
       [  6, 136, 212,  84,  65],
       [202, 206, 150, 164,   6],
       [ 83, 115, 192,  87, 152],
       [205,  55,  27, 158,  66]], dtype=uint8)
>>> img = Image.Random(5, dtype='float32')
>>> img.image
array([[0.929 , 0.0643, 0.6713, 0.7745, 0.8872],
       [0.1942, 0.5624, 0.3383, 0.7688, 0.8692],
       [0.3723, 0.4603, 0.8692, 0.6489, 0.7662],
       [0.5377, 0.6292, 0.1437, 0.6272, 0.6601],
       [0.6796, 0.1297, 0.2107, 0.8418, 0.4344]])