Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions HyperSpectral/aceScoreCalculation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import numpy as np

#The Adaptive Cosine Estimator (ACE) algorithm is a popular method used in hyperspectral image processing for target detection.
#It determines the presence of a specific material within a hyperspectral image by calculating the normalized correlation between the spectrum of each pixel and a known target spectrum.

def aceScoreCalculation(spectrumValA1, spectrumValA2, spectrumValB1, spectrumValB2):
# Define the pixel spectrum and target spectrum
pixel_spectrum = np.array([spectrumValA1, spectrumValA2])
target_spectrum = np.array([spectrumValB1, spectrumValB2])

# Calculate dot products
numerator = np.dot(pixel_spectrum, target_spectrum)**2
denominator = np.dot(pixel_spectrum, pixel_spectrum) * np.dot(target_spectrum, target_spectrum)

# ACE score calculation
ace_score = numerator / denominator
print(f"ACE Score: {ace_score}")


10 changes: 10 additions & 0 deletions HyperSpectral/euclideanDistance.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import numpy as np

#calculating distance between two points
#points are np.arrays containing x and y coordinates only
#must exist within the same "space"

def calcEuclideanDist(x1, x2):
ed = np.sqrt(np.matmul(np.matrix.transpose(x1-x2),(x1-x2)))
print('The Euclidean distance is: ')
print(ed)
38 changes: 38 additions & 0 deletions HyperSpectral/matrixMath.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import numpy as np

#calculating Eigen values, Eigen vectors, and the Coefficient Matrix for a matrix
def matrixMath(matrix):
eigenValues, eigenVectors = np.linalg.eig(matrix)

print('The eigenvalues of the covariance matrix are: ')
print(eigenValues)

print('The eigenvectors for covariance matrix are: ')
print(eigenVectors)

coefficentMatrix = eigenVectors.transpose()
print('The coefficient matrix is: ')
print(coefficentMatrix)

return eigenValues, eigenVectors, coefficentMatrix

#calculate mean of matrix
def matrixMean(matrix):
mean = np.mean(matrix)
return mean

#calculate principal components of matrix values and arrays of x,y coordinates
def principalComponents(matrix, array1, array2):
mean = matrixMean(matrix)
eigenVal, eigenVectors, coefficientmatrix = matrixMath(matrix)

pcArray1 = np.matmul(coefficientmatrix, (array1-mean))
pcArray2 = np.matmul(coefficientmatrix, (array2-mean))

print('The Principal Component transformed value for array1 is: ');
print(pcArray1)

print('The Principal Component transformed value for array2 is: ');
print(pcArray2)

return pcArray1, pcArray2
14 changes: 14 additions & 0 deletions HyperSpectral/spectralAngle.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import numpy as np

# Calculate the angle between two vectors given positions in nonEuclidean space
def calculateSpectralAngle(spectralArray1, spectralArray2):
angle = np.arccos( (np.dot(spectralArray1, spectralArray2)) / (np.linalg.norm(spectralArray1)*(np.linalg.norm(spectralArray2))))

angleDeg = angle * (180.0/np.pi)
print('The Spectral Angle in radians is: ');
print(angle)

print('The Spectral Angle in degrees is: ');
print(angleDeg)

return angle, angleDeg