Python API

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

bob.ip.draw.get_config()[source]

Returns a string containing the configuration information.

bob.ip.draw.box(image, p, size, color) → None

Draws a box anchored at a point, with the given dimensions.

This method draws a box, using the line() primitives, into the provided image. The box will be anchored at a given point, which refers to its upper-left corner and have a certain size, defined in terms of its height and width.

The line may go out of the image bounds in which case such points (lying outside the image boundary) are ignored.

See also: http://en.wikipedia.org/wiki/Bresenham’s_line_algorithm.

This function can work with either gray-scale or color images. In case you pass a 2D array representing a gray-scale image, this function expects you pass a single scalar as a value for the input parameter color. In the case you pass a 3D array (color image), then the color parameter should be set to a tuple contanining 3 scalars representing the levels for each of the color components (red, green and blue)

Parameters:

image : array (uint8|uint16|float64, 3D)

Input array containing an image with the shape (height, width) (for gray-scale images) or (3, height, width) (for color images)

p : tuple

a point, on the format (y, x), defining the location on the image of the upper-left corner of the box.

size : tuple

a tuple of integers on the format (height, width) indicating the size of the box.

color : scalar|tuple

Color of the pixel. In case the input image is gray-scale (2D), this should be a single scalar. If the input image is colored (3D), then it should be a sequence containing 3 scalars, representing the levels of red, green and blue (in this order) of the pixel to be drawn. The type of scalars representing colors should match the pixel type in image.

bob.ip.draw.cross(image, p, radius, color) → None

Draws a cross in the given (gray-scale or color) image.

This method can draw a cross-like set of lines resembling an x, in either gray-scale (2D) or color images. The cross is centered on a given point p and will have the radius defined. Images have to be numpy.ndarray’s with either uint8, uint16 or float64 data type. Trying to access outside the image range will raise a RuntimeError.

In case you pass a 2D array representing a gray-scale image, this function expects you pass a single scalar as a value for the input parameter color. In the case you pass a 3D array (color image), then the color parameter should be set to a tuple contanining 3 scalars representing the levels for each of the color components (red, green and blue)

Color images are expected to be represented using the first dimension for the color planes: (3, height, width). Images are modified in place.

Parameters:

image : array (uint8|uint16|float64, 3D)

Input array containing an image with the shape (height, width) (for gray-scale images) or (3, height, width) (for color images)

p : tuple

a point, on the format (y, x), defining the location on the image that the pixel is going to be drawn.

radius : int

the value of the radius for the cross to be drawn, in pixels

color : scalar|tuple

Color of the cross sign. In case the input image is gray-scale (2D), this should be a single scalar. If the input image is colored (3D), then it should be a sequence containing 3 scalars, representing the levels of red, green and blue (in this order) of the pixel to be drawn. The type of scalars representing colors should match the pixel type in image.

bob.ip.draw.line(image, p1, p2, color) → None

Draws a line between two points on the given image.

This function is based on the Bresenham’s line algorithm and is highly optimized to be able to draw lines very quickly. There is no floating point arithmetic nor multiplications and divisions involved. Only additions, subtractions and bit shifting operations are used.

The line may go out of the image bounds in which case such points (lying outside the image boundary) are ignored.

See also: http://en.wikipedia.org/wiki/Bresenham’s_line_algorithm.

This function can work with either gray-scale or color images. In case you pass a 2D array representing a gray-scale image, this function expects you pass a single scalar as a value for the input parameter color. In the case you pass a 3D array (color image), then the color parameter should be set to a tuple contanining 3 scalars representing the levels for each of the color components (red, green and blue)

Parameters:

image : array (uint8|uint16|float64, 3D)

Input array containing an image with the shape (height, width) (for gray-scale images) or (3, height, width) (for color images)

p1, p2 : tuple

Points, on the format (y, x), defining the start and end of the line. Portions of the line outside the image range will be ignored.

color : scalar|tuple

Color of the pixel. In case the input image is gray-scale (2D), this should be a single scalar. If the input image is colored (3D), then it should be a sequence containing 3 scalars, representing the levels of red, green and blue (in this order) of the pixel to be drawn. The type of scalars representing colors should match the pixel type in image.

bob.ip.draw.plus(image, p, radius, color) → None

Draws a plus sign in the given (gray-scale or color) image.

This method can draw a cross-like set of lines resembling an +, in either gray-scale (2D) or color images. The cross is centered on a given point p and will have the radius defined. Images have to be numpy.ndarray’s with either uint8, uint16 or float64 data type. Trying to access outside the image range will raise a RuntimeError.

In case you pass a 2D array representing a gray-scale image, this function expects you pass a single scalar as a value for the input parameter color. In the case you pass a 3D array (color image), then the color parameter should be set to a tuple contanining 3 scalars representing the levels for each of the color components (red, green and blue)

Color images are expected to be represented using the first dimension for the color planes: (3, height, width). Images are modified in place.

Parameters:

image : array (uint8|uint16|float64, 3D)

Input array containing an image with the shape (height, width) (for gray-scale images) or (3, height, width) (for color images)

p : tuple

a point, on the format (y, x), defining the location on the image that the pixel is going to be drawn.

radius : int

the value of the radius for the cross to be drawn, in pixels

color : scalar|tuple

Color of the cross sign. In case the input image is gray-scale (2D), this should be a single scalar. If the input image is colored (3D), then it should be a sequence containing 3 scalars, representing the levels of red, green and blue (in this order) of the pixel to be drawn. The type of scalars representing colors should match the pixel type in image.

bob.ip.draw.point(image, p, color) → None

Draws a point in the given (gray-scale or color) image.

This method can draw a point in either gray-scale (2D) or color images. Images have to be numpy.ndarray’s with either uint8, uint16 or float64 data type. Trying to access outside the image range will raise a RuntimeError.

In case you pass a 2D array representing a gray-scale image, this function expects you pass a single scalar as a value for the input parameter color. In the case you pass a 3D array (color image), then the color parameter should be set to a tuple contanining 3 scalars representing the levels for each of the color components (red, green and blue)

Color images are expected to be represented using the first dimension for the color planes: (3, height, width). Images are modified in place.

Parameters:

image : array (uint8|uint16|float64, 3D)

Input array containing an image with the shape (height, width) (for gray-scale images) or (3, height, width) (for color images)

p : tuple

a point, on the format (y, x), defining the location on the image that the pixel is going to be drawn.

color : scalar|tuple

Color of the pixel. In case the input image is gray-scale (2D), this should be a single scalar. If the input image is colored (3D), then it should be a sequence containing 3 scalars, representing the levels of red, green and blue (in this order) of the pixel to be drawn. The type of scalars representing colors should match the pixel type in image.

bob.ip.draw.try_point(image, p, color) → None

Tries to draw a point in the given (gray-scale or color) image.

This method tries to draw a point in either gray-scale (2D) or color images. If the point is out of bounds, it is simply ignored and not drawn. The input of this method is identical to the input of point(), in this module. See its help message for details.

Parameters:

image : array (uint8|uint16|float64, 3D)

Input array containing an image with the shape (height, width) (for gray-scale images) or (3, height, width) (for color images)

p : tuple

a point, on the format (y, x), defining the location on the image that the pixel is going to be drawn.

color : scalar|tuple

Color of the pixel. In case the input image is gray-scale (2D), this should be a single scalar. If the input image is colored (3D), then it should be a sequence containing 3 scalars, representing the levels of red, green and blue (in this order) of the pixel to be drawn. The type of scalars representing colors should match the pixel type in image.