From 0656f7df482ef09e30a0b7e94a0af75d3d88d9a4 Mon Sep 17 00:00:00 2001 From: Anthony Agby Date: Tue, 20 May 2025 14:20:26 -0400 Subject: [PATCH 1/5] add Ace Score Calculation --- HyperSpectral/aceScoreCalculation.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 HyperSpectral/aceScoreCalculation.py diff --git a/HyperSpectral/aceScoreCalculation.py b/HyperSpectral/aceScoreCalculation.py new file mode 100644 index 0000000..5c16a59 --- /dev/null +++ b/HyperSpectral/aceScoreCalculation.py @@ -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}") + + From 41d38102d555ce197b7944a0038e4bead0f3ca7d Mon Sep 17 00:00:00 2001 From: Anthony Agby Date: Tue, 20 May 2025 14:26:29 -0400 Subject: [PATCH 2/5] add euclidean distance --- HyperSpectral/euclideanDistance.py | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 HyperSpectral/euclideanDistance.py diff --git a/HyperSpectral/euclideanDistance.py b/HyperSpectral/euclideanDistance.py new file mode 100644 index 0000000..0b2593e --- /dev/null +++ b/HyperSpectral/euclideanDistance.py @@ -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) \ No newline at end of file From 0c97cab7a0c15f74fc1dfd043c848419c5a57952 Mon Sep 17 00:00:00 2001 From: Anthony Agby Date: Tue, 20 May 2025 14:35:11 -0400 Subject: [PATCH 3/5] add matrix math --- HyperSpectral/matrixMath.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 HyperSpectral/matrixMath.py diff --git a/HyperSpectral/matrixMath.py b/HyperSpectral/matrixMath.py new file mode 100644 index 0000000..85f00e8 --- /dev/null +++ b/HyperSpectral/matrixMath.py @@ -0,0 +1,17 @@ +import numpy as np + +#calculating Eigen values, Eigen vectors, and the Coefficient Matrix for a matrix +def matrixMath(valA1, valA2, valB1, valB2): + matrix = np.array([[valA1, valA2], [valB1, valB2]], dtype=float) + + 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) \ No newline at end of file From 4df818cdeb14f6851c45e98a56916716f0a7608c Mon Sep 17 00:00:00 2001 From: Anthony Agby Date: Tue, 20 May 2025 14:52:26 -0400 Subject: [PATCH 4/5] additional math for mean and PC --- HyperSpectral/matrixMath.py | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/HyperSpectral/matrixMath.py b/HyperSpectral/matrixMath.py index 85f00e8..da166dd 100644 --- a/HyperSpectral/matrixMath.py +++ b/HyperSpectral/matrixMath.py @@ -1,9 +1,7 @@ import numpy as np #calculating Eigen values, Eigen vectors, and the Coefficient Matrix for a matrix -def matrixMath(valA1, valA2, valB1, valB2): - matrix = np.array([[valA1, valA2], [valB1, valB2]], dtype=float) - +def matrixMath(matrix): eigenValues, eigenVectors = np.linalg.eig(matrix) print('The eigenvalues of the covariance matrix are: ') @@ -14,4 +12,27 @@ def matrixMath(valA1, valA2, valB1, valB2): coefficentMatrix = eigenVectors.transpose() print('The coefficient matrix is: ') - print(coefficentMatrix) \ No newline at end of file + 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 \ No newline at end of file From 9ffb698667ed02907182b7766deac0d5601deda1 Mon Sep 17 00:00:00 2001 From: Anthony Agby Date: Tue, 20 May 2025 14:57:02 -0400 Subject: [PATCH 5/5] add spectral angle calculation --- HyperSpectral/spectralAngle.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 HyperSpectral/spectralAngle.py diff --git a/HyperSpectral/spectralAngle.py b/HyperSpectral/spectralAngle.py new file mode 100644 index 0000000..0a30d97 --- /dev/null +++ b/HyperSpectral/spectralAngle.py @@ -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 \ No newline at end of file