Batch converting rover images for photogrammetry

Batch converting rover images for photogrammetry#

This notebook will introduce advanced image filtering and parallel processing.

Many of it’s functions are designed to prepare rover images for photogrammetry processing.

from pathlib import Path

from marsimage.batch_processing import process_images, filter_photogrammetry
from marsimage.download import download_msl

Multi Sol and Multi instrument downloading#

For larger projects like photogrammetry, it is necessary to download images from a range of sols and for multiple instruments.

MarsImage provides a batch download function called download_msl to download calibrated MSL/Curiosity images from the PDS.

You can specify a list of instruments to download from: mastcam, mahli, mardi, navcam, hazcam, or all to download all at once.

To download multiple cameras at once, you can write them as a python list: ['navcam', 'mastcam']. The full command will look like this:

download_msl(['navcam', 'mastcam'], sol_start=3560, sol_end=3650, output_dir=download_dir)
download_dir = './temp/MontMercouHazcam/'

# this will download all MSL Hazcam images from sol 3074 to 3076
download_msl('hazcam', sol_start=3074, sol_end=3076, output_dir=download_dir);
Downloading images from Sol 3074 to Sol 3076 for HAZCAM.

Batch Converting the images#

With the process_images() function we can now convert the PDS products to TIFF files and automatically apply masks in the alpha-channel.

It is possible to specify a very flexible grouping pattern. You can specify any folder pattern from the following keywords:

  • sol, cam_id, site, drive, rmc, site_drive

  • any attribute of the MarsImage object, like mission_id, width, target, etc…

Examples:

  • 'sol/cam_id/site/drive' would save to something like this: 3048/MAST_LEFT/Site_87/Drive_420/

  • 'mission_id/instrument_name' would save to something like this: 'MSL/MAST_CAMERA_LEFT/'

# get all the Hazcam images from the download directory
images = list(Path('./temp/MontMercouHazcam/').rglob('*.IMG'))
output_dir = './temp/MontMercouHazcam/converted/'

# process the images in parrallel, group them by camera id and apply the mask
process_images(images, output_dir, group='cam_id', apply_mask=True, image_filter=filter_photogrammetry)

Filtering images#

Many rover images are unsuited for photogrammetry (for example sky surveys, autofocus images, instrument inspections, etc..).

Therefore we need to filter them out before converting the images. Batch Processing implements several filter functions that are designed to remove these images. They are still a work in progress and may break for some parts of the mission. If they should break, you can disable them by calling process_images with the image_filter=None argument, or by writing your own filter implement your own filters and pass them to the batch processing function.

The following example disables the filter and processes eight more images because they are not filtered out like before.

# get all the Hazcam images from the download directory
images = list(Path('./temp/MontMercouHazcam/').rglob('*.IMG'))
output_dir = './temp/MontMercouHazcam/converted/'

# process the images in parrallel, group them by camera id and apply the mask
process_images(images, output_dir, group='cam_id', apply_mask=True, image_filter=None)