Commit fdf971e0 authored by Daniel Scheffler's avatar Daniel Scheffler
Browse files

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

* Test image used for unittests is now a pseudo-random image instead of a true random image to ensure comparable results.
* Fixed issue #6

 (ValueError: X has 6 features, but MaxAbsScaler is expecting 1 features as input.).

Signed-off-by: Daniel Scheffler's avatarDaniel Scheffler <danschef@gfz-potsdam.de>
parent f28a45db
Pipeline #18189 passed with stage
in 6 minutes and 14 seconds
...@@ -35,13 +35,22 @@ def normalize_endmembers_image(endmembers, image): ...@@ -35,13 +35,22 @@ def normalize_endmembers_image(endmembers, image):
em = endmembers.astype(np.float) em = endmembers.astype(np.float)
im = image.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) allVals = np.hstack([em.flat, im.flat]).reshape(-1, 1)
if allVals.min() < -1 or allVals.max() > 1: if allVals.min() < -1 or allVals.max() > 1:
max_abs_scaler = MaxAbsScaler() max_abs_scaler = MaxAbsScaler()
max_abs_scaler.fit_transform(allVals) max_abs_scaler.fit(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]) 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 return endmembers_norm, image_norm
......
...@@ -64,20 +64,23 @@ test_gA_pure_endmembers[:, :, :] = cluster_centers ...@@ -64,20 +64,23 @@ test_gA_pure_endmembers[:, :, :] = cluster_centers
# compute test image # compute test image
def _get_testIm(shape, nodataVal): 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 # get array full of nodata values
spec = np.full(shape, nodataVal).reshape(shape[0] * shape[1], shape[2]) spec = np.full(shape, nodataVal).reshape(shape[0] * shape[1], shape[2])
# fill array with random spectra taken from the cluster centers # fill array with random spectra taken from the cluster centers
for i in range(cluster_centers.shape[0]): for i in range(cluster_centers.shape[0]):
spec[np.random.randint(spec.shape[0], spec[rand.randint(spec.shape[0],
size=spec.shape[0]//10), :] = \ size=spec.shape[0]//10), :] = \
cluster_centers[i, :] cluster_centers[i, :]
# fill remaining nodata positions with first spectrum # fill remaining nodata positions with first spectrum
spec[spec[:, 0] == nodataVal, :] = cluster_centers[0, :] spec[spec[:, 0] == nodataVal, :] = cluster_centers[0, :]
# add 10% noise to each spectrum # 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 spec_out = spec * noise_factor
# return in desired image dimensions # return in desired image dimensions
......
Supports Markdown
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