MATLAB: How to combine three hyperspectral bands into an “RGB” image

concatenateenvihyperspectralimageImage Processing Toolboxrgb

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')

Best Answer

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.
Related Question