clc
clear
path1='D:\...\GF1_PMS2_E116.7_N40.2_20130501_L1A0000152355-MSS2.tiff';
image=imread(path1);
R=image(:,:,1);
G=image(:,:,2);
B=image(:,:,3);
Nir=image(:,:,4);
[row,column,band]=size(image);
N=zeros(row,column);
for i=1:row         %进行一一遍历
    for j=1:column
        N(i,j)=double((G(i,j)-Nir(i,j)))/double((G(i,j)+Nir(i,j)));
    end
end
%N=double(G-Nir)/double(G+Nir);% 也可以采用这种语法,不过貌似有些问题,还没找到
imwrite(N,'ndwi.tif','compression','none','resolution',[1,1]);

Jetbrains全家桶1年46,售后保障稳定