Commit ff759434 authored by Daniel Scheffler's avatar Daniel Scheffler

Merge branch 'bugfix/fix_maxabsscaler' into 'master'

* Test image used for unittests is now a pseudo-random image instead of a true...

Closes #6

See merge request !4
parents f28a45db fdf971e0
Pipeline #18190 passed with stages
in 34 minutes and 2 seconds
......@@ -35,13 +35,22 @@ def normalize_endmembers_image(endmembers, image):
em = endmembers.astype(np.float)
im = image.astype(np.float)
# provide training values as 2D ROW (n samples x 1 feature),
# because normalization should be applied globally, not band-by-band
allVals = np.hstack([em.flat, im.flat]).reshape(-1, 1)
if allVals.min() < -1 or allVals.max() > 1:
max_abs_scaler = MaxAbsScaler()
max_abs_scaler.fit_transform(allVals)
endmembers_norm = max_abs_scaler.transform(em)
image_norm = spectra2im(max_abs_scaler.transform(im2spectra(im)), tgt_rows=im.shape[0], tgt_cols=im.shape[1])
max_abs_scaler.fit(allVals)
endmembers_norm = \
max_abs_scaler \
.transform(em.reshape(-1, 1)) \
.reshape(em.shape)
image_norm = \
max_abs_scaler \
.transform(im.reshape(-1, 1)) \
.reshape(im.shape)
return endmembers_norm, image_norm
......
......@@ -64,20 +64,23 @@ test_gA_pure_endmembers[:, :, :] = cluster_centers
# compute test image
def _get_testIm(shape, nodataVal):
# fix the random state to avoid different test images with each new test run (would be not comparable)
rand = np.random.RandomState(1234)
# get array full of nodata values
spec = np.full(shape, nodataVal).reshape(shape[0] * shape[1], shape[2])
# fill array with random spectra taken from the cluster centers
for i in range(cluster_centers.shape[0]):
spec[np.random.randint(spec.shape[0],
size=spec.shape[0]//10), :] = \
spec[rand.randint(spec.shape[0],
size=spec.shape[0]//10), :] = \
cluster_centers[i, :]
# fill remaining nodata positions with first spectrum
spec[spec[:, 0] == nodataVal, :] = cluster_centers[0, :]
# add 10% noise to each spectrum
noise_factor = np.random.normal(1, .1, spec.size).reshape(spec.shape)
noise_factor = rand.normal(1, .1, spec.size).reshape(spec.shape)
spec_out = spec * noise_factor
# return in desired image dimensions
......
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