MATLAB Answers

Regarding Hyperspectral Image Processing

15 views (last 30 days)
R Akshay
R Akshay on 29 Sep 2020
Answered: Subhadeep Koley on 2 Nov 2020
Hi Everyone,
I am Akshay, I am working with (SPECIM IQ), it is a hyperspectral camera. After clicking the image, the output of the camera comes with ENVI format. It generates a 3D cube of data( with 2 axis would be pixel information and 3rd axis will contain the wavelength information. Now i want a code in such a way that when i keep a cursor on any particular pixel it should plot a graph with x axis being wavelength and y axis being intensity for that particular pixel location.
Thanks

  0 Comments

Sign in to comment.

Answers (2)

Image Analyst
Image Analyst on 15 Oct 2020
You could do this:
[rows, columns, numWavelengths] = size(image3dcube)
spectrum = zeros(1, numWavelengths);
for w = 1 : numWavelengths
spectrum(w) = image3dcube(row, column, w); % You need to specify which row and column.
end
plot(spectrum, 'b.-', 'LineWidth', 2, 'MarkerSize', 18);
grid on;
xlabel('Wavelength [image slice]', 'FontSize', 17);
ylabel('Spectral Reflectance [gray levels]', 'FontSize', 17);
caption = sprintf('Spectral Reflectance at x (column) = %d, y (row) = %d vs. Wavelength', column, row);
title(caption, 'FontSize', 17);
Or you could do this (somewhat more cryptic way) instead of the zeros() and for loop, if you want a "vectorized" solution (though I don't think there won't be any time difference between the two methods):
spectrum = squeeze(image3dcube(row, column, :));

  2 Comments

R Akshay
R Akshay on 16 Oct 2020
Thank you very much for the reply regarding the query. After capturing the image from the SPECIM camera. I get an output in a folder consisiting of 3subfolder folders( capture, metadata, result) and under that sub files in different file format. opening the file directly is not possible in matlab. So it is difficult to find that which file contains the 3D data cube in order to plot the wavelength spectrum.
.
I have written a code which shows me the image of a particular band and gives the intensity plot of particular (single band).
clc;
clear;
filename = '044.raw';
lines = 512;
samples = 512;
bands = 204;
datatype = 'int16';
offset = 0;
interleave = 'bil';
byteorder = 'ieee-le';
bandtoread =100;
bandtoread1 =101;
wavelength =397.32+(2.97*bandtoread);
wavelength1 =397.32+(2.97*bandtoread1);
bandname = sprintf('Band %d \nwavelength %3.3f', bandtoread, wavelength);
bandname1 = sprintf('Band %d \nwavelength %3.3f', bandtoread1, wavelength1);
img = multibandread(filename, [lines, samples, bands], ...
datatype, offset, interleave, byteorder, ...
{'Band', 'Direct', bandtoread});
img1 = multibandread(filename, [lines, samples, bands], ...
datatype, offset, interleave, byteorder, ...
{'Band', 'Direct', bandtoread1});
% img1 = multibandread(filename, [lines, samples, bands], ...
% datatype, offset, interleave, byteorder, ...
% {'Band', 'Direct', bandtoread});
subplot(2,2,1);
imagesc(img);
% colormap(gray);
title(bandname);
subplot(2,2,2);
imagesc(img1);
% colormap(gray);
title(bandname1);
subplot(2,2,3);
plot(squeeze(img(278,:)))
title(sprintf('Spectrum along x'));
subplot(2,2,4);
plot(squeeze(img(336,:)))
title(sprintf('Spectrum along y'));
legend(compose('band %d',bands));
figure
imgfinal=img-img1;
subplot (2,2,1)
imagesc(img);
% colormap(gray);
subplot (2,2,2)
imagesc(img1);
% colormap(gray);
subplot (2,2,3)
imagesc(imgfinal);
% colormap(gray);
% title(sprintf('Spectrum along row', row));
% figure;
% himg = imshow(img(100,100));
% % himg = imagesc(img(:, :,:));
% hcontrol = uicontrol('style', 'popupmenu', 'String', compose('band %d', 1:bandtoread), 'Position', [0 512 512,0], 'Callback', @(hcontrol, ~) set(himg, 'CData', img(:, :, hcontrol.Value)));
% X= multibandread('044.bsq', [512,512,204],'int16',0, 'bsq', 'ieee-be');
And this is the output of the code.
So I would request you to kindly help me with the code depending on the folder name in order to refer the file or folder to access the data and to plot a spectrum plot.
Thanks and Regards
Image Analyst
Image Analyst on 16 Oct 2020
You mean like this?
% Have user browse for a file, from a specified "starting folder."
% For convenience in browsing, set a starting folder from which to browse.
startingFolder = pwd; % or 'C:\wherever';
if ~isfolder(startingFolder)
% If that folder doesn't exist, just start in the current folder.
startingFolder = pwd;
end
% Get the name of the file that the user wants to use.
defaultFileName = fullfile(startingFolder, '*.*');
[baseFileName, folder] = uigetfile(defaultFileName, 'Select a file');
if baseFileName == 0
% User clicked the Cancel button.
return;
end
fullFileName = fullfile(folder, baseFileName)

Sign in to comment.


Subhadeep Koley
Subhadeep Koley on 2 Nov 2020
Hi, for reading a hypersepctral image in ENVI format you can use the hypercube function. E.g.,
% Read the ENVI format data
hCube = hypercube('yourENVIImage.hdr');
% Extract the 3D cube of data from the 'hCube' object
dataCube = hCube.DataCube;
For visualization of individual pixel spectra / hyperspectral image in different color schemes (False-coloured, RGB, CIR), you can use the interactive hyperspetralViewer App. E.g.,
hyperspectralViewer(hCube)
All the above mentioned fetures come under Image Processing Toolbox's Hyperspectral Imaging Library support package, and can be downloaded from here. For more information on Hyperspectral Imaging Library see the documentation.

  0 Comments

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!