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
'MinDist': Minimum Distance (Nearest Centroid)
'kNN': k-nearest-neighbour
'SAM': spectral angle mapping
'kNN_SAM': k-nearest neighbour spectral angle mapping
'FEDSA': fused euclidian distance / spectral angle
'SID': spectral information divergence
'RF': random forest
......@@ -542,6 +543,13 @@ def classify_image(image, train_spectra, train_labels, classif_alg, in_nodataVal
train_spectra,
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':
clf = FEDSA_Classifier(
train_spectra,
......@@ -559,15 +567,16 @@ def classify_image(image, train_spectra, train_labels, classif_alg, in_nodataVal
CPUs=CPUs, **kwargs)
else:
raise NotImplementedError("Currently only the methods 'kNN', 'MinDist', 'SAM', 'FEDSA', 'SID' and 'RF' "
"are implemented.")
raise NotImplementedError("Currently only the methods 'kNN', 'MinDist', 'SAM', 'kNN_SAM', "
"'FEDSA', 'SID' and 'RF' are implemented.")
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', 'FEDSA', 'SID']:
raise RuntimeError("Only the methods 'MinDist', 'SAM', 'FEDSA' and 'SID' can label unclassifed pixels.")
if classif_alg not in ['MinDist', 'SAM', 'kNN_SAM', 'FEDSA', 'SID']:
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)
......@@ -577,7 +586,7 @@ def classify_image(image, train_spectra, train_labels, classif_alg, in_nodataVal
else:
if classif_alg == 'MinDist':
dist = clf.euclidian_distance
elif classif_alg == 'SAM':
elif classif_alg in ['SAM', 'kNN_SAM']:
dist = clf.angles_deg
elif classif_alg == '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