brails.types.image_set module

This module contains classes for managing and manipulating sets of image.

Classes:
  • Image: A class to represent an individual image.

  • ImageSet: A class for handling collections of images.

Image(filename[, properties])

Represents an image and its associated metadata.

ImageSet()

A collection of Image objects.

class brails.types.image_set.Image(filename, properties=None)

Bases: object

Represents an image and its associated metadata.

To import the Image class, use:

from brails.types.image_set import Image
Parameters:
  • filename (str) – The name of the file containing the image.

  • properties (dict) – A dictionary containing metadata or properties related to the image, such as camera settings, location, or depth maps.

print_info()

Print the image filename and properties.

If no properties are set, only the filename will be printed.

Examples

>>> img = Image('gstrt_4769427063_-12213443753.jpg')
>>> img.print_info()
filename: 'gstrt_4769427063_-12213443753.jpg'
>>> img.update_properties({'width': 640, 'height': 480})
>>> img.print_info()
filename: 'gstrt_4769427063_-12213443753.jpg'
properties: {'width': 640, 'height': 480}
update_filename(filename)

Update the filename for the image.

Parameters:

filename (str) – New filename for the image.

Example

>>> img = Image('building.jpg')
>>> img.update_filename('gstrt_4769427063_-12213443753.jpg')
>>> img.filename
'gstrt_4769427063_-12213443753.jpg'
update_properties(additional_properties)

Update image properties.

Parameters:

additional_properties (Dict[str, Any]) – Key-value pairs to update image properties.

Example

>>> img = Image(
...     'gstrt_4769427063_-12213443753.jpg',
...     {'width': 640}
... )
>>> img.update_properties({'height': 480, 'cam_elevation': 12.1})
>>> img.properties
{'width': 640, 'height': 480, 'cam_elevation': 12.1}
class brails.types.image_set.ImageSet

Bases: object

A collection of Image objects.

The ImageSet class can be imported using the syntax below:

from brails.types.image_set import ImageSet
Parameters:
  • dir_path (str) – Path to the directory containing image files.

  • images (Dict[Union[str, int], Image]) – Dictionary of Image objects keyed by user-defined identifiers.

add_image(key, filename, properties=None)

Create and add a new Image to the ImageSet.

Parameters:
  • key (Union[str, int]) – Identifier for the image.

  • filename (str) – Name of the image file.

  • properties (Optional[Dict[str, Any]]) – Optional metadata for the image.

Returns:

True if image was added; False if the key already exists.

Return type:

bool

Examples

>>> img_set = ImageSet()
>>> img_set.add_image(
...     1,
...     'building_front.jpg',
...     {'width': 1920, 'height': 1080}
... )
True
>>> img_set.add_image(1, 'street_view.png')  # Duplicate key
False
get_image(key)

Retrieve an image by key.

Parameters:

key (Union[str, int]) – Identifier for the image.

Returns:

The Image if found; otherwise, None.

Return type:

Optional[Image]

Examples

>>> img_set = ImageSet()
>>> img_set.add_image('main', 'roof_detail.jpg')
True
>>> img = img_set.get_image('main')
>>> img.filename
'roof_detail.jpg'
print_info()

Print information about the image set.

Displays:
  • The directory path (if set).

  • The number of images in the set.

  • The key, filename, and any properties for each image.

Examples

>>> img_set = ImageSet()
>>> img_set.add_image('north_view', 'north_building.jpg')
>>> img_set.add_image(
...     'east_view',
...     'east_building.jpg',
...     {'location': (36.0142, -75.6679)}
... )
True
>>> img_set.print_info()
Directory:
Total number of images: 2
List of Images
----------------
- key: north_view, filename: north_building.jpg
- key: east_view, filename: east_building.jpg,
properties: {'location': (36.0142, -75.6679)}
set_directory(path_to_dir, include_existing_images=False, limited_to_extension_types=None)

Set the image directory and optionally load existing images.

Parameters:
  • path_to_dir (str) – Path to the directory containing image files.

  • include_existing_images (bool) – If True, add existing image files in the directory to the set using numeric keys starting at 1.

  • limited_to_extension_types (Optional[List[str]]) – If provided, only include files whose extensions match one of the allowed types (e.g., ['.jpg', '.png']).

Returns:

True if the directory exists and was set; False if the directory does not exist.

Return type:

bool

Examples

Assuming the path /data/images exists:

>>> img_set = ImageSet()
>>> img_set.set_directory(
...     '/data/images',
...     include_existing_images=True,
...     limited_to_extension_types=['.jpg', '.png']
)
True

Assuming the path /DOES-NOT-EXIST does not exist:

>>> img_set.set_directory('/DOES-NOT-EXIST')
Warning: the specified path /DOES-NOT-EXIST is not a valid
directory
False