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:
| Name | Type | Description | Default |
|---|---|---|---|
client | The database connector, perhaps as returned by | required |
total_results
total_results() -> int
Returns the total number of images that matched the query
Returns:
| Name | Type | Description |
|---|---|---|
int | int | 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:
| Name | Type | Description | Default |
|---|---|---|---|
index | int | 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:
| Name | Type | Description | Default |
|---|---|---|---|
index | int | 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:
| Name | Type | Description | Default |
|---|---|---|---|
index | int | Position in the image ids retrieved. | required |
Returns:
| Name | Type | Description |
|---|---|---|
_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:
| Name | Type | Description | Default |
|---|---|---|---|
constraints | dict | Constraints. Defaults to None. | None |
operations | dict | Operations. Defaults to None. | None |
format | str | Format of the returned images. Without this, the images are returned as they are stored. Defaults to None. | None |
limit | int | number of values to restrict results to. Defaults to None. | None |
sort | dict | 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:
| Name | Type | Description | Default |
|---|---|---|---|
prop_key | str | Key on which to search | required |
prop_values | list | 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:
| Name | Type | Description | Default |
|---|---|---|---|
show_bboxes | bool | bool, optional Show bounding boxes, by default False | False |
bbox_constraints | Constraints | Constraints, optional Constraints for bounding boxes, by default None | None |
show_polygons | bool | bool, optional Show polygons, by default False | False |
limit | Union[int, object] | Union[int, object], optional Number of images to display, by default None | None |
polygon_constraints | Constraints | Constraints, optional Constraints for polygons, by default None | None |
polygon_tag_key | str | str, optional Key for the polygon tag, by default "_label" | '_label' |
polygon_tag_format | str | 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:
| Name | Type | Description |
|---|---|---|
properties | List[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:
| Name | Type | Description | Default |
|---|---|---|---|
prop_list | List[str] | The list of properties to retrieve. Defaults to []. | [] |
Returns:
| Name | Type | Description |
|---|---|---|
property_values | Dict[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:
| Name | Type | Description | Default |
|---|---|---|---|
client | The database connector, perhaps as returned by | required |
np_arr_img_to_bytes
np_arr_img_to_bytes(arr, format: str = 'JPEG') -> bytes
Convert a NumPy array to bytes
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arr | The NumPy array to convert | required | |
format | str | The format of the image. Defaults to "JPEG". | 'JPEG' |
Returns:
| Name | Type | Description |
|---|---|---|
bytes | bytes | The image as bytes |
image_to_bytes
image_to_bytes(image: Image, format: str = 'JPEG') -> bytes
Convert an image to bytes
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image | Image | The image to convert | required |
format | str | The format of the image. Defaults to "JPEG". | 'JPEG' |
Returns:
| Name | Type | Description |
|---|---|---|
bytes | bytes | The image as bytes |
rotate
rotate(points, angle, c_x=0, c_y=0)
Rotate a set of points around a center
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
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:
| Name | Type | Description |
|---|---|---|
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:
| Name | Type | Description | Default |
|---|---|---|---|
points | NumPy array | The coordinates of the bounding box; shape (...,2) | required |
image_meta | dict | The image properties | required |
operations | list | The operations applied to the image | required |
Returns:
| Name | Type | Description |
|---|---|---|
resolved_points | NumPy array | The resolved coordinates, same shape as points |