Residual image cannot be generated due to shape differences
Hey there,
I tried to generate a residual image but received a value error stating that residual image cannot be reshaped into the shape of the actual image.
The issue seems to be in the _residual_image() function and image_as_line attribute:
In the former this line
residuals = self.image_as_line - np.sum(fractions[np.newaxis, :, 0:-1] * endmembers, axis=2)
gives a value error because the shapes within the np.sum() are different. If I am not mistaking, this first issue is that the class axis is subset instead of the first spatial axis and the second one is that summation is not done over the class axis. I think this solves the first two problems inside the np.sum():
residuals = self.image_as_line - np.sum(fractions[np.newaxis, 0:-1, :] * endmembers, axis=1)
Furthermore, the image_as_line attribute does not have the no_data_pixels, resulting in a different number of pixels compared to the result of np.sum(). Instead the image can be used like:
residuals = image - np.sum(fractions[np.newaxis, 0:-1, :] * endmembers, axis=1)
I hope this makes sense.
Best, Marcel
Comments (2)
-
-
OK, the problem seems to be in line 568 in mesma.py where residuals should be changed to residuals_expanded.
The original code is:
return (np.reshape(models_expanded.T, (self.n_classes,) + image_dimensions), np.reshape(fractions_expanded.T, (self.n_classes + 1,) + image_dimensions), np.reshape(rmse_expanded, image_dimensions), np.reshape(residuals, image.shape))
and I think the problem is solved with this one:
return (np.reshape(models_expanded.T, (self.n_classes,) + image_dimensions), np.reshape(fractions_expanded.T, (self.n_classes + 1,) + image_dimensions), np.reshape(rmse_expanded, image_dimensions), np.reshape(residuals_expanded, image.shape))
- Log in to comment
Above statement can be ignored: I figured out that I did my testing on 3D arrays while fractions and models are 2D arrays inside the functions.
Yet, the problem persists and is related to the no_data_pixels: