Commit 1da8e603 authored by Daniel Scheffler's avatar Daniel Scheffler
Browse files

classify_image() now also supports labelling of unclassified pixels.


Signed-off-by: Daniel Scheffler's avatarDaniel Scheffler <danschef@gfz-potsdam.de>
parent 5c135584
Pipeline #3885 failed with stage
in 1 minute and 57 seconds
......@@ -350,8 +350,9 @@ class RF_Classifier(_ImageClassifier):
def classify_image(image, train_spectra, train_labels, classif_alg, in_nodataVal=None, cmap_nodataVal=None,
tiledims=(1000, 1000), CPUs=None, return_distance=False, **kwargs):
# type: (Union[np.ndarray, GeoArray], np.ndarray, Union[np.ndarray, List[int]], str, int, int, tuple, int, bool, dict) -> Union[GeoArray, Tuple[GeoArray, np.ndarray]] # noqa E501
tiledims=(1000, 1000), CPUs=None, return_distance=False, unclassified_threshold=None,
unclassified_pixVal=-1, **kwargs):
# type: (Union[np.ndarray, GeoArray], np.ndarray, Union[np.ndarray, List[int]], str, int, int, tuple, int, bool, Union[int, float, str], int, dict) -> Union[GeoArray, Tuple[GeoArray, np.ndarray]] # noqa E501
"""Classify image to find the cluster each spectrum belongs to.
:param image: image to be classified
......@@ -369,6 +370,13 @@ def classify_image(image, train_spectra, train_labels, classif_alg, in_nodataVal
:param tiledims:
:param CPUs: number of CPUs to be used for classification
:param return_distance: whether to return the distance metrics leading to the returned classification map
:param unclassified_threshold: if given, all pixels where the computed distance metric exceeds the given threshold
are labelled as unclassified (only usable for 'MinDist', 'SAM' and 'SID'
- may be given as float, integer or string to label a certain distance percentile
- if given as string, it must match the format, e.g., '10%' for labelling the worst
10 % of the distances as unclassified
:param unclassified_pixVal: pixel value to be used in the classification map for unclassified pixels
(default: -1)
:param kwargs: keyword arguments to be passed to classifiers if possible
"""
if classif_alg == 'kNN':
......@@ -406,6 +414,14 @@ def classify_image(image, train_spectra, train_labels, classif_alg, in_nodataVal
cmap = clf.classify(image, in_nodataVal=in_nodataVal, cmap_nodataVal=cmap_nodataVal, tiledims=tiledims)
# label unclassified pixels
if unclassified_threshold is not None:
if classif_alg not in ['MinDist', 'SAM', 'SID']:
raise RuntimeError("Only the methods 'MinDist', 'SAM' and 'SID' can label unclassifed pixels.")
clf.label_unclassified_pixels(label_unclassified=unclassified_pixVal, threshold=unclassified_threshold)
# return
if not return_distance:
return cmap
else:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment