Skip to main content

Images

Image Objects

Images​

Images(client, batch_size=100, response=None, **kwargs)

Bases: Entities

The python wrapper of images in ApertureDB.

This class serves 2 purposes:

This class is a layer on top of the native query.

It facilitate interactions with images in the database in a pythonic way. Abstracts the complexity of the query language and the communication with the database.

It includes utility methods to visualize image and annotations

Inter convert the representation into NumPy matrices and find similar images, related bounding boxes, etc.

Parameters:

NameTypeDescriptionDefault
client

The database connector, perhaps as returned by CommonLibrary.create_connector

required

total_results​

total_results() -> int

Returns the total number of images that matched the query

Returns:

NameTypeDescription
intint

Count of images that match the query.

get_image_by_index​

get_image_by_index(index: int)

Get a single image by its index in the array of retrieved ids

Parameters:

NameTypeDescriptionDefault
indexint

Position in the image ids retrieved.

required

get_np_image_by_index​

get_np_image_by_index(index: int)

Retrieves the NumPy representation of image from database

Parameters:

NameTypeDescriptionDefault
indexint

Position in the image ids retrieved.

required

get_bboxes_by_index​

get_bboxes_by_index(index: int)

Get related bounding box for the image

Parameters:

NameTypeDescriptionDefault
indexint

Position in the image ids retrieved.

required

Returns:

NameTypeDescription
_type_

description

search​

search(constraints=None, operations=None, format=None, limit=None, sort=None)

Sets a new query to retrieve images parameters as described below

Parameters:

NameTypeDescriptionDefault
constraintsdict

Constraints. Defaults to None.

None
operationsdict

Operations. Defaults to None.

None
formatstr

Format of the returned images. Without this, the images are returned as they are stored. Defaults to None.

None
limitint

number of values to restrict results to. Defaults to None.

None
sortdict

Sort. Defaults to None.

None

search_by_property​

search_by_property(prop_key: str, prop_values: list)

Constructs a constraints block and does a new search

Parameters:

NameTypeDescriptionDefault
prop_keystr

Key on which to search

required
prop_valueslist

The values that must match for the key.

required

display​

display(show_bboxes: bool = False, bbox_constraints: Constraints = None, show_polygons: bool = False, limit: Union[int, object] = None, polygon_constraints: Constraints = None, polygon_tag_key: str = '_label', polygon_tag_format: str = '{}') -> None

Display images with annotations

Parameters:

NameTypeDescriptionDefault
show_bboxesbool

bool, optional Show bounding boxes, by default False

False
bbox_constraintsConstraints

Constraints, optional Constraints for bounding boxes, by default None

None
show_polygonsbool

bool, optional Show polygons, by default False

False
limitUnion[int, object]

Union[int, object], optional Number of images to display, by default None

None
polygon_constraintsConstraints

Constraints, optional Constraints for polygons, by default None

None
polygon_tag_keystr

str, optional Key for the polygon tag, by default "_label"

'_label'
polygon_tag_formatstr

str, optional Format for the polygon tag, by default "{}"

'{}'

get_props_names​

get_props_names() -> List[str]

Get the names of the properties that apply to images

Returns:

NameTypeDescription
propertiesList[str]

The names of the properties of the images

get_properties​

get_properties(prop_list: Iterable[str] = []) -> Dict[str, Any]

Get the properties of the images

Parameters:

NameTypeDescriptionDefault
prop_listList[str]

The list of properties to retrieve. Defaults to [].

[]

Returns:

NameTypeDescription
property_valuesDict[str, Any]

The properties of the images

Frames​

Frames(client, batch_size=100, response=None, **kwargs)

Bases: Images

The python wrapper of frame images in ApertureDB.

Frames in ApertureDB are quite similar to images and so are modeled in python as a subclass.

Parameters:

NameTypeDescriptionDefault
client

The database connector, perhaps as returned by CommonLibrary.create_connector

required

np_arr_img_to_bytes​

np_arr_img_to_bytes(arr, format: str = 'JPEG') -> bytes

Convert a NumPy array to bytes

Parameters:

NameTypeDescriptionDefault
arr

The NumPy array to convert

required
formatstr

The format of the image. Defaults to "JPEG".

'JPEG'

Returns:

NameTypeDescription
bytesbytes

The image as bytes

image_to_bytes​

image_to_bytes(image: Image, format: str = 'JPEG') -> bytes

Convert an image to bytes

Parameters:

NameTypeDescriptionDefault
imageImage

The image to convert

required
formatstr

The format of the image. Defaults to "JPEG".

'JPEG'

Returns:

NameTypeDescription
bytesbytes

The image as bytes

rotate​

rotate(points, angle, c_x=0, c_y=0)

Rotate a set of points around a center

Parameters:

NameTypeDescriptionDefault
points

The points to rotate; iterable of (x, y) pairs

required
angle

The angle of counterclockwise rotation in degrees

required
c_x

The x coordinate of the center of rotation

0
c_y

The y coordinate of the center of rotation

0

Returns:

NameTypeDescription
points

The rotated points as a NumPy array of shape (n,2) and type int

resolve​

resolve(points: array, image_meta, operations) -> np.array

Resolve the coordinates of a bounding box to the original image size

Given an array of (x,y) points with respect to the coordinates of an image, returns the corresponding coordinates with respect to a the resized or rotated image that resulted from a series of operations.

Parameters:

NameTypeDescriptionDefault
pointsNumPy array

The coordinates of the bounding box; shape (...,2)

required
image_metadict

The image properties

required
operationslist

The operations applied to the image

required

Returns:

NameTypeDescription
resolved_pointsNumPy array

The resolved coordinates, same shape as points