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([[149, 107, 104,  80, 126],
       [ 36, 149, 111, 241,  98],
       [245, 113, 232, 169,  36],
       [189, 222,  55, 171,  81],
       [198, 220, 166, 162, 226]], dtype=uint8)
>>> img = Image.Random(5, colororder='RGB')
>>> img
Image: 5 x 5 (uint8), R:G:B
>>> img.red().image
array([[ 74,  90, 118, 105, 252],
       [218, 107,  63, 192,  18],
       [ 37,  79,  19,  77, 137],
       [ 35, 220,  65, 176, 180],
       [199, 202, 134, 154, 104]], dtype=uint8)
>>> img = Image.Random(5, dtype='float32')
>>> img.image
array([[0.8085, 0.5285, 0.3004, 0.5926, 0.3087],
       [0.5023, 0.1676, 0.3989, 0.6207, 0.6714],
       [0.3741, 0.3239, 0.8079, 0.8162, 0.0101],
       [0.6854, 0.1802, 0.162 , 0.8103, 0.5199],
       [0.583 , 0.3049, 0.2203, 0.8467, 0.8453]])