RSGISLib Image Tools
Animate Images
- rsgislib.tools.imagetools.animate_img_set(input_imgs: List[str], output_img: str, fps: int = 1, resize: bool = False, out_x_size: int = 720, out_y_size: int = None, tmp_dir: str = './tmp')
A function which uses the imageio module to animate a set input images to create an animated GIF video file. This is intended to be used to a set of images which have been exported (e.g., from the mapping module).
The input images can be resampled to a new size but this requires the PIL module to be installed.
- Parameters:
input_imgs – list of input image paths
output_img – output image file path.
fps – the number of frames per second. Higher values will result in faster video (i.e., less time per frame). Default: 1.
resize – boolean specifying whether to resize the input images.
out_x_size – the size of the output image (if resizing) for the x axis. Default: 720
out_y_size – the size of the output image (if resizing) for the y axis. If None then the size is calculated from the input image to keep the proportions the same. Default: None
tmp_dir – a temp path for the resized images to be written to if resizing the input images.
EXIF Metadata
- rsgislib.tools.imagetools.list_exif_info(input_img)
A function which lists the exif information from an input image using the PIL module.
- Parameters:
input_img – the path to the input image
Sort Images
- rsgislib.tools.imagetools.split_photos_by_time(input_imgs, output_base_dir, time_split_secs=60, date_time_tag='DateTime', date_time_format='%Y:%m:%d %H:%M:%S', out_date_time_format='%Y%m%d_%H%M%S')
A function which splits a set of images (e.g., from drone surveys) by time. Where photos taken within the specified time window will be clustered together (default: 60 seconds). The photos are then copied into a new directory based on the start time of the cluster. Note, photos are copied and not moved from their current location.
- Parameters:
input_imgs – a list of input images (e.g., glob.glob(”*.jpg”))
output_base_dir – the output base directory where the output directories will be created.
time_split_secs – The time difference in seconds for a new cluster to be created.
date_time_tag – the EXIF tag for the date / time of the acquisition. Default is ‘DataTime’ but this might be different for different cameras and therefore you might need to use the list_exif_info function to find the correct field.
date_time_format – The python datetime.strptime format string for the datetime provided in the EXIF metadata. Default: %Y:%m:%d %H:%M:%S
out_date_time_format – The python datetime.strftime format string for the used to create the output directory for the files. Note, this must be unique. Default: %Y%m%d_%H%M%S
PDF Utilities
- rsgislib.tools.imagetools.extract_images_from_pdf(input_pdf, output_dir)
A function which extracts the images from a PDF file and files them to a directory as PNG image files.
Note this function requires the fitz module to be installed:
pip install fitz
The fitz module also requires the PyMuPDF module which is not installed by pip.
pip install PyMuPDF
- Parameters:
input_pdf – the path to the input PDF file.
output_dir – the output directory where the images will be stored.