hyper-spectral image displays in not true color it shows in blue

4 views (last 30 days)
hello !. i am new to matlab ,
i used multibandread to display specific bands of a hyperspectral image and its spectral profile ( used raw or fla or int) ,
my problems is
1:the image displays but not in its normal color, it displays in blue ( adding photos and code related)
2:i want to get the spectral profile of each band ( i did already plot in the code but the spectrum i get seems not like the z-profile i get from envi)
3: can i display it in colors ?
( note iam using Matlab R2016a ,R2018a)
here is the code i made
I editied the code thanks to Guillaume to make it easier to read /cheers
thanks very much
filename = 'fvf01.fla';
lines = 1040;
samples = 1392;
bands = 31;
datatype = 'uint16';
offset = 0;
interleave = 'bsq';
byteorder = 'ieee-le';
bandtoread = 10;
bandname = sprintf('Band %d', bandtoread);
img = multibandread(filename, [lines, samples, bands], ...
datatype, offset, interleave, byteorder, ...
{'Band', 'Direct', bandtoread});
imagesc(img);
title(bandname);
  10 Comments
kefo
kefo on 15 Nov 2018
@Walter Roberson thanks very much . thats very helpful and useful link
sorry again for the mess up with my tags , didn't understand exactly how it works :D

Sign in to comment.

Accepted Answer

Guillaume
Guillaume on 14 Nov 2018
I'm sorry to say I'm struggling to understand what you're asking so my answer may be completely off the mark.
I think you may be better off loading the whole hyperspectral image as a 3D matrix, and then if you want to look at a specific band, just select the relevant slice of the 3d matrix. This would go like this:
filename = 'fvf01.fla';
lines = 1040;
samples = 1392;
bands = 31;
datatype = 'uint16';
offset = 0;
interleave = 'bsq';
byteorder = 'ieee-le';
img = multibandread(filename, [lines, samples, bands], ...
datatype, offset, interleave, byteorder); %read whole image
%img should be a 1040 x 1392 x 31 matrix
%to view a specific band
bandtoshow = 10;
imshow(img(:, :, bandtoshow));
title(sprintf('band %d', bandtoshow));
Note that I use imshow to display the band instead of imagesc. imshow defaults to a greyscale colourmap whereas imagesc uses pareto. You could always change the colourmap if you use imagesc:
imagesc(img(:, :, bandtoshow));
colormap(gray);
I don't think there is a function to display multispectral images in matlab (but I don't work with multispectral images). You could make a simple gui that allows you to see each band individually:
figure;
himg = imshow(img(:, :, 1));
hcontrol = uicontrol('style', 'popupmenu', 'String', compose('band %d', 1:bands), 'Position', [50 20 80 20], 'Callback', @(hcontrol, ~) set(himg, 'CData', img(:, :, hcontrol.Value)));
If you want to see the profile of a pixel along the bands, simply index your 3D matrix:
pixelrow = 50;
pixelcolumn = 20;
figure;
plot(squeeze(img(pixelrow, pixelcolumn, :)));
title(sprintf('Spectrum at x = %d, y = %d', pixelcolumn, pixelrow));
And this is how you'd plot all the spectrums along a given row:
row = 100;
figure;
plot(squeeze(img(row, :, :)));
legend(compose('band %d', 1:bands));
title(sprintf('Spectrum along row %d', row));
Hopefuly, this helps you do what you want.
  3 Comments
Guillaume
Guillaume on 14 Nov 2018
1- You're seeing a warning that the image is not displayed at a scale of 1:1. It's not an error. I think it's a stupid warning, You can turn it off with
warning('off', 'images:initSize:adjustingMag');
4- The idea is to plot the intensities along a single row of the image (2D) for each band. It may not be useful to you. Another way to visualise the same data which you may understand better:
row = 100;
figure;
ribbon(squeeze(img(row, :, :)));
xlabel('band');
ylabel('column');
title(sprintf('intensities at row %d', row));
kefo
kefo on 15 Nov 2018
@Guillaume good i got most of it now , and btw every thing works now fully combined ( image loaded, band selected and displayed in greyscale , dsplaying pixel spectrum , either single band on same and spectrum per figure or 4 bands and 4 plots in same figure with subplot
something like that
there is no words i can express with my gratitude and admire for your generosity, kindness, knowlage and patience , i have learned alot from you and looking forward for more cooperations later.
we learn from the masters of the profession
so thanks very much again and again . its really was nice to meet you and to keep as friend . /friendship highfive
fig.PNG
figure ;
subplot(2, 2, 1)
plot(squeeze(image(pixelrow1, pixelcolumn1, :)));
title(sprintf('Spectrum at x = %d, y = %d', pixelcolumn1, pixelrow1));

Sign in to comment.

More Answers (1)

R Akshay
R Akshay on 22 Jun 2020
Hi
I am trying to plot a spectrum of the hyperspectral image captured using SpecimIQ camera. On using the above mentioned code to plot the spectrum profile of the i could not get any output.
Used this same code as mentioned above.
figure ;
plot(squeeze(image(pixelrow1, pixelcolumn1, :)));
title(sprintf('Spectrum at x = %d, y = %d', pixelcolumn1, pixelrow1));
my image size is 512*512 and has 204 bands in it.
but output of spectrum profile shows blank output.
  2 Comments
Image Analyst
Image Analyst on 22 Jun 2020
Edited: Image Analyst on 23 Jun 2020
What does this produce in the command window
spectrum = YourImage(pixelrow1, pixelcolumn1, :) % Don't use a semicolon.
Also, don't use image as the name of your variable. When you say plot(squeeze(image(pixelrow1, pixelcolumn1, :))); it might be calling the function called image() instead of referencing your variable. Probably not if you defined image beforehand, but still, it's very bad practice to name your function after built-in functions.

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!