查找图像频带之间的方差和协方差值

时间:2018-12-29 21:11:42

标签: image matlab covariance variance

我想编码而不使用现成的命令。我做了些什么,但结果太小了。发生错误时,我没有计算其他频段。如果您能提供帮助,我将不胜感激。

我的V1(方差1)值出现在1,2820183e-05,但是使用了var()函数91.143653869628900。

format long g
img = imread('Landsat8.tif');
blue = round((im2single(img(:, :, 1))+1)*128);
grn = round((im2single(img(:, :, 2))+1)*128);
red = round((im2single(img(:, :, 3))+1)*128);
blue_r = reshape(blue,[2000*2000,1]);
grn_r = reshape(grn,[2000*2000,1]);
red_r = reshape(red,[2000*2000,1]);

%% Mean
mean1 = sum(blue_r)/(2000*2000);
mean2 = sum(grn_r)/(2000*2000);
mean3 = sum(red_r)/(2000*2000);

%% Variance
sum1 = 0;
for i= 1 : length(2000*2000)
   sum1 = sum1 + (blue_r(i) - mean1).^2;
end
V1 = sum1 ./ (length(blue_r));

sum2 = 0;
for i= 1 : length(2000*2000)
    sum2 = sum2 + (grn_r(i) - mean2).^2;
end
V2 = sum2 / (length(grn_r));

%% covariance
sum12 = 0;
for i= 1 : length(2000*2000)
    sum12 = sum12 + (blue_r(i) - mean1) * (grn_r(i) - mean2);
end
c12 = sum12 / (length(blue_r));

0 个答案:

没有答案