Monday, July 22, 2013

Create cloud masks for aerial photos in batch

Clouds in aerial photos can interfere in the feature identification and matching stages of the ortho-photo rectification process. Depending on the software algorithm, it may be necessary to either remove the entire photo or mask out the cloud portions from the photo. If there are hundreds or thousands of photos with clouds, then it will be very tedious to manually digitize the cloud masks with a photo editing software. It would be nice to have some tool to automate the task somewhat.

Here is a simple procedure of using the free and open source software Imagemagick and the threshold option to generate the cloud masks from the photos. The assumption is that clouds in aerial photos would be brighter than the terrain underneath. An example aerial photo with clouds is shown below.
Photo credit: Kevin Payravi, Wikimedia Commons

  1. In the Windows Command Prompt, type in the following:

    C:/> convert Overview_head_of_cloud_with_shadow.jpg -threshold 40% cloud_mask.png

    Note: the threshold option tells Imagemagick to set pixel values below 40% to 0 (black) and above to white.

    The mask is created.

  2. Optional. In some software, black is the mask so it may be necessary to invert the mask with the following command.

    C:/> convert cloud_mask.png -channel rgba -transparent black -fill black -opaque white -fill white -opaque none -alpha off -define png:color-type=6 cloud_invert_mask.png

    The mask is inverted as RGB file type
Note: if there are bright objects on the ground e.g. river, stream, road, metallic rooftops, then the mask may contain these objects too. It may be necessary to edit the mask to remove these objects.

No comments:

Post a Comment