⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 framedif1.m

📁 多种基于内容的视频检索镜头分割算法matlab程序
💻 M
字号:
%求解视频的帧差分布 (方法一,通用直方图统计法)
%读取视频
clear all;
clc;
tic;%start time
shot=mpgread('..\videos\cut.mpg',[1:200],'truecolor');%读取视频
%shot=aviread('video\skiing.avi');
frames=size(shot,2);
%movie(shot);
%gray
count1=zeros(256,1);
count2=zeros(256,1);
%rgb
countr1=zeros(256,1);
countr2=zeros(256,1);
countg1=zeros(256,1);
countg2=zeros(256,1);
countb1=zeros(256,1);
countb2=zeros(256,1);
%%%%
framedif=zeros(frames,1);
framedifr=zeros(frames,1);
framedifg=zeros(frames,1);
framedifb=zeros(frames,1);
framedifrgb=zeros(frames,1);
%%%%%%%%%%%%%求帧间差%%%%%%%%%%%%%%
divnum=64;%district num
phase=256/divnum;%division
%%
gray1=double(rgb2gray(shot(1,1).cdata));
w=size(shot(1,1).cdata,1);%height
h=size(shot(1,1).cdata,2);%width
%%%%%%%
r=double(shot(1,1).cdata(:,:,1));
g=double(shot(1,1).cdata(:,:,2));
b=double(shot(1,1).cdata(:,:,3));
for j=1:w
      for k=1:h
           count1(gray1(j,k)+1)=count1(gray1(j,k)+1)+1;
           countr1(r(j,k)+1)=countr1(r(j,k)+1)+1;
           countg1(g(j,k)+1)=countg1(g(j,k)+1)+1;
           countb1(b(j,k)+1)=countb1(b(j,k)+1)+1;
      end
end
district1=zeros(divnum,1);
district2=zeros(divnum,1);
%%%%%%%%%
districtr1=zeros(divnum,1);
districtr2=zeros(divnum,1);
districtg1=zeros(divnum,1);
districtg2=zeros(divnum,1);
districtb1=zeros(divnum,1);
districtb2=zeros(divnum,1);
for m=1:divnum
    for n=1:phase
      district1(m,1)=district1(m,1)+count1((m-1)*phase+n,1);
      districtr1(m,1)=districtr1(m,1)+countr1((m-1)*phase+n,1);
      districtg1(m,1)=districtg1(m,1)+countg1((m-1)*phase+n,1);
      districtb1(m,1)=districtb1(m,1)+countb1((m-1)*phase+n,1);
   end
end
for i=2:frames  
   %for c=1:3   
     gray2=double(rgb2gray(shot(1,i).cdata));
     r=double(shot(1,i).cdata(:,:,1));
     g=double(shot(1,i).cdata(:,:,2));
     b=double(shot(1,i).cdata(:,:,3));
     for j=1:w
         for k=1:h
            count2(gray2(j,k)+1)=count2(gray2(j,k)+1)+1;
            countr2(r(j,k)+1)=countr2(r(j,k)+1)+1;
            countg2(g(j,k)+1)=countg2(g(j,k)+1)+1;
            countb2(b(j,k)+1)=countb2(b(j,k)+1)+1;
         end
     end
     for m=1:divnum
        for n=1:phase
          district2(m,1)=district2(m,1)+count2((m-1)*phase+n,1);
          districtr2(m,1)=districtr2(m,1)+countr2((m-1)*phase+n,1);
          districtg2(m,1)=districtg2(m,1)+countg2((m-1)*phase+n,1);
          districtb2(m,1)=districtb2(m,1)+countb2((m-1)*phase+n,1);
        end
     end
     framedif(i,1)=sum(abs(district2-district1))/(2*w*h);
     framedifr(i,1)=sum(abs(districtr2-districtr1))/(2*w*h);
     framedifg(i,1)=sum(abs(districtg2-districtg1))/(2*w*h);
     framedifb(i,1)=sum(abs(districtb2-districtb1))/(2*w*h);
     framedifrgb(i,1)=(framedifr(i,1)+framedifg(i,1)+framedifb(i,1))/3;
     
     if (framedif(i,1)>=0.45)%%output the frames before and after the shot change
         figure(1),
         subplot('position',[0 0 0.5 1]),imshow(shot(1,i-1).cdata),xlabel(strcat('第',int2str(i-1),'帧')),title('突变前图像帧');
         subplot('position',[0.5 0 0.5 1]),imshow(shot(1,  i).cdata),xlabel(strcat('第',int2str(  i),'帧')),title('突变后图像帧');
     end
     district1=district2;
     districtr1=districtr2;
     districtg1=districtg2;
     districtb1=districtb2;
     
     district2=zeros(divnum,1);
     districtr2=zeros(divnum,1);
     districtg2=zeros(divnum,1);
     districtb2=zeros(divnum,1);
     count2=zeros(256,1);
     countr2=zeros(256,1);
     countg2=zeros(256,1);
     countb2=zeros(256,1);
 end 
 %%%%%%%%%绘制图形%%%%%%%%%%%
 figure(2),
 %plot(framedif,'y');
 plot(framedif);
 hold;
 %figure,
 %plot(framedifr,'r');
 %figure,
 %plot(framedifg,'g');
 %figure,
 %plot(framedifb,'b');
 %figure,
 %plot(framedifrgb,'k');
 xlabel('帧数');% x label
 ylabel('直方图帧差');%y label
 title('视频直方图帧差统计');%title setting
 %l=legend('灰度值','R分量','G分量','B分量','彩色量');
 legend('灰度值');
 box on;
 %set(gca,'Color','none');
 %set(l,'color','none');
 %text(90,0.5,'突变边界');
 %line([0,150],[0.46,0.46],'color','k','linestyle','-.');
 toc;%统计时间
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

    
  
 
            
    

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -