machinevisiontoolbox.Image.Random
- classmethod Image.Random(w, h=None, value=0, colororder=None, dtype='uint8', maxval=None)
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’
maxval (same as
dtype
, optional) – maximum value for random values, defaults to None
- 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([[ 6, 183, 20, 156, 215], [146, 99, 217, 194, 196], [ 77, 171, 180, 165, 227], [242, 83, 181, 65, 37], [ 49, 113, 83, 151, 247]], dtype=uint8) >>> img = Image.Random(5, colororder='RGB') >>> img Image: 5 x 5 (uint8), R:G:B >>> img.red().image array([[ 10, 88, 41, 239, 15], [188, 149, 249, 130, 70], [242, 253, 182, 54, 214], [ 39, 146, 76, 249, 186], [ 56, 142, 128, 7, 42]], dtype=uint8) >>> img = Image.Random(5, dtype='float32') >>> img.image array([[0.614 , 0.4037, 0.0528, 0.4219, 0.766 ], [0.8846, 0.3887, 0.9282, 0.1643, 0.2722], [0.9729, 0.3573, 0.3563, 0.2636, 0.4312], [0.6737, 0.304 , 0.3599, 0.6381, 0.0614], [0.7345, 0.3377, 0.6564, 0.9865, 0.3899]], dtype=float32)