machinevisiontoolbox.Image.Constant
- classmethod Image.Constant(w, h=None, value=0, colororder=None, dtype='uint8')
Create image with all pixels having same value
- Parameters:
w (int, (int, int)) – width, or (width, height)
h (int, optional) – height, defaults to None
value (scalar, array_like, str) – value for all pixels, defaults to 0
colororder (str) – color plane names, defaults to None
dtype (str, optional) – NumPy datatype, defaults to ‘uint8’
- Returns:
image of constant values
- Return type:
Image
Creates a new image initialized to
value
. Ifvalue
is iterable then the image haslen(value)
planes, each initialized to the corresponding element ofvalue
.Example:
>>> from machinevisiontoolbox import Image >>> img = Image.Constant(10, value=17) >>> img Image: 10 x 10 (uint8) >>> img.image[0, 0] 17 >>> img = Image.Constant(10, 20, [100, 50, 200], colororder='RGB') >>> img Image: 10 x 20 (uint8), R:G:B >>> img.image[0, 0, :] array([100, 50, 200], dtype=uint8) >>> img = Image.Constant(10, value=range(6), colororder='ABCDEF') >>> img Image: 10 x 10 (uint8), A:B:C:D:E:F >>> img.image[0, 0, :] array([0, 1, 2, 3, 4, 5], dtype=uint8) >>> img = Image.Constant(10, value='cyan') >>> img.image[0, 0, :] array([ 0, 255, 255], dtype=uint8)
- Note:
If
len(value) == 3
andcolororder
is not specified then RGB is assumed.- Seealso: