Skip to content

Renaming

Module for batch renaming images

ImageRenamer

A class for renaming a list of images.

Parameters:

Name Type Description Default
image_list ImageList

A list of images to be renamed.

required
dest_folder Union[str, Path]

The destination folder where the renamed images will be saved. Defaults to "renamed".

'renamed'
base_name str

The base name for the renamed images. Defaults to "IMG".

'IMG'
prior_class_file Union[str, Path]

A CSV file containing prior classification data. Defaults to None.

None
delete_original bool

Whether to delete the original image after renaming. Defaults to False.

False
parallel bool

Whether to use multiprocessing for faster renaming. Defaults to False.

False

Attributes:

Name Type Description
renaming_dict dict

A dictionary of the old and new names, if build_dictionary is set to True.

Methods:

Name Description
rename

Renames the images from EXIF data. Returns a Pandas dataframe mapping the old to the new ones, and adding additional information from EXIF and, if provided, prior classification of the images.

Returns: pd.DataFrame: A dataframe mapping the old names to new ones and containing additional information from EXIF and, if provided, prior classification of the images.

Raises: RuntimeError: If an error occurs while renaming an image.

make_previews

Creates a preview image for each renamed image, using the make_previews function with the specified parameters. The previews will be saved in the specified dest_folder.

Args: dest_folder (Union[str, Path]): The destination folder for the preview images. preview_size (Union[int, Tuple[int, int]], optional): The size of the preview image. Defaults to None. **kwargs: Additional arguments to be passed to make_previews.

__init__(image_list, dest_folder='renamed', base_name='IMG', progressive_ids=False, prior_class_file=None, delete_original=False, parallel=False)

Initializes the ImageRenamer class.

Parameters:

Name Type Description Default
image_list ImageList

A list of paths to the images to be renamed.

required
dest_folder Union[str, Path]

The destination folder for the renamed images. Defaults to "renamed".

'renamed'
base_name str

The base name for the renamed images. Defaults to "IMG".

'IMG'
prior_class_file Union[str, Path]

A CSV file containing prior classification data. Defaults to None.

None
delete_original bool

Whether to delete the original images after renaming. Defaults to False.

False
parallel bool

Whether to use multiprocessing. Defaults to False.

False

make_previews(dest_folder='previews', resize_factor=-1, preview_size=None, **kwargs)

Create preview images for all images in the ImageList object.

Parameters:

Name Type Description Default
dest_folder Union[str, Path]

The destination folder where preview images will be saved.

'previews'
preview_size float

The size of the preview image. Defaults to None.

None
**kwargs dict

Additional keyword arguments passed to the make_previews function.

{}

Returns:

Type Description
None

None

Raises:

Type Description
RuntimeError

If unable to rename a file.

rename()

Rename the images in self.image_list, applying the copy_and_rename_overlay function with the specified parameters to each image. Return a dictionary mapping the original index of each image in self.image_list to its new name generated by copy_and_rename_overlay.

Returns:

Type Description
DataFrame

A Pandas Dataframe mapping old names of the images with the new ones and adding additional information from exif and, if given as input, prior classification of the images.

Raises:

Type Description
RuntimeError

If an error occurs while renaming an image.

RenamingDict

Bases: TypedDict

A dictionary for storing metadata about an image being renamed. It maps the old image name to the new one and stores additional metadata about the image.

Fields: old_name (str): The original name of the image file. new_name (str): The new name of the image file. date (str): The date the image was taken in the format YYYY:MM:DD. time (str): The time the image was taken in the format HH:MM:SS. camera (str): The camera model that captured the image. focal (float): The focal length of the lens that captured the image. GPSlat (float): The latitude of the location where the image was taken. GPSlon (float): The longitude of the location where the image was taken. GPSh (float): The altitude of the location where the image was taken. classification (int or None): The classification of the image, if applicable.

copy_and_rename(fname, dest_folder='renamed', base_name='IMG', progressive_id=None, delete_original=False)

Renames an image file based on its EXIF data and copies it to a specified destination folder.

Parameters:

Name Type Description Default
fname Union[str, Path]

A string or Path object specifying the file path of the image to rename and copy.

required
dest_folder Union[str, Path]

A string or Path object specifying the destination directory path to copy the renamed image to. Defaults to "renamed".

'renamed'
base_name str

A string to use as the base name for the renamed image file. Defaults to "IMG".

'IMG'
delete_original bool

Whether to delete the original image file after copying the renamed image. Defaults to False.

False

Returns:

Name Type Description
dict bool

A dictionary containing the extracted EXIF data.

Raises:

Type Description
RuntimeError

If the exif data cannot be read or if the image date-time cannot be retrieved from the exif data.

make_previews(fname, dest_folder='previews', resize_factor=-1, resize_to=-1, undistort=False, camera=None, overlay_name=True, output_format='jpg', **kwargs)

Make image resized image previews for Potree Viewer and overlaying the image names.

overlay_text(image, text, font_scale=5, font_color=(255, 255, 255), font_thickness=10, border_px=50, background_color=(255, 255, 255), background_buffer=20)

Overlay text onto an image.

Parameters:

Name Type Description Default
image ndarray

The image onto which the text will be overlaid.

required
text str

The text to be overlaid onto the image.

required
font_scale int

The size of the font for the text. Defaults to 5.

5
font_color Tuple[int, int, int]

The color of the text in BGR format. Defaults to (255, 255, 255).

(255, 255, 255)
font_thickness int

The thickness of the text in pixels. Defaults to 10.

10
border_px int

The number of pixels from the edge of the image to use as a margin for the text. Defaults to 50.

50
background_color Union[Tuple[int, int, int], None]

The color of the background behind the text. If None, no background is added. Defaults to (255, 255, 255).

(255, 255, 255)
background_buffer int

The number of pixels of padding to add around the text when a background is added. Defaults to 20.

20

Returns:

Type Description
ndarray

np.ndarray: The modified image with text overlaid.