Commit 090aef8a authored by Daniel Scheffler's avatar Daniel Scheffler
Browse files

Updated classify_image().


Signed-off-by: Daniel Scheffler's avatarDaniel Scheffler <danschef@gfz-potsdam.de>
parent 226a7a5b
Pipeline #3998 failed with stage
in 2 minutes and 8 seconds
......@@ -473,11 +473,12 @@ def classify_image(image, train_spectra, train_labels, classif_alg, in_nodataVal
:param train_labels:
:param classif_alg: algorithm to be used for image classification
(to define which cluster each pixel belongs to)
'MinDist': Minimum Distance (Nearest Centroid)
'kNN': k-nearest-neighbour
'SAM': spectral angle mapping
'SID': spectral information divergence
'RF': random forest
'MinDist': Minimum Distance (Nearest Centroid)
'kNN': k-nearest-neighbour
'SAM': spectral angle mapping
'FEDSA': fused euclidian distance / spectral angle
'SID': spectral information divergence
'RF': random forest
:param in_nodataVal:
:param cmap_nodataVal:
:param tiledims:
......@@ -511,6 +512,11 @@ def classify_image(image, train_spectra, train_labels, classif_alg, in_nodataVal
train_spectra,
CPUs=CPUs)
elif classif_alg == 'FEDSA':
clf = FEDSA_Classifier(
train_spectra,
CPUs=CPUs)
elif classif_alg == 'SID':
clf = SID_Classifier(
train_spectra,
......@@ -523,14 +529,15 @@ 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', 'SID' and 'RF' are implemented.")
raise NotImplementedError("Currently only the methods 'kNN', 'MinDist', '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', 'SID']:
raise RuntimeError("Only the methods 'MinDist', 'SAM' and 'SID' can label unclassifed pixels.")
if classif_alg not in ['MinDist', 'SAM', 'FEDSA', 'SID']:
raise RuntimeError("Only the methods 'MinDist', 'SAM', 'FEDSA' and 'SID' can label unclassifed pixels.")
clf.label_unclassified_pixels(label_unclassified=unclassified_pixVal, threshold=unclassified_threshold)
......@@ -542,6 +549,8 @@ def classify_image(image, train_spectra, train_labels, classif_alg, in_nodataVal
dist = clf.euclidian_distance
elif classif_alg == 'SAM':
dist = clf.angles_deg
elif classif_alg == 'FEDSA':
dist = clf.fedsa
elif classif_alg == 'SID':
dist = clf.sid
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