Closed jason-brown904 closed 3 years ago
Just to be clear, when you say "replace the PC1 with another image" you mean to just replace the first PC vector with the first PC vector from another image? That is, you want to replace one of the actual eigenvectors (not an image raster layer in PC space).
Yes, then inverse transform.
Well, there's not a "method" to do that per se but I think you could create a hack to do it. The principal_components
function just returns a PrincipalComponents
object. If you look at the methods in that class, you could fairly easily create a subclass to do it.
Here's some completely untested code, which may do what you want:
from spectral.algorithms.algorithms import PrincipalComponents
from spectral.algorithms.transforms import LinearTransform
class PCFuser(PrincipalComponents):
def __init__(self, pc):
super().__init__(pc.eigenvalues, pc.eigenvectors, pc.stats)
def get_fused_image(self, image, V_mod):
V = self.eigenvectors
f = LinearTransform(V_mod.dot(V.T), pre=-self.mean,
post=self.mean)
return f(image)
Then, to use it:
pc = spy.principal_components(X)
# Replace the first eigenvector (column) in a new array
vecs = np.array(pc.eigenvectors)
vecs[:, 0] = some_other_vector
# Compute the fused image
pcf = PCFuser(pc)
fused_image = pcf.get_fused_image(X, vecs)
Let me know if that works for you. One thing I'll point out though...
If you replace one of the eigenvectors without doing some additional voodoo, it is likely that your eigenvectors will no longer be orthogonal. So if you intend to use that PC object for doing any other operations (denoising, etc.), all warranties are voided.
I should also point out that there were no warranties to begin with ;-)
Thanks! I'll give it a try and let you know how it works out. #nowarranties
Closing due to lack of activity.
I'm curious if there is a method to do an inverse PCT with Spectral?
I want to do a PCT fusion like this: 1) take the PCT of a multispectral image 2) replace the PC1 with another image 3) inverse PCT 4) display fused image
Is that possible with principal_components() ?