Python API¶
This section includes information for using the pure Python API of
bob.ip.color
.

bob.ip.color.
gray_to_rgb
()¶  gray_to_rgb(input, output) > output
 gray_to_rgb(y) > r, g, b
Converts a gray pixel or a full array (image) to RGB
This function converts a gray pixel or a gray array representing an image to a monochrome colored equivalent. This method is implemented for completeness and is equivalent to replicating the Y pixel value over the three RGB bands.
The input is expected to be either an array or a scalar. If you input an array, it is expected to assume the shape
(height, width)
, representing an image encoded in gray scale, with the specifiedheight
andwidth
. If you input a single scalar, it defines the value of Y in a discrete way.The output array may be optionally provided. In such a case, it should be a 3D array with the same number of columns and rows as the input, and have have the same data type. The number of color planes (first dimension) of such array should be
3
. If an output array is not provided, one will be allocated internally. In any case, the output array is always returned.If the input is of scalar type, this method will return a tuple with the 3 discrete values for red, green and blue.
Note
This method only supports arrays and scalars of the following data types:
numpy.uint8
numpy.uint16
numpy.float64
(or the native pythonfloat
)
 To create an object with a scalar type that will be accepted by this
 method, use a construction like the following:
>> import numpy >> y = numpy.uint8(32)
Parameters:
input
: array_like (uint8uint16float64, 2D)Input array containing an image with the shape(height, width)
output
: array (uint8uint16float64, 3D), optionalOutput array  if provided, should have matching data type toinput
. The shape should be(3, height, width)
y
: scalar (uint8uint16float64)The grayscale pixel scalar you wish to convert into an RGB tupleReturns:
output
: array (uint8uint16float64, 3D)Theoutput
array is returned by the function. If one was not provided, a new one is allocated internallyr, g, b
: scalar (uint8uint16float64)Discrete pixel values for the red, green and blue channels

bob.ip.color.
hsl_to_rgb
()¶  hsl_to_rgb(input, output) > output
 hsl_to_rgb(h, s, l) > r, g, b
Converts an HSL colorcoded pixel or a full array (image) to RGB
This function converts an HSL array or colorcoded pixel (http://en.wikipedia.org/wiki/HSL_and_HSL) to RGB.
The input is expected to be either an array or scalars. If you input an array, it is expected to assume the shape
(3, height, width)
, representing an image encoded in HSL, in this order, with the specifiedheight
andwidth
. The output array may be optionally provided. In such a case, it should be a 3D array with the same dimensions as the input, and have have the same data type. If an output array is not provided, one will be allocated internally. In any case, the output array is always returned.If the input is of scalar type, this method will return the HSL version for a pixel with the 3 discrete values for red, green and blue. The input in this case should consist of 3 scalars defining the discrete values of H, S and L.
Note
If you provide python scalars, then you should provide 3 values that share the same scalar type. Type mixing will raise a
TypeError
exception.Note
This method only supports arrays and scalars of the following data types:
numpy.uint8
numpy.uint16
numpy.float64
(or the native pythonfloat
)
 To create an object with a scalar type that will be accepted by this
 method, use a construction like the following:
>> import numpy >> r = numpy.uint8(32)
Parameters:
input
: array_like (uint8uint16float64, 3D)Input array containing an image with the shape(3, height, width)
output
: array (uint8uint16float64, 2D), optionalOutput array  if provided, should have matching data type toinput
. The shape should match theinput
shapeh, s, l
: scalar (uint8uint16float64)Discrete pixel values for H, S and L channelsReturns:
output
: array (uint8uint16float64, 2D)Theoutput
array is returned by the function. If one was not provided, a new one is allocated internallyr, g, b
: scalar (uint8uint16float64)Three scalars are returned when this function is fed discrete HSL values. The types match the input pixel values

bob.ip.color.
hsv_to_rgb
()¶  hsv_to_rgb(input, output) > output
 hsv_to_rgb(h, s, v) > r, g, b
Converts an HSV colorcoded pixel or a full array (image) to RGB
This function converts an HSV array or colorcoded pixel (http://en.wikipedia.org/wiki/HSL_and_HSV) to RGB.
The input is expected to be either an array or scalars. If you input an array, it is expected to assume the shape
(3, height, width)
, representing an image encoded in HSV, in this order, with the specifiedheight
andwidth
. The output array may be optionally provided. In such a case, it should be a 3D array with the same dimensions as the input, and have have the same data type. If an output array is not provided, one will be allocated internally. In any case, the output array is always returned.If the input is of scalar type, this method will return the HSV version for a pixel with the 3 discrete values for red, green and blue. The input in this case should consist of 3 scalars defining the discrete values of H, S and V.
Note
If you provide python scalars, then you should provide 3 values that share the same scalar type. Type mixing will raise a
TypeError
exception.Note
This method only supports arrays and scalars of the following data types:
numpy.uint8
numpy.uint16
numpy.float64
(or the native pythonfloat
)
 To create an object with a scalar type that will be accepted by this
 method, use a construction like the following:
>> import numpy >> r = numpy.uint8(32)
Parameters:
input
: array_like (uint8uint16float64, 3D)Input array containing an image with the shape(3, height, width)
output
: array (uint8uint16float64, 2D), optionalOutput array  if provided, should have matching data type toinput
. The shape should match theinput
shapeh, s, v
: scalar (uint8uint16float64)Discrete pixel values for H, S and V channelsReturns:
output
: array (uint8uint16float64, 2D)Theoutput
array is returned by the function. If one was not provided, a new one is allocated internallyr, g, b
: scalar (uint8uint16float64)Three scalars are returned when this function is fed discrete HSV values. The types match the input pixel values

bob.ip.color.
rgb_to_gray
()¶  rgb_to_gray(input, output) > output
 rgb_to_gray(r, g, b) > y
Converts an RGB colorcoded pixel or a full array (image) to grayscale
This function converts an RGB colorcoded pixel or a full RGB array to grayscale using the CCIR 601 (Kb = 0.114, Kr = 0.299) norm (http://www.fourcc.org/fccyvrgb.php). It returns only the gray value (Y component) in the desired data format. This method is more efficient than calling
rgb_to_yuv()
method just to extract the Y component.The input is expected to be either an array or scalars. If you input an array, it is expected to assume the shape
(3, height, width)
, representing an image encoded in RGB, in this order, with the specifiedheight
andwidth
; or a set of 3 scalars defining the input R, G and B in a discrete way. The output array may be optionally provided. In such a case, it should be a 2D array with the same number of columns and rows as the input, and have have the same data type. If an output array is not provided, one will be allocated internally. In any case, the output array is always returned.If the input is of scalar type, this method will return the grayscaled version for a pixel with the 3 discrete values for red, green and blue.
Note
If you provide python scalars, then you should provide 3 values that share the same scalar type. Type mixing will raise a
TypeError
exception.Note
This method only supports arrays and scalars of the following data types:
numpy.uint8
numpy.uint16
numpy.float64
(or the native pythonfloat
)
 To create an object with a scalar type that will be accepted by this
 method, use a construction like the following:
>> import numpy >> r = numpy.uint8(32)
Parameters:
input
: array_like (uint8uint16float64, 3D)Input array containing an image with the shape(3, height, width)
output
: array (uint8uint16float64, 2D), optionalOutput array  if provided, should have matching data type toinput
. The shape should be(height, width)
r, g, b
: scalar (uint8uint16float64)Discrete pixel values for the red, green and blue channelsReturns:
output
: array_like (uint8uint16float64, 2D)Theoutput
array is returned by the function. If one was not provided, a new one is allocated internallyy
: scalar (uint8uint16float64)A scalar is returned when this function is fed discrete RGB values. The type matches the input pixel values

bob.ip.color.
rgb_to_hsl
()¶  rgb_to_hsl(input, output) > output
 rgb_to_hsl(r, g, b) > h, s, l
Converts an RGB colorcoded pixel or a full array (image) to HSL
This function converts an RGB colorcoded pixel or a full RGB array to HSL (http://en.wikipedia.org/wiki/HSL_and_HSL).
The input is expected to be either an array or scalars. If you input an array, it is expected to assume the shape
(3, height, width)
, representing an image encoded in RGB, in this order, with the specifiedheight
andwidth
. The output array may be optionally provided. In such a case, it should be a 3D array with the same dimensions as the input, and have have the same data type. If an output array is not provided, one will be allocated internally. In any case, the output array is always returned.If the input is of scalar type, this method will return the HSL version for a pixel with the 3 discrete values for H, S and L. The input in this case should consist of 3 scalars defining the discrete values of R, G and B.
Note
If you provide python scalars, then you should provide 3 values that share the same scalar type. Type mixing will raise a
TypeError
exception.Note
This method only supports arrays and scalars of the following data types:
numpy.uint8
numpy.uint16
numpy.float64
(or the native pythonfloat
)
 To create an object with a scalar type that will be accepted by this
 method, use a construction like the following:
>> import numpy >> r = numpy.uint8(32)
Parameters:
input
: array_like (uint8uint16float64, 3D)Input array containing an image with the shape(3, height, width)
output
: array (uint8uint16float64, 2D), optionalOutput array  if provided, should have matching data type toinput
. The shape should match theinput
shaper, g, b
: scalar (uint8uint16float64)Discrete pixel values for the red, green and blue channelsReturns:
output
: array (uint8uint16float64, 2D)Theoutput
array is returned by the function. If one was not provided, a new one is allocated internallyh, s, l
: scalar (uint8uint16float64)Three scalars are returned when this function is fed discrete RGB values. The types match the input pixel values

bob.ip.color.
rgb_to_hsv
()¶  rgb_to_hsv(input, output) > output
 rgb_to_hsv(r, g, b) > h, s, v
Converts an RGB colorcoded pixel or a full array (image) to HSV
This function converts an RGB colorcoded pixel or a full RGB array to HSV (http://en.wikipedia.org/wiki/HSL_and_HSV).
The input is expected to be either an array or scalars. If you input an array, it is expected to assume the shape
(3, height, width)
, representing an image encoded in RGB, in this order, with the specifiedheight
andwidth
. The output array may be optionally provided. In such a case, it should be a 3D array with the same dimensions as the input, and have have the same data type. If an output array is not provided, one will be allocated internally. In any case, the output array is always returned.If the input is of scalar type, this method will return the HSV version for a pixel with the 3 discrete values for H, S and V. The input in this case should consist of 3 scalars defining the discrete values of R, G and B.
Note
If you provide python scalars, then you should provide 3 values that share the same scalar type. Type mixing will raise a
TypeError
exception.Note
This method only supports arrays and scalars of the following data types:
numpy.uint8
numpy.uint16
numpy.float64
(or the native pythonfloat
)
 To create an object with a scalar type that will be accepted by this
 method, use a construction like the following:
>> import numpy >> r = numpy.uint8(32)
Parameters:
input
: array_like (uint8uint16float64, 3D)Input array containing an image with the shape(3, height, width)
output
: array (uint8uint16float64, 2D), optionalOutput array  if provided, should have matching data type toinput
. The shape should match theinput
shaper, g, b
: scalar (uint8uint16float64)Discrete pixel values for the red, green and blue channelsReturns:
output
: array (uint8uint16float64, 2D)Theoutput
array is returned by the function. If one was not provided, a new one is allocated internallyh, s, v
: scalar (uint8uint16float64)Three scalars are returned when this function is fed discrete RGB values. The types match the input pixel values

bob.ip.color.
rgb_to_yuv
()¶  rgb_to_yuv(input, output) > output
 rgb_to_yuv(r, g, b) > y, u, v
Converts an RGB colorcoded pixel or a full array (image) to YUV
This function converts an RGB colorcoded pixel or a full RGB array to YUV (Y’CbCr) using the CCIR 601 (Kb = 0.114, Kr = 0.299) norm (http://www.fourcc.org/fccyvrgb.php).
The input is expected to be either an array or scalars. If you input an array, it is expected to assume the shape
(3, height, width)
, representing an image encoded in RGB, in this order, with the specifiedheight
andwidth
. The output array may be optionally provided. In such a case, it should be a 3D array with the same dimensions as the input, and have have the same data type. If an output array is not provided, one will be allocated internally. In any case, the output array is always returned.If the input is of scalar type, this method will return the YUV version for a pixel with the 3 discrete values for Y, U (Cb) and V (Cr). The input in this case should consist of 3 scalars defining the discrete values of R, G and B.
Note
If you provide python scalars, then you should provide 3 values that share the same scalar type. Type mixing will raise a
TypeError
exception.Note
This method only supports arrays and scalars of the following data types:
numpy.uint8
numpy.uint16
numpy.float64
(or the native pythonfloat
)
 To create an object with a scalar type that will be accepted by this
 method, use a construction like the following:
>> import numpy >> r = numpy.uint8(32)
Parameters:
input
: array_like (uint8uint16float64, 3D)Input array containing an image with the shape(3, height, width)
output
: array (uint8uint16float64, 2D), optionalOutput array  if provided, should have matching data type toinput
. The shape should match theinput
shaper, g, b
: scalar (uint8uint16float64)Discrete pixel values for the red, green and blue channelsReturns:
output
: array (uint8uint16float64, 2D)Theoutput
array is returned by the function. If one was not provided, a new one is allocated internallyy, u, v
: scalar (uint8uint16float64)Three scalars are returned when this function is fed discrete RGB values. The types match the input pixel values

bob.ip.color.
yuv_to_rgb
()¶  yuv_to_rgb(input, output) > output
 yuv_to_rgb(y, u, v) > r, g, b
Converts an YUV colorcoded pixel or a full array (image) to RGB
This function converts an YUV (Y’CbCr) array or colorcoded pixel using the CCIR 601 (Kb = 0.114, Kr = 0.299) norm (http://www.fourcc.org/fccyvrgb.php) to RGB.
The input is expected to be either an array or scalars. If you input an array, it is expected to assume the shape
(3, height, width)
, representing an image encoded in YUV, in this order, with the specifiedheight
andwidth
. The output array may be optionally provided. In such a case, it should be a 3D array with the same dimensions as the input, and have have the same data type. If an output array is not provided, one will be allocated internally. In any case, the output array is always returned.If the input is of scalar type, this method will return the YUV version for a pixel with the 3 discrete values for red, green and blue. The input in this case should consist of 3 scalars defining the discrete values of Y, U and V.
Note
If you provide python scalars, then you should provide 3 values that share the same scalar type. Type mixing will raise a
TypeError
exception.Note
This method only supports arrays and scalars of the following data types:
numpy.uint8
numpy.uint16
numpy.float64
(or the native pythonfloat
)
 To create an object with a scalar type that will be accepted by this
 method, use a construction like the following:
>> import numpy >> r = numpy.uint8(32)
Parameters:
input
: array_like (uint8uint16float64, 3D)Input array containing an image with the shape(3, height, width)
output
: array (uint8uint16float64, 2D), optionalOutput array  if provided, should have matching data type toinput
. The shape should match theinput
shapey, u, v
: scalar (uint8uint16float64)Discrete pixel values for Y, U (Cb) and V (Cr) channelsReturns:
output
: array (uint8uint16float64, 2D)Theoutput
array is returned by the function. If one was not provided, a new one is allocated internallyr, g, b
: scalar (uint8uint16float64)Three scalars are returned when this function is fed discrete YUV values. The types match the input pixel values