# How can I combine three hyperspectral bands into an "RGB" image?

16 visualizaciones (últimos 30 días)
Max1000000 el 22 de Mayo de 2015
Respondida: Subhadeep Koley el 31 de Mzo. de 2021
I've used a toolbox to import files from ENVI and I have verified that they imported correctly. I can easily isolate the individual bands I want (if A is the image matrix then R = A(:,:,1) gets the 2D image for the first band) and they prove to be exactly what ENVI shows for individual bands, but when I combine them with cat (cat(3,R,G,B)) they seem to change drastically and lose all their detail (just a weird pixelly image of 1 or 2 colors).
Example code:
% Indicate what bands are Red, Green, and Blue % Red = 1; Green = 2; Blue = 3;
% Combines Red, Green and Blue channels to form an image
R = A(:,:,Red);
G = A(:,:,Green);
B = A(:,:,Blue);
% simply shows the separate R, G B images
figure(1);
subplot(1,3,1); imshow(R,[]); title('Red')
subplot(1,3,2); imshow(G,[]); title('Green')
subplot(1,3,3); imshow(B,[]); title('Blue')
RGBimage = cat(3, R, G, B);
figure(2); imshow(RGBimage,[]); title('RGB Image')
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

Image Analyst el 22 de Mayo de 2015
The ranges of the individual R, G, and B may be way different. You might want to use mat2gray() to equalize them. Or else scale them all to one min and max. Attach a .mat file with A in it if you want more help.
##### 4 comentariosMostrar 2 comentarios más antiguosOcultar 2 comentarios más antiguos
Image Analyst el 26 de Mayo de 2015
I have no idea what that File Exchange submission does. Can you attach a screenshot?
Max1000000 el 27 de Mayo de 2015
I actually ended up figuring it out using the File Exchange submission and rgb2gray to allow for colormaps.
Thanks for the help!

Iniciar sesión para comentar.

### Más respuestas (3)

Walter Roberson el 26 de Mayo de 2015
If you use cat(3) to combine bands into an RGB matrix and display that, then the result is a TrueColor image and colormap does not apply to TrueColor data. If you want to be able to manipulate the three images by changing colormap without redrawing the image object, then you will need to use multiple graphic objects. However in such a case how the pixels interact to form display color would be a significant consideration.
Possibly what would work for you is if you took the cat(3) result and you used rgb2ind() on it, producing both an indexed image and a colormap. Then you could manipulate the active colormap. If you did this then the triple would be mapped into an index once and those locations would change together with the colormap changes. If you need the three layers to have their colormaps individually alterable, that is potentially possible but the visual combination would be dubious. Perhaps you are looking for transparency, AlphaData, and manipulating that to show or hide the layers?
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

Image Analyst el 8 de Mzo. de 2017
See this paper, which goes into great detail on the hyperspectral to RGB conversion process: http://my.ece.msstate.edu/faculty/du/JSTARS-VIS.pdf
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

Subhadeep Koley el 31 de Mzo. de 2021
You can use the hypercube(__) function to read your ENVI file (.dat and .hdr file pair), and also the colorize(__) method will help you to estimate the RGB color image automatically.
% Read the ENVI format image (specify your image file name here)
hCube = hypercube('paviaU.hdr');
% Estimate the RGB image
rgbImg = colorize(hCube, 'method', 'rgb', 'ContrastStretching', true);
% Visualize the RGB image
figure
imshow(rgbImg)
title('RGB image')
NOTE: 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 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

### Categorías

Más información sobre Hyperspectral Image Processing en Help Center y File Exchange.

### Community Treasure Hunt

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

Start Hunting!

Translated by