Modifying the NDBI values using MODIS bands data

조회 수: 3 (최근 30일)
Vipasha Sharma
Vipasha Sharma 2022년 2월 8일
import matlab.io.hdfeos.*
import matlab.io.hdf4.*
for i=1
direc=strcat('F:\Bands_data\Terra\');
cd(direc)
files = dir(fullfile( '*.hdf'));
for j=1:size(files,1)
filename=files(j).name;
FILE_NAME=strcat('F:\Bands_data\Terra\',filename);
GRID_NAME='MOD_Grid_500m_Surface_Reflectance';
DATAFIELD_NAME='sur_refl_b01';
file_id = gd.open(FILE_NAME, 'rdonly');
grid_id = gd.attach(file_id, GRID_NAME);
data = gd.readField(grid_id, DATAFIELD_NAME, [], [], []);
[xdimsize, ydimsize, upleft,lowright] = gd.gridInfo(grid_id);
gd.detach(grid_id);
gd.close(file_id);
data=double(data);
data=data';
SD_id = sd.start(FILE_NAME, 'rdonly');
sds_index = sd.nameToIndex(SD_id, DATAFIELD_NAME);
sds_id = sd.select(SD_id, sds_index);
fillvalue_index = sd.findAttr(sds_id, '_FillValue');
fillvalue = sd.readAttr(sds_id, fillvalue_index);
long_name_index = sd.findAttr(sds_id, 'long_name');
long_name = sd.readAttr(sds_id, long_name_index);
units_index = sd.findAttr(sds_id, 'units');
units = sd.readAttr(sds_id, units_index);
scale_index = sd.findAttr(sds_id, 'scale_factor');
scale = sd.readAttr(sds_id, scale_index);
scale = double(scale);
offset_index = sd.findAttr(sds_id, 'add_offset');
offset = sd.readAttr(sds_id, offset_index);
range_index = sd.findAttr(sds_id, 'valid_range');
range = sd.readAttr(sds_id, range_index);
sd.endAccess(sds_id);
sd.close(SD_id);
data(data==fillvalue) = NaN;
data(data < range(1)) = NaN;
data(data > range(2)) = NaN;
data = (data - offset) * scale;
Band1(:,:,j)=data;
clear data
j
end
end
clearvars -except Band2 Band6 Band1
%%
b1=mean(Band1,3,'omitNaN');
b2=mean(Band2,3,'omitNaN');
b6=mean(Band6,3,'omitNaN');
b7=mean(Band7,3,'omitNaN');
%%
NDBI=(double(b6)-double(b2))./(double(b6)+double(b2));
ndbire=griddata(double(lat),double(lon),NDBI,h24v6lat,h24v6lon);
reshapeAOD=reshape(MeanAOD,1697000,1);
reshapeNDBI=reshape(ndbire,1697000,1);
reshapeddatandbi=cat(2,reshapeAOD, reshapeNDBI);
reshapeddatandbi(any(isnan(reshapeddatandbi),2),:)=[];
correlation_NDBI = corr(reshapeddatandbi(:,1),reshapeddatandbi(:,2));
This is the code used to generate Normalized Difference Built-Up Index. In the output figure the lower left portion is water area and the water area is also classified into built up area and built up area is lying in negative values range. I need to figure this out where am i doing wrong?

답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by