Linear regression with MATLAB by VFC of picture elements (two) picture elements by linear regression

By-pixel linear regression

tic
[a,R]=geotiffread('1.tif');%先导入某个图像的投影信息,为后续图像输出做准确
info=geotiffinfo('1.tif');
[m,n]=size(a);
years=10; %表示有多少年份需要做回归
data=zeros(m*n,years);
k=1;
for year=1:10 %起始年份
    file=[int2str(year),'.tif'];%注意自己的名字形式,这里使用的名字是年prec2000.tif,根据这个可修改
    bz=importdata(file);
    bz=reshape(bz,m*n,1);
    data(:,k)=bz;
    k=k+1;
end
    xielv=zeros(m,n);
    p=zeros(m,n);
    %b = zeros(m,n);
    F = zeros(m,n);
    %R_2 = zeros(m,n);
for i=1:length(data)
    bz=data(i,:);
    if isnan(bz)    %注意这是进行判断有效值范围,如果有效范围是-1到1,则改成max(bz)>-1即可
        bz = bz';                   %背景不进行回归
        p(i) = NaN;
        xielv(i) = NaN;
        F(i) = NaN;
    elseif numel(unique(bz)) ==2;   %水体像元不进行回归
         bz = bz';
        p(i) = -3;
        xielv(i) = -3;
        F(i) = -3;
    elseif unique(bz) == 0;         %如果是VFC一直为0
        bz = bz';
        p(i) = -4;
        xielv(i) = -4;
        F(i) =-4;
    else
        bz=bz';
        X=[ones(size(bz)) bz];
        X(:,2)=[1:years]';
        [b,bint,r,rint,stats] = regress(bz,X);
        pz=stats(3);
        p(i)=pz;
        xielv(i)=b(2);
        %R_2 = stats(1);
        %B(i) = b(1);     
        F(i) = stats(2);
    end
end
name = 'k_.tif'
name2='P值.tif';
name4 = 'F的值.tif';
geotiffwrite(name,xielv,R,'GeoKeyDirectoryTag',info.GeoTIFFTags.GeoKeyDirectoryTag);
geotiffwrite(name2,p,R,'GeoKeyDirectoryTag',info.GeoTIFFTags.GeoKeyDirectoryTag);
geotiffwrite(name4,F,R,'GeoKeyDirectoryTag',info.GeoTIFFTags.GeoKeyDirectoryTag);
%一般来说,只有通过显著性检验的趋势值才是可靠的
F;
toc  

Here Insert Picture Description
VFC fact is another index of vegetation coverage, using pixel calculated two-division model. NDVI is an index of progress.
In fact, that is a by-pixel basis yuan be like after each operation picture elements, but due to the large amount of data, can lead to very long time, depending on the configuration of the computer and the data amount determined by the size, I would like have to run more than 10 minutes. Need to be patient. Second, because each person has when dealing with remote sensing images of different habits, such as water I will assign to -3, but the nature of these operations is the assignment matrix, as to how to write the program still need to own a lot of pondering.
It is recommended that the VFC change '1-10.tif' management is not only convenient, but also for subsequent read more convenient. Because when dealing with VFC I've done some deal with.
This article mainly draws and own a series of changes.
Probably better time to update. . After carefully preparing to graduate school.
Matlab raster data based on a linear regression and significance test (Trend Slope)

Published 14 original articles · won praise 2 · Views 818

Guess you like

Origin blog.csdn.net/weixin_43342986/article/details/104581185