Commit 5f4ec877 authored by Daniel Scheffler's avatar Daniel Scheffler
Browse files

Added 'kNN_SAM' to classification.classify_image().


Signed-off-by: Daniel Scheffler's avatarDaniel Scheffler <danschef@gfz-potsdam.de>
parent c6dd9c3b
Pipeline #4091 failed with stage
in 2 minutes and 10 seconds
...@@ -506,6 +506,7 @@ def classify_image(image, train_spectra, train_labels, classif_alg, in_nodataVal ...@@ -506,6 +506,7 @@ def classify_image(image, train_spectra, train_labels, classif_alg, in_nodataVal
'MinDist': Minimum Distance (Nearest Centroid) 'MinDist': Minimum Distance (Nearest Centroid)
'kNN': k-nearest-neighbour 'kNN': k-nearest-neighbour
'SAM': spectral angle mapping 'SAM': spectral angle mapping
'kNN_SAM': k-nearest neighbour spectral angle mapping
'FEDSA': fused euclidian distance / spectral angle 'FEDSA': fused euclidian distance / spectral angle
'SID': spectral information divergence 'SID': spectral information divergence
'RF': random forest 'RF': random forest
...@@ -542,6 +543,13 @@ def classify_image(image, train_spectra, train_labels, classif_alg, in_nodataVal ...@@ -542,6 +543,13 @@ def classify_image(image, train_spectra, train_labels, classif_alg, in_nodataVal
train_spectra, train_spectra,
CPUs=CPUs) CPUs=CPUs)
elif classif_alg == 'kNN_SAM':
kw = dict(k=kwargs['k']) if 'k' in kwargs else dict()
clf = kNN_SAM_Classifier(
train_spectra,
CPUs=CPUs,
**kw)
elif classif_alg == 'FEDSA': elif classif_alg == 'FEDSA':
clf = FEDSA_Classifier( clf = FEDSA_Classifier(
train_spectra, train_spectra,
...@@ -559,15 +567,16 @@ def classify_image(image, train_spectra, train_labels, classif_alg, in_nodataVal ...@@ -559,15 +567,16 @@ def classify_image(image, train_spectra, train_labels, classif_alg, in_nodataVal
CPUs=CPUs, **kwargs) CPUs=CPUs, **kwargs)
else: else:
raise NotImplementedError("Currently only the methods 'kNN', 'MinDist', 'SAM', 'FEDSA', 'SID' and 'RF' " raise NotImplementedError("Currently only the methods 'kNN', 'MinDist', 'SAM', 'kNN_SAM', "
"are implemented.") "'FEDSA', 'SID' and 'RF' are implemented.")
cmap = clf.classify(image, in_nodataVal=in_nodataVal, cmap_nodataVal=cmap_nodataVal, tiledims=tiledims) cmap = clf.classify(image, in_nodataVal=in_nodataVal, cmap_nodataVal=cmap_nodataVal, tiledims=tiledims)
# label unclassified pixels # label unclassified pixels
if unclassified_threshold is not None: if unclassified_threshold is not None:
if classif_alg not in ['MinDist', 'SAM', 'FEDSA', 'SID']: if classif_alg not in ['MinDist', 'SAM', 'kNN_SAM', 'FEDSA', 'SID']:
raise RuntimeError("Only the methods 'MinDist', 'SAM', 'FEDSA' and 'SID' can label unclassifed pixels.") raise RuntimeError("Only the methods 'MinDist', 'SAM', 'kNN_SAM', 'FEDSA' and 'SID' "
"can label unclassifed pixels.")
clf.label_unclassified_pixels(label_unclassified=unclassified_pixVal, threshold=unclassified_threshold) clf.label_unclassified_pixels(label_unclassified=unclassified_pixVal, threshold=unclassified_threshold)
...@@ -577,7 +586,7 @@ def classify_image(image, train_spectra, train_labels, classif_alg, in_nodataVal ...@@ -577,7 +586,7 @@ def classify_image(image, train_spectra, train_labels, classif_alg, in_nodataVal
else: else:
if classif_alg == 'MinDist': if classif_alg == 'MinDist':
dist = clf.euclidian_distance dist = clf.euclidian_distance
elif classif_alg == 'SAM': elif classif_alg in ['SAM', 'kNN_SAM']:
dist = clf.angles_deg dist = clf.angles_deg
elif classif_alg == 'FEDSA': elif classif_alg == 'FEDSA':
dist = clf.fedsa dist = clf.fedsa
......
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