Commit 681a4ea7 authored by Daniel Scheffler's avatar Daniel Scheffler
Browse files

Bugfix for homogenization exception in case the source image tile consists only of no data values.

parent 9c9ec8ea
Pipeline #2970 failed with stage
in 17 minutes and 15 seconds
......@@ -1712,10 +1712,11 @@ class Cluster_Learner(object):
"""
cluster_labels = sorted(list(np.unique(cmap)))
im_pred = np.full((im_src.shape[0], im_src.shape[1], self.tgt_n_bands), nodataVal, dtype=im_src.dtype)
if len(cluster_labels) > 1:
# iterate over all cluster labels and apply corresponding machine learner parameters
# to predict target spectra
im_pred = np.empty((im_src.shape[0], im_src.shape[1], self.tgt_n_bands), dtype=im_src.dtype)
for pixVal in cluster_labels:
if pixVal == nodataVal:
......@@ -1726,10 +1727,16 @@ class Cluster_Learner(object):
im_pred[mask_pixVal] = classifier.predict(im_src[mask_pixVal]).astype(im_src.dtype)
else:
# predict target spectra directly
spectra = im2spectra(im_src)
classifier = self.MLdict[cluster_labels[0]]
spectra_pred = classifier.predict(spectra).astype(im_src.dtype)
im_pred = spectra2im(spectra_pred, im_src.shape[0], im_src.shape[1])
# predict target spectra directly (much faster than the above algorithm)
pixVal = cluster_labels[0]
if pixVal != nodataVal:
spectra = im2spectra(im_src)
classifier = self.MLdict[pixVal]
spectra_pred = classifier.predict(spectra).astype(im_src.dtype)
im_pred = spectra2im(spectra_pred, im_src.shape[0], im_src.shape[1])
else:
# im_src consists only of no data values
pass # im_pred keeps at nodataVal
return im_pred
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