matlab calculated grayscale images first moment, second moment, the third moment

The first moment is defined average intensity of each color component

Second moment, color variance test reflection region, i.e. inhomogeneity

Third moment defined skewness color components, i.e., the color asymmetry

 

close all;clear all;clc;
J = imread('lena.jpg');
K = imadjust(J,[70/255 160/255],[]);
figure;
subplot(121),imshow(J);
subplot(122),imshow(K);
[m,n] = size(J);
mm = round(m/2);
mn = round(n/2);
[p,q] = size(K);
pp = round(p/2);
qq = round(q/2);
J = double(J);
K = double(K);
colorsum = 0.0;
Javg = mean2(J)  %求原图像一阶矩
Kavg = mean2(K)  %求增强对比度后的图像一阶矩
Jstd = std(std(J))  %求原图像的二阶矩,因为一次std函数表示按列求标准差,两次std表示求整个矩阵的标准差
Kstd = std(std(K))   %求增强对比度后的图像二阶矩
for i=1:mm
    for j=1:mn
        colorsum = colorsum+(J(i,j)-Javg)^3;
    end
end
Jske = (colorsum/(mm*mn))^(1/3)  %求原图像的三阶矩
colorsum = 0.0;
for i=1:pp
    for j=1:qq
        colorsum = colorsum + (J(i,j)-Kavg)^3;
    end
end
Kske = (colorsum/(pp*qq))^(1/3)  %求增强对比度后的图像三阶矩
        

Section Function Description:

mean2 (A): averaging matrix A

std (x, flag, dim): find the standard deviation of x

std (x, 0,1): 0 In addition to n-1,1 by column represents time division request indicates standard deviation  

std (x, 1,2): 1 indicates inter n, 2 denotes dividing line when evaluated by standard deviation

Guess you like

Origin www.cnblogs.com/wojianxin/p/11423126.html