Welcome to Flamingo’s documentation!

The Flamingo toolbox is an open-source toolbox for image segmentation, classification and rectification. It is developed by the Department of Hydraulic Engineering of Delft University of Technology for coastal image analysis. The toolbox is built around the scikit-image, scikit-learn, OpenCV and pystruct toolboxes.

Flamingo is developed and maintained by:

Max Radermacher <m.radermacher@tudelft.nl>

The toolbox can be found at http://github.com/openearth/flamingo.

Command-line tools

Several command-line functions are supplied with the toolbox for batch processing of large datasets. Each command-line function serves a specific part of the image analysis. See for more information the –help option of each command.

rectify-images

Ortho-rectify images based on ground control points (GCP)

Usage:
rectify-image <image> <gcpfile> [–dist-model=NAME] [–dist-coefs=VALUES] [–verbose]
Positional arguments:
image image to be rectified gcpfile file containing GCP’s in image (UVXYZ)
Options:
-h, --help show this help message and exit
--dist-model=NAME
 name of distortion model to use [default: OPENCV]
--dist-coefs=VALUES
 coefficients used for distortion model [default: 0,0,0,0]
--size=SIZE size of output figure [default: 30,20]
--rotation=ANGLE
 rotate resulting image [default: 0]
--translation=DIST
 translate resulting image [default: 0,0]
--maxdistance=DIST
 maximum distance from origin included in plot [default: 1e4]
--verbose print logging messages

classify-images

Train, score and use classification models on image datasets.

Usage:
classify-images preprocess <dataset> [–segmentate] [–channels] [–features] [–extract] [–update] [–normalize] [–relloc] [–relloc_maps] [–images=FILE] [–config=FILE] [–overwrite] [–verbose] classify-images partition <dataset> [–n=N] [–frac=FRAC] [–images=FILE] [–config=FILE] [–verbose] classify-images train <dataset> [–type=NAME] [–partitions=N] [–images=FILE] [–config=FILE] [–verbose] classify-images score <dataset> [–model=NAME] [–images=FILE] [–config=FILE] [–verbose] classify-images predict <dataset> [–model=NAME] [–images=FILE] [–config=FILE] [–overwrite] [–verbose] classify-images regularization <dataset> [–type=NAME] [–images=FILE] [–config=FILE] [–verbose]
Positional arguments:
dataset dataset containing the images image image file to be classified
Options:
-h, --help show this help message and exit
--segmentate create segmentation of images
--channels include channel extraction
--features include feature extraction
--extract extract channels/features
--update update channels/features
--normalize normalize channels/features
--relloc include relative location features
--relloc_maps compute new relative location maps
--n=N number of partitions [default: 5]
--frac=FRAC fraction of images used for testing [default: 0.25]
--type=NAME model type to train [default: LR]
--partitions=N only train these partitions
--model=NAME name of model to be scored, uses last trained if omitted
--images=FILE images to include in process
--config=FILE configuration file to use instead of command line options
--overwrite overwrite existing files
--verbose print logging messages

calibrate-camera

File system

The toolbox uses a file system structure for the analysis of datasets. The flamingo.filesys module takes care of any reading and writing of files in this file structure. Each dataset is stored in a single directory and can consist out of the following file types:

Image files
Any image file recognized by the system
Cropped image files
Names start with cropped_. A non-cropped version of the image file should exist.
Export files
Pickle files with data concerning an image. Each export file name has the following format: <image_name>.<key>.pkl. A special type of export file is the feature file. Not all features are written to a single export file, but they are subdivided into multiple export files depending on the feature block they belong to. The block name is added to the export file, just before the file extension.
Log files
Pickle files with data concerning the entire dataset. Log file names can have any name.
Model files
Pickle files with a trained model. Each model file is accompanied by a meta file. Each model file name has the following format: model_<model_type>_<dataset>_I<nr_of_images>_B<nr_of_blocks>_<timestamp>.pkl. The corresponding meta file has meta added to the name, just before the file extension.
flamingo.filesys.check_export_file(ds, im, ext)[source]

Check if export file exists

flamingo.filesys.get_dataset_list()[source]

Get list of available datasets

flamingo.filesys.get_dataset_path()[source]

Get path to datasets

flamingo.filesys.get_export_file(ds, im=None, ext=None)[source]

Get path to export file

flamingo.filesys.get_image_list(ds)[source]

Get list with all images in dataset

flamingo.filesys.get_image_location(ds, im)[source]

Get absolute path to specific image in dataset

flamingo.filesys.get_image_path(ds)[source]

Get absolute path to images within dataset

flamingo.filesys.get_model_list(ds)[source]

Get list of model files in dataset

flamingo.filesys.has_features(ds, im)[source]

Determine if features for image are extracted

flamingo.filesys.is_classified(ds, im)[source]

Determine if image is annotated

flamingo.filesys.is_segmented(ds, im)[source]

Determine if image is segmented

flamingo.filesys.read_default_categories(ds)[source]

Read list of uniquely defined classes in dataset

flamingo.filesys.read_export_file(ds, im, ext)[source]

Read contents of export file

flamingo.filesys.read_feature_files(ds, im, blocks=['extract_blocks_grey', 'extract_blocks_intensity', 'extract_blocks_mask', 'extract_blocks_pixel', 'extract_blocks_shape', 'extract_blocks_intensitystatistics'], ext=None)[source]

Read features from a collection of export files including only selected feature blocks

flamingo.filesys.read_image_file(ds, im, crop=True)[source]

Read image file

flamingo.filesys.read_log_file(ds, keys=None)[source]

Read contents of log file

flamingo.filesys.read_model_file(ds, model_name)[source]

Read a model from export file including meta data

flamingo.filesys.set_dataset_path(fpath)[source]

Set path to datasets

flamingo.filesys.write_export_file(ds, im, ext, contents, append=False)[source]

Write contents to export file

flamingo.filesys.write_feature_files(ds, im, features, features_in_block, ext=None)[source]

Write features to a collection of export files depending on their feature block

flamingo.filesys.write_log_file(ds, contents)[source]

Write contents to log file

flamingo.filesys.write_model_file(ds, model, meta, ext='')[source]

Write a single model to export file including meta data

flamingo.filesys.write_model_files(ds, models, meta, ext='')[source]

Write a series of models to export files including meta data

Configuration

Only the very basic options of the toolbox are exposed through the command-line functions. For the full extent of options a configuration file is used. This configuration file is parsed by the flamingo.config module. The module also supplies wrappers for the automated updating of a function call based on the configuration file used.

flamingo.config.CLASSIFICATION_DEFAULTS = {'channels': {'enabled': True, 'methods': ['gabor', 'gaussian', 'sobel'], 'methods_params': {'frequencies': [0.05, 0.15, 0.25], 'sigmas': [1, 8, 15], 'thetas': [0.0, 0.785, 1.571, 2.356]}}, 'segmentation': {'remove_disjoint': True, 'extract_contours': False, 'enabled': True, 'method': 'slic', 'method_params': {}}, 'relative_location': {'sigma': 2, 'enabled': False, 'n': 100}, 'features': {'feature_blocks': 'all', 'enabled': True, 'blocks_params': {}}, 'score': {}, 'partition': {'n_partitions': 5, 'force_split': False, 'enabled': True, 'frac_test': 0.25, 'frac_validation': 0.0}, 'training': {'partitions': 'all'}, 'regularization': {'C': [0.1, 1.0, 10.0, 100.0, 1000.0, 10000.0], 'partition': 0}, 'general': {'model_type': 'LR', 'colorspace': 'rgb', 'class_aggregation': '', 'model_dataset': ''}}

Configuration constants for classification toolbox

flamingo.config.get_function_args(fcn, cfg, sections=[])[source]

Get relevant function arguments given a configuration file

flamingo.config.parse_config(sections=[])[source]

Wrapper for parsing config file for specific function call

flamingo.config.read_config(cfgfile, defaults={'channels': {'enabled': True, 'methods': ['gabor', 'gaussian', 'sobel'], 'methods_params': {'frequencies': [0.05, 0.15, 0.25], 'sigmas': [1, 8, 15], 'thetas': [0.0, 0.785, 1.571, 2.356]}}, 'segmentation': {'remove_disjoint': True, 'extract_contours': False, 'enabled': True, 'method': 'slic', 'method_params': {}}, 'relative_location': {'sigma': 2, 'enabled': False, 'n': 100}, 'features': {'feature_blocks': 'all', 'enabled': True, 'blocks_params': {}}, 'score': {}, 'partition': {'n_partitions': 5, 'force_split': False, 'enabled': True, 'frac_test': 0.25, 'frac_validation': 0.0}, 'training': {'partitions': 'all'}, 'regularization': {'C': [0.1, 1.0, 10.0, 100.0, 1000.0, 10000.0], 'partition': 0}, 'general': {'model_type': 'LR', 'colorspace': 'rgb', 'class_aggregation': '', 'model_dataset': ''}})[source]

Read configuration file and update default settings

flamingo.config.write_config(cfgfile, defaults={'channels': {'enabled': True, 'methods': ['gabor', 'gaussian', 'sobel'], 'methods_params': {'frequencies': [0.05, 0.15, 0.25], 'sigmas': [1, 8, 15], 'thetas': [0.0, 0.785, 1.571, 2.356]}}, 'segmentation': {'remove_disjoint': True, 'extract_contours': False, 'enabled': True, 'method': 'slic', 'method_params': {}}, 'relative_location': {'sigma': 2, 'enabled': False, 'n': 100}, 'features': {'feature_blocks': 'all', 'enabled': True, 'blocks_params': {}}, 'score': {}, 'partition': {'n_partitions': 5, 'force_split': False, 'enabled': True, 'frac_test': 0.25, 'frac_validation': 0.0}, 'training': {'partitions': 'all'}, 'regularization': {'C': [0.1, 1.0, 10.0, 100.0, 1000.0, 10000.0], 'partition': 0}, 'general': {'model_type': 'LR', 'colorspace': 'rgb', 'class_aggregation': '', 'model_dataset': ''}})[source]

Write configuration file

Example configuration

[channels]
enabled = True
methods = ["gabor", "gaussian", "sobel"]
methods_params = {"frequencies": [0.05, 0.15, 0.25], "sigmas": [1, 8, 15], "thetas": [0.0, 0.785, 1.571, 2.356]}

[segmentation]
remove_disjoint = True
extract_contours = False
enabled = True
method = slic
method_params = {}

[relative_location]
sigma = 2
enabled = False
n = 100

[features]
feature_blocks = all
enabled = True
blocks_params = {}

[score]

[train]
partitions = all

[partition]
n_partitions = 5
force_split = False
enabled = True
frac_test = 0.25
frac_validation = 0.0

[regularization]
c = [0.1, 1.0, 10.0, 100.0, 1000.0, 10000.0]
partition = 0

[general]
model_type = LR
colorspace = rgb
class_aggregation = 
model_dataset = 

Acknowledgements

The Flamingo toolbox is developed at Delft University of Technology with support from the ERC-Advanced Grant 291206 – Nearshore Monitoring and Modeling (NEMO), STW Grant 12686 – Nature-driven Nourishments of Coastal Systems (NatureCoast), S1: Coastal safety and Deltares.

Indices and tables