转载,学习中
*********KEY
FRAME.M***********
I1=imread('Pray_119.jpg');
I2=imread('Pray_122.jpg');
[K,G,N]=size(I1);
J1=rgb2hsv(I1);
K1=rgb2gray(I1);
grayout1=megray(K,G,K1);
out11=block1(K,G,J1);
out12=block2(K,G,J1);
out13=block3(K,G,J1);
out14=block4(K,G,J1);
out15=block5(K,G,J1);
J2=rgb2hsv(I2);
K2=rgb2gray(I2);
grayout2=megray(K,G,K2);
out21=block1(K,G,J2);
out22=block2(K,G,J2);
out23=block3(K,G,J2);
out24=block4(K,G,J2);
out25=block5(K,G,J2);
dis = zeros(1,5);
for i =1:1:72
dis(1) =
dis(1)+abs((out21(i)-out11(i))/(out11(i)+0.000001));
dis(2) =
dis(2)+abs((out22(i)-out12(i))/(out12(i)+0.000001));
dis(3) =
dis(3)+abs((out23(i)-out13(i))/(out13(i)+0.000001));
dis(4) =
dis(4)+abs((out24(i)-out14(i))/(out14(i)+0.000001));
dis(5) =
dis(5)+abs((out25(i)-out15(i))/(out15(i)+0.000001));
end
hsvdis = dis(1)+dis(2)+dis(3)+dis(4)+dis(5)
graydis = 0;
for i =1:1:16
a =
abs(grayout2(i)-grayout1(i))/(grayout1(i)+0.000001);
graydis = graydis+(a.^3)/16;
end
graydis = graydis
%keyframe=(graydis<0.3||hsvdis<40)
function out=block1(K,G,J)
out1=zeros(1,72);
H=J(:,:,1);
for i =1:1:round(K/4)
for j =1:1:round(G/2)
if((0.8750
H1(i,j)=0;end
if((0.0556
H1(i,j)=1;end
if((0.1111
H1(i,j)=2;end
if((0.2083
H1(i,j)=3;end
if((0.4306
H1(i,j)=4;end
if((0.5278
H1(i,j)=5;end
if((0.7500
H1(i,j)=6;end
if((0.8194
H1(i,j)=7;end
end
end
S=J(:,:,2);
for i =1:1:round(K/4)
for j =1:1:round(G/2)
if((0.0000<=H(i,j))||(H(i,j)<0.2000))
H2(i,j)=0;end
if((0.2000<=H(i,j))&&(H(i,j)<0.7000))
H2(i,j)=1;end
if((0.7000<=H(i,j))&&(H(i,j)<=1.0000))
H2(i,j)=2;end
end
end
V=J(:,:,3);
for i =1:1:round(K/4)
for j =1:1:round(G/2)
if((0.0000<=H(i,j))||(H(i,j)<0.2000))
H3(i,j)=0;end
if((0.2000<=H(i,j))&&(H(i,j)<0.7000))
H3(i,j)=1;end
if((0.7000<=H(i,j))&&(H(i,j)<=1.0000))
H3(i,j)=2;end
end
end
for i =1:1:round(K/4)
for j =1:1:round(G/2)
H4(i,j)=9*H1(i,j)+3*H2(i,j)+H3(i,j);
k=H4(i,j)+1;
out1(k)=out1(k)+1;
end
end
out=out1;
function out=block1(K,G,J)
out1=zeros(1,72);
H=J(:,:,1);
for i =1:1:round(K/4)
for j =round(G/2):1:G
if((0.8750
H1(i,j)=0;end
if((0.0556
H1(i,j)=1;end
if((0.1111
H1(i,j)=2;end
if((0.2083
H1(i,j)=3;end
if((0.4306
H1(i,j)=4;end
if((0.5278
H1(i,j)=5;end
if((0.7500
H1(i,j)=6;end
if((0.8194
H1(i,j)=7;end
end
end
S=J(:,:,2);
for i =1:1:round(K/4)
for j =round(G/2):1:G
if((0.0000<=H(i,j))||(H(i,j)<0.2000))
H2(i,j)=0;end
if((0.2000<=H(i,j))&&(H(i,j)<0.7000))
H2(i,j)=1;end
if((0.7000<=H(i,j))&&(H(i,j)<=1.0000))
H2(i,j)=2;end
end
end
V=J(:,:,3);
for i =1:1:round(K/4)
for j =round(G/2):1:G
if((0.0000<=H(i,j))||(H(i,j)<0.2000))
H3(i,j)=0;end
if((0.2000<=H(i,j))&&(H(i,j)<0.7000))
H3(i,j)=1;end
if((0.7000<=H(i,j))&&(H(i,j)<=1.0000))
H3(i,j)=2;end
end
end
for i =1:1:round(K/4)
for j =round(G/2):1:G
H4(i,j)=9*H1(i,j)+3*H2(i,j)+H3(i,j);
k=H4(i,j)+1;
out1(k)=out1(k)+1;
end
end
out=out1;
function out=block3(K,G,J)
out1=zeros(1,72);
H=J(:,:,1);
for i =round(K/4):1:round(K*3/4)
for j =1:1:G
if((0.8750
H1(i,j)=0;end
if((0.0556
H1(i,j)=1;end
if((0.1111
H1(i,j)=2;end
if((0.2083
H1(i,j)=3;end
if((0.4306
H1(i,j)=4;end
if((0.5278
H1(i,j)=5;end
if((0.7500
H1(i,j)=6;end
if((0.8194
H1(i,j)=7;end
end
end
S=J(:,:,2);
for i =round(K/4):1:round(K*3/4)
for j =1:1:G
if((0.0000<=H(i,j))||(H(i,j)<0.2000))
H2(i,j)=0;end
if((0.2000<=H(i,j))&&(H(i,j)<0.7000))
H2(i,j)=1;end
if((0.7000<=H(i,j))&&(H(i,j)<=1.0000))
H2(i,j)=2;end
end
end
V=J(:,:,3);
for i =round(K/4):1:round(K*3/4)
for j =1:1:G
if((0.0000<=H(i,j))||(H(i,j)<0.2000))
H3(i,j)=0;end
if((0.2000<=H(i,j))&&(H(i,j)<0.7000))
H3(i,j)=1;end
if((0.7000<=H(i,j))&&(H(i,j)<=1.0000))
H3(i,j)=2;end
end
end
for i =round(K/4):1:round(K*3/4)
for j =1:1:G
H4(i,j)=9*H1(i,j)+3*H2(i,j)+H3(i,j);
k=H4(i,j)+1;
out1(k)=out1(k)+1;
end
end
out=out1;
function out=block4(K,G,J)
out1=zeros(1,72);
H=J(:,:,1);
for i =round(K*3/4):1:K
for j =1:1:G/2
if((0.8750
H1(i,j)=0;end
if((0.0556
H1(i,j)=1;end
if((0.1111
H1(i,j)=2;end
if((0.2083
H1(i,j)=3;end
if((0.4306
H1(i,j)=4;end
if((0.5278
H1(i,j)=5;end
if((0.7500
H1(i,j)=6;end
if((0.8194
H1(i,j)=7;end
end
end
S=J(:,:,2);
for i =round(K*3/4):1:K
for j =1:1:G/2
if((0.0000<=H(i,j))||(H(i,j)<0.2000))
H2(i,j)=0;end
if((0.2000<=H(i,j))&&(H(i,j)<0.7000))
H2(i,j)=1;end
if((0.7000<=H(i,j))&&(H(i,j)<=1.0000))
H2(i,j)=2;end
end
end
V=J(:,:,3);
for i =round(K*3/4):1:K
for j =1:1:G/2
if((0.0000<=H(i,j))||(H(i,j)<0.2000))
H3(i,j)=0;end
if((0.2000<=H(i,j))&&(H(i,j)<0.7000))
H3(i,j)=1;end
if((0.7000<=H(i,j))&&(H(i,j)<=1.0000))
H3(i,j)=2;end
end
end
for i =round(K*3/4):1:K
for j =1:1:G/2
H4(i,j)=9*H1(i,j)+3*H2(i,j)+H3(i,j);
k=H4(i,j)+1;
out1(k)=out1(k)+1;
end
end
out=out1;
function out=block5(K,G,J)
out1=zeros(1,72);
H=J(:,:,1);
for i =round(K*3/4):1:K
for j =round(G/2):1:G
if((0.8750
H1(i,j)=0;end
if((0.0556
H1(i,j)=1;end
if((0.1111
H1(i,j)=2;end
if((0.2083
H1(i,j)=3;end
if((0.4306
H1(i,j)=4;end
if((0.5278
H1(i,j)=5;end
if((0.7500
H1(i,j)=6;end
if((0.8194
H1(i,j)=7;end
end
end
S=J(:,:,2);
for i =round(K*3/4):1:K
for j =round(G/2):1:G
if((0.0000<=H(i,j))||(H(i,j)<0.2000))
H2(i,j)=0;end
if((0.2000<=H(i,j))&&(H(i,j)<0.7000))
H2(i,j)=1;end
if((0.7000<=H(i,j))&&(H(i,j)<=1.0000))
H2(i,j)=2;end
end
end
V=J(:,:,3);
for i =round(K*3/4):1:K
for j =round(G/2):1:G
if((0.0000<=H(i,j))||(H(i,j)<0.2000))
H3(i,j)=0;end
if((0.2000<=H(i,j))&&(H(i,j)<0.7000))
H3(i,j)=1;end
if((0.7000<=H(i,j))&&(H(i,j)<=1.0000))
H3(i,j)=2;end
end
end
for i =round(K*3/4):1:K
for j =round(G/2):1:G
H4(i,j)=9*H1(i,j)+3*H2(i,j)+H3(i,j);
k=H4(i,j)+1;
out1(k)=out1(k)+1;
end
end
out=out1;
function out=megray(K,G,J)
out1=zeros(1,16);
H=J;
for i =1:1:K
for j =1:1:G
if((0<=H(i,j))&&(H(i,j)<16))
out1(1)=out1(1)+1;end
if((16<=H(i,j))&&(H(i,j)<32))
out1(2)=out1(2)+1;end
if((32<=H(i,j))&&(H(i,j)<48))
out1(3)=out1(3)+1;end
if((48<=H(i,j))&&(H(i,j)<64))
out1(4)=out1(4)+1;end
if((64<=H(i,j))&&(H(i,j)<80))
out1(5)=out1(5)+1;end
if((80<=H(i,j))&&(H(i,j)<96))
out1(6)=out1(6)+1;end
if((96<=H(i,j))&&(H(i,j)<112))
out1(7)=out1(7)+1;end
if((112<=H(i,j))&&(H(i,j)<128))
out1(8)=out1(8)+1;end
if((128<=H(i,j))&&(H(i,j)<144))
out1(9)=out1(9)+1;end
if((144<=H(i,j))&&(H(i,j)<160))
out1(10)=out1(10)+1;end
if((160<=H(i,j))&&(H(i,j)<176))
out1(11)=out1(11)+1;end
if((176<=H(i,j))&&(H(i,j)<192))
out1(12)=out1(12)+1;end
if((192<=H(i,j))&&(H(i,j)<208))
out1(13)=out1(13)+1;end
if((208<=H(i,j))&&(H(i,j)<224))
out1(14)=out1(14)+1;end
if((224<=H(i,j))&&(H(i,j)<240))
out1(15)=out1(15)+1;end
if((240<=H(i,j))&&(H(i,j)<256))
out1(16)=out1(16)+1;end
end
end
out =out1;
%sum=0;
%for i=1:1:16
% sum = sum+out1(i);
%end
%out =sum;