Image Filters
Image filters are modules designed to clean images before they are processed for information extraction. Removing unwanted elements from an image can improve the accuracy and efficiency of the processing algorithms.
The following example demonstrates this process: it uses the user’s chosen footprint scraper to create an AssetInventory
. Then, it retrieves Google Street View images for a subset of the inventory and applies a HouseView
filter, which attempts to isolate the house located at the center of each downloaded image. The filter returns a new, cleaned image.
A typical Python example is shown below:
1"""
2brails_filters.py
3================
4Example showing the use of BRAILS module that crops building images from panos.
5
6 Purpose: Testing 1) get_class method of Importer
7 2) get_footprints using scraper provided
8 3) get_images using StreetView for subset of footprints
9 4) filter method of HouseView
10"""
11
12import os
13import argparse
14from pathlib import Path
15from brails import Importer
16
17# This script needs a Google API Key to run.
18# We suggest placing your API key in file apiKey.txt in the same directory as
19# this script if you plan to commit changes to this example. This way, you do
20# not risk accidentally uploading your API key (apiKey.txt is in .gitignore,
21# so you have work to do to get it uploaded)
22
23API_KEY_DIR = '../api_key.txt'
24if os.path.exists(API_KEY_DIR):
25 with open(API_KEY_DIR, 'r', encoding='utf-8') as file:
26 api_key = file.readline().strip() # Read first line & strip whitespace
27else:
28 raise FileNotFoundError('API key file not found. Please ensure the file'
29 f' exists at: {API_KEY_DIR}')
30
31
32def main():
33 # Create the argument parser
34 parser = argparse.ArgumentParser(description="Demonstrate Importer.")
35 parser.add_argument('scraper', type=str, help="Footprint Scraper")
36 parser.add_argument('location', type=str, help="Location")
37
38 # Parse the arguments
39 args = parser.parse_args()
40
41 importer = Importer()
42
43 region_boundary_class = importer.get_class("RegionBoundary")
44 region_boundary_object = region_boundary_class({"type": "locationName", "data": args.location})
45 scraper_class = importer.get_class(args.scraper)
46 scraper = scraper_class({"length": "ft"})
47 inventory = scraper.get_footprints(region_boundary_object)
48 print(f"num assets found: {len(inventory.inventory)} for {args.location} using {args.scraper}")
49
50 # Subsample from the extracted assets to keep the image downloading step quick.
51 # Here, we are randomly sampling 10 buildings using a random seed value of 100:
52 small_inventory = inventory.get_random_sample(10, 100)
53
54
55 # Get street level imagery for the selected subset using GoogleStreetview:
56 google_street_class = importer.get_class('GoogleStreetview')
57 google_street = google_street_class({'apiKey': api_key})
58 images_street = google_street.get_images(small_inventory, 'tmp/street/')
59
60 images_street.print_info()
61
62 # Crop the obtained imagery such that they include just the buildings of
63 # interest:
64 filter_house = importer.get_class('HouseView')
65 image_filter = filter_house({})
66 filtered_images_street = image_filter.filter(images_street, 'tmp/filtered_images')
67 print('\nCropped images are available in ',
68 Path(filtered_images_street.dir_path).resolve())
69
70 filtered_images_street.print_info()
71
72# Run the main function if this script is executed directly
73if __name__ == "__main__":
74 main()
To run, for example, the brails_filters.py script for Berkeley, CA, execute the following command in a terminal window:
python3 brails_filter.py USA_FootprintScraper "Berkeley, CA"
and the application would produce two ImageSet
objects:
Raw Images
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
Filtered Images:
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |