diff --git a/pysegcnn/plot/class_distribution.py b/pysegcnn/plot/class_distribution.py new file mode 100644 index 0000000000000000000000000000000000000000..1d9da16538ded9617998c1637bc78269c69d258e --- /dev/null +++ b/pysegcnn/plot/class_distribution.py @@ -0,0 +1,46 @@ +"""Plot the distribution of the classes of a dataset in spectral space. + +License +------- + + Copyright (c) 2020 Daniel Frisinghelli + + This source code is licensed under the GNU General Public License v3. + + See the LICENSE file in the repository's root directory. + +""" + +# !/usr/bin/env python +# -*- coding: utf-8 -*- + +# builtins +from logging.config import dictConfig + +# locals +from pysegcnn.core.trainer import DatasetConfig +from pysegcnn.core.graphics import plot_class_distribution +from pysegcnn.core.logging import log_conf +from pysegcnn.plot.plot_config import (PLOT_PATH, BANDS, FIGSIZE, ALPHA, + DATASETS, DPI) + + +if __name__ == '__main__': + + # initialize logging + dictConfig(log_conf()) + + # iterate over the datasets + for name, params in DATASETS.items(): + + # instanciate dataset + dc = DatasetConfig(dataset_name=name, bands=BANDS, tile_size=None, + **params) + ds = dc.init_dataset() + + # plot class distribution + fig = plot_class_distribution(ds, FIGSIZE, ALPHA) + + # save figure + filename = PLOT_PATH.joinpath('{}_sdist.png'.format(name)) + fig.savefig(filename, dpi=DPI, bbox_inches='tight') diff --git a/pysegcnn/plot/composites.py b/pysegcnn/plot/composites.py new file mode 100644 index 0000000000000000000000000000000000000000..6a937bd525b95063f8577b7598664e86ad285f71 --- /dev/null +++ b/pysegcnn/plot/composites.py @@ -0,0 +1,61 @@ +"""Plot a false color composite of each scene in a dataset. + +License +------- + + Copyright (c) 2020 Daniel Frisinghelli + + This source code is licensed under the GNU General Public License v3. + + See the LICENSE file in the repository's root directory. + +""" + +# !/usr/bin/env python +# -*- coding: utf-8 -*- + +# builtins +import logging +from logging.config import dictConfig + +# locals +from pysegcnn.core.trainer import DatasetConfig +from pysegcnn.core.graphics import plot_sample +from pysegcnn.core.logging import log_conf +from pysegcnn.plot.plot_config import (PLOT_PATH, BANDS, FIGSIZE, ALPHA, + DATASETS, PLOT_BANDS, DPI) + +# module level logger +LOGGER = logging.getLogger(__name__) + + +if __name__ == '__main__': + + # initialize logging + dictConfig(log_conf()) + + # iterate over the datasets + for name, params in DATASETS.items(): + + # instanciate dataset + dc = DatasetConfig(dataset_name=name, bands=BANDS, tile_size=None, + **params) + ds = dc.init_dataset() + + # iterate over the scenes of the dataset + for scene in range(len(ds)): + # name of the current scene + scene_id = ds.scenes[scene]['id'] + LOGGER.info(scene_id) + + # get the data of the current scene + x, y = ds[scene] + + # plot the current scene + fig = plot_sample(x, ds.use_bands, ds.labels, y=y, + hide_labels=True, bands=PLOT_BANDS, + alpha=ALPHA, figsize=FIGSIZE) + + # save the figure + fig.savefig(PLOT_PATH.joinpath('.'.join([scene_id, 'png'])), + dpi=DPI, bbox_inches='tight') diff --git a/pysegcnn/plot/plot_config.py b/pysegcnn/plot/plot_config.py new file mode 100644 index 0000000000000000000000000000000000000000..69075247cd09766db0bd79244d84374cbef9c8df --- /dev/null +++ b/pysegcnn/plot/plot_config.py @@ -0,0 +1,54 @@ +"""Configuration file for plotting. + +License +------- + + Copyright (c) 2020 Daniel Frisinghelli + + This source code is licensed under the GNU General Public License v3. + + See the LICENSE file in the repository's root directory. + +""" + +# !/usr/bin/env python +# -*- coding: utf-8 -*- + +# builtins +import pathlib + +# path to this file +HERE = pathlib.Path(__file__).resolve().parent + +# path to save plots +PLOT_PATH = HERE.joinpath('_plots/') + +# check if the output path exists +if not PLOT_PATH.exists(): + PLOT_PATH.mkdir() + +# path to the datasets on the current machine +# DRIVE_PATH = pathlib.Path('C:/Eurac/Projects/CCISNOW/Datasets/') +DRIVE_PATH = pathlib.Path('F:/Studium/SS 2020/Datasets/') + +# name and paths to the datasets +DATASETS = {'Sparcs': {'root_dir': DRIVE_PATH.joinpath('Sparcs'), + 'merge_labels': {'Shadow_over_water': 'Shadow', + 'Flooded': 'Land'}, + 'gt_pattern': '(.*)mask\\.png'}, + 'Alcd': {'root_dir': DRIVE_PATH.joinpath('Alcd/Resampled/20m'), + 'merge_labels': {'Cirrus': 'Cloud', + 'Not_used': 'No_data'}, + 'gt_pattern': '(.*)Labels\\.tif'} + } + +# spectral bands to plot distribution +BANDS = ['aerosol', 'blue', 'green', 'red', 'nir', 'cirrus', 'swir1', 'swir2'] + +# plot parameters +FIGSIZE = (16, 9) +ALPHA = 0.5 +DPI = 300 + +# natural with atmospheric removal +PLOT_BANDS = ['swir2', 'nir', 'green']