基于matlab的MOD13A2-NDVI的植被指数重建-SG滤波与质量控制文件

在应用年内的NDVI信息的时候,由于云的干扰,通常需要对NDVI产品如MOD13A2进行滤波处理进行重建,本文基于matlab平台,结合SG滤波和质量控制文件对MOD13A2产品进行重新构建,基本思路是首先对23期数据进行滤波处理,然后质量好的像元保持不变,而质量较差的像元为滤波后的值,构成新的NDVI序列。基本代码如下

% @author [email protected]
[a,R]=geotiffread('I:\MOD13A2\MOD13A2_yr_03-17_16DAY\NDVI_PR_2017353.hdfout.1_km_16_days_NDVI.tif');
info=geotiffinfo('I:\MOD13A2\MOD13A2_yr_03-17_16DAY\NDVI_PR_2017353.hdfout.1_km_16_days_NDVI.tif');
[m,n]=size(a);
begin_year=2001;
end_year=2018;
qs=23;
%总共23期数据
for year=begin_year:end_year
    ndvisum=zeros(m*n,qs)+NaN;
    qcsum=zeros(m*n,qs)+NaN;
    k1=1;
    for k=1:16:366 
        if k<10
              filename=['I:\MOD13A2\MOD13A2_yr_03-17_16DAY\NDVI_PR_',int2str(year),'00',int2str(k),'.hdfout.1_km_16_days_NDVI.tif'];
              filename_pr=['I:\MOD13A2\MOD13A2_yr_03-17_16DAY\NDVI_PR_',int2str(year),'00',int2str(k),'.hdfout.1_km_16_days_pixel_reliability.tif'];
        else
           if k<100
              filename=['I:\MOD13A2\MOD13A2_yr_03-17_16DAY\NDVI_PR_',int2str(year),'0',int2str(k),'.hdfout.1_km_16_days_NDVI.tif']; 
              filename_pr=['I:\MOD13A2\MOD13A2_yr_03-17_16DAY\NDVI_PR_',int2str(year),'0',int2str(k),'.hdfout.1_km_16_days_pixel_reliability.tif']; 
            else
              filename=['I:\MOD13A2\MOD13A2_yr_03-17_16DAY\NDVI_PR_',int2str(year),int2str(k),'.hdfout.1_km_16_days_NDVI.tif'];  
              filename_pr=['I:\MOD13A2\MOD13A2_yr_03-17_16DAY\NDVI_PR_',int2str(year),int2str(k),'.hdfout.1_km_16_days_pixel_reliability.tif'];  
            end 
        end
        ndvi=double(importdata(filename));%获取ndvi
        ndvi=reshape(ndvi,m*n,1);
        ndvi(ndvi==-3000)=NaN;
        qc=importdata(filename_pr);%获取ndvi的质量文件
        qc=reshape(qc,m*n,1);
        ndvisum(:,k1)=ndvi;
        qcsum(:,k1)=qc; 
        k1=k1+1;
    end
    for i=1:m*n
        data1=ndvisum(i,:);
        if min(data1)>=-2000
            qc=qcsum(i,:);
            data_sg=sgolayfilt(data1,3,5);
            data_sg(qc==0)=data1(qc==0);%进行还原
            ndvisum(i,:)=data_sg;
        end
    end
    for k=1:qs
        ndvi=ndvisum(:,k);
        ndvi=reshape(ndvi,m,n);
        ndvi(ndvi<-2000)=NaN;
        filename=['I:\MOD13A2\MOD13A2_yr_03-17_16DAY\基于质量文件和SG滤波插补\MOD13A2_',int2str(year),'_',int2str(k),'.tif'];
        geotiffwrite(filename,ndvi,R,'GeoKeyDirectoryTag',info.GeoTIFFTags.GeoKeyDirectoryTag)
    end
end

更多需求,请查看个人介绍

你可能感兴趣的:(基于matlab的MOD13A2-NDVI的植被指数重建-SG滤波与质量控制文件)