RGB % values of an image (MATLAB code)

 I = imread('C:\xxx.jpg');
rgb_percent = squeeze(sum(sum(I,1),2))/sum(I(:))*100

rgb_percent =

   27.3365
   34.4873
   38.1762

RGB band combination of Satellite image data (MATLAB code)


RGB band combination
% ---------------------------- VNIR or CIR --------------------------------
% Pull bands 3N, 2, and 1 from the HDF file into their own matrices. These
% bands are in the VNIR (aka CIR) range and will highlight actively
% photosynthesizing vegetation (showns as red), undisturbed bedrock and
% soils (browns, greens, and greys), and the built environment (blues,
% greens, reddish-purples, and whites)
Band_3 = hdfread('SPCraterASTERData.hdf','VNIR_Swath','Fields','ImageData3N');
Band_2 = hdfread('SPCraterASTERData.hdf','VNIR_Swath','Fields','ImageData2');
Band_1 = hdfread('SPCraterASTERData.hdf','VNIR_Swath','Fields','ImageData1');

% Construct an RGB matrix from the three bands into one 3D matrix.
SPCrater_321 = cat(3,Band_3,Band_2,Band_1);

% Display the image
figure(1)
imshow(SPCrater_321)
xlabel('Longitude (pixels)')
ylabel('Latitude (pixels)')
title('ASTER Bands 3, 2, 1')

shortwave infrared of Satellite image data (MATLAB code)


Here is the shortwave infrared (SWIR):
% ---------------------------- SWIR ---------------------------------------
% Pull bands 8, 6, and 4 from the HDF file into their own matrices. These
% bands are in the SWIR range and will highlight spectral features
% diagnostic for iron oxides, illite, kaolinite, and carbonates.
Band_8 = hdfread('SPCraterASTERData.hdf','SWIR_Swath','Fields','ImageData8');
Band_6 = hdfread('SPCraterASTERData.hdf','SWIR_Swath','Fields','ImageData6');
Band_4 = hdfread('SPCraterASTERData.hdf','SWIR_Swath','Fields','ImageData4');

% Construct an RGB matrix from the three bands into one 3D matrix.
SPCrater_864 = cat(3 , Band_8 , Band_6 , Band_4);

% Perform histogram equalization stretch on the image
for i=1:3
    SPCrater_864_stretch(:,:,i)=histeq(SPCrater_864(:,:,i));
end
% Display the image
figure(3)
imshow(SPCrater_864_stretch)
xlabel('Longitude (pixels)')
ylabel('Latitude (pixels)')
title('ASTER Bands 8, 6, 4')


Thermal Infrared of Satellite image data (MATLAB code)


Thermal Infrared:
% -------------------------- TIR ------------------------------------------
% Pull bands 13, 12, and 10 from the HDF file into their own matrices.
% These bands are in the TIR range and will highlight spectral features
% diagnostic for silicates, iron- and magnesium-bearing minerals and rocks,
% and carbonates. Quartzites are bright red, basaltic rocks are blue,
% granitoids are purple-violet, and carbonates are greenish yellow.
Band_13 = hdfread('SPCraterASTERData.hdf','TIR_Swath','Fields','ImageData13');
Band_12 = hdfread('SPCraterASTERData.hdf','TIR_Swath','Fields','ImageData12');
Band_10 = hdfread('SPCraterASTERData.hdf','TIR_Swath','Fields','ImageData10');

% Construct an RGB matrix from the three bands into one 3D matrix.
SPCrater_131210 = cat(3 , Band_13 , Band_12 , Band_10);

% Do a decorrelation stretch to enhance differences in colors.
SPCrater_131210_decorr = decorrstretch(SPCrater_131210,'Tol',0.01);

% Display the image
figure(4)
imshow(SPCrater_131210_decorr)
xlabel('Longitude (pixels)')
ylabel('Latitude (pixels)')
title('ASTER Bands 13, 12, 10')

Normalized Difference Vegetation Index of Satellite Image data (MATLAB code)


Normalized Difference Vegetation Index is a single band image derived from mathematical combinations of bands which measure the responce of vegetation very differently. This image is a measure of relative amounts of green vegetation. The NDVI is computed as: (Band_3 - Band_2) ./ (Band_3 + Band_2).
% ---------------------------- NDVI ---------------------------------------
% Compute the Normalized Difference Vegetation Index (NDVI) using the following
% formula: [(Band_3 - Band_2)./(Band_3 + Band_2)]. The NDVI shows the relative
% abundance of actively photosynthesizing vegetation. In other words, it
% assesses how healthy the vegetation is!

% Pull the bands.
Band_3 = hdfread('SPCraterASTERData.hdf','VNIR_Swath','Fields','ImageData3N');
Band_2 = hdfread('SPCraterASTERData.hdf','VNIR_Swath','Fields','ImageData2');
Band_1 = hdfread('SPCraterASTERData.hdf','VNIR_Swath','Fields','ImageData1');

% Calculate NDVI.
% Before we can calculate this, let's look at the format (aka "class" of
% Bands 1, 2, and 3 in the MATLAB Workspace. You will notice that they are
% "uint8", which means they are 8-bit integers! This isn't useful to us,
% especially if we want to do division because division of integers can
% only result in whole numbers. So, we first need to convert these bands to
% a class known as "single" so that we can do some band ratioing!
Band_2 = im2single(Band_2);
Band_3 = im2single(Band_3);
SPCrater_NDVI = (Band_3 - Band_2) ./ (Band_3 + Band_2);

% Display the image.
figure(5)
% Note that because the range of numbers in our NDVI ratio is between
% 0 and 1, we need to display the image's colors using an appropriate scale
% [0 1]
imshow(SPCrater_NDVI,'DisplayRange',[0 1])
xlabel('Longitude (pixels)')
ylabel('Latitude (pixels)')
title('NDVI computed from ASTER Image')