How do I extract data from a specific point I click on a hyperspectral image?

32 views (last 30 days)
I have a hypercube created with the hypercube() function and was able to display the hyperspectral image using colorize(). I am now wondering how I can click on a specific point on the image and extract the hyperspectral data. I tried using [x, y] = ginput(1), but that only gives me the x and y coordinates on the image itself, not the data associated what those coordinated.
Any help would be appreciated.
Thanks, and let me know if more information is needed.

Answers (2)

Abhishek Tripathi
Abhishek Tripathi on 6 Nov 2024 at 4:16
Hi Keegan,
There is one way to extract data from a specific point in your hyperspectral data: by using our Hyperspectral Viewer app. This app allows you to interactively explore and analyze your hyperspectral dataset. With it, you can view individual bands as grayscale images or create color composite representations like RGB, color-infrared (CIR), and false-color images. You can also visualize various hyperspectral indices directly in the app.
For point-specific data extraction, simply click on a location of interest in the image. The app generates a "spectral profile" for that point, displaying its spectral signature across all bands. This is a powerful way to identify materials or elements within the hyperspectral data. Additionally, you can plot and export spectral profiles for small regions, giving insight into the spectral characteristics of selected areas.
For more detailed instructions, please refer to our guide on exploring hyperspectral data in the Hyperspectral Viewer app.

Sameer
Sameer on 4 Nov 2024 at 17:58
To extract hyperspectral data from a specific point after selecting it with "ginput", follow these steps:
1. Use "ginput(1)" to get the x and y coordinates of the point you clicked.
2. Convert the coordinates to indices that correspond to your data array. This typically involves rounding the values.
3. Extract the data from the hypercube using these indices.
Here's a sample code snippet
% Assuming 'hcube' is your hypercube object
colorize(hcube);
% Get a point from the user
[x, y] = ginput(1);
% Convert to integer indices
xIndex = round(x);
yIndex = round(y);
% Extract the hyperspectral data for the selected point
spectralData = squeeze(hcube.DataCube(yIndex, xIndex, :));
% Plot the spectral data
figure;
plot(spectralData);
xlabel('Band Number');
ylabel('Reflectance');
title('Spectral Signature at Selected Point');
Hope this helps!

Products


Release

R2023b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!