在视频分析中,需要用到离群点挖掘,下面给出一个简单的离群点挖掘, matlab代码如下:
clear
clc
orgX = [1 1 0 3 4 5 2 70 100 100 100 6 60 3 2 2 1 1 0]
k = 3;
th = 1;
outlier = [];
x = newArray(orgX, k)
len = length(x);
average = mean(x);
standard = std(x);
for i = 1 : len
if x(i) > 0 && x(i) - average > th * standard % 此处没有用abs函数,所以,有些负数可能没有离群
outlier = [outlier orgX(i)];
end
end
outlier
function y = newArray(x, k);
n = length(x);
for i = 1 : k
y(i) = 0;
y(n - i + 1) = 0;
end
for i = k + 1 : n - k
y(i) = x(i) - ( min(x(i - k : i - 1)) + min(x(i + 1 : i + k)))/2;
end
结果为:
orgX =
Columns 1 through 18
1 1 0 3 4 5 2 70 100 100 100 6 60 3 2 2 1 1
Column 19
0
x =
Columns 1 through 10
0 0 0 2.0000 3.0000 4.0000 -34.5000 19.0000 96.0000 96.0000
Columns 11 through 19
63.5000 -45.0000 56.0000 -0.5000 0 1.0000 0 0 0
outlier =
100 100 100 60