For the extraction of certain elements of the movement, we can still extract according to the method of static images, such as RG poor extraction component, provided that the objectives of certain unique characteristics. Consider a motion picture -
The target is in motion, the background is prohibited, target mainly in red, red background containing local stationary. Like this it is difficult to analyze from a single static method.
For the above-mentioned image similarity, the easiest method is to extract the frame difference and background difference. Both algorithms process is simple, but the limitations are obvious: a stationary frame difference is easy to filter out the elements, but the extraction of
Image is incomplete (and sometimes only the contour of an object), but also more dependent on the frame rate, frame rate slow easily lead to ghost phenomenon (to extract two goals), fast frame rate may be mistaken for stationary element is filtered out. Rear
King difference can be extracted relatively complete goal, but updating the background of a challenge (such as the original field of view after the moving body still needs to be included in the background, after the beginning of the original motion still needs to be from a moving body
Excluding the background and updates the background but also to ensure the integrity of the extracted).
For inter-frame difference, usually to the three differential images, ghost phenomenon can be well avoided; the difference may be two background images and background subtraction, the same part of the differential results in the background
Update. This article only explore the basic algorithm.
Frame difference:
The figure is three montage image can be seen on the left displacement of the red car, the car to the right of the red perfectly still, if RG component alone can not extract moving vehicle. Three-frame difference effect Left:
Background subtraction:
Still with the example above, for example (static eliminating red car), select three image.
First, the background of three displacement, the first direct access to the first image, where the use of the gradation difference component RB (zebra avoid interference), the two updates are obtained:
Then the original image is read out three times using grayscale difference component RB:
Finally, as a result of background difference extraction:
It should be noted that the three figures the election was not continuous, continuous, then if there is overlap car, this is more difficult to update the background, there may be a better algorithm to eliminate this BUG!
The following is a matlab simulation test code:
%三帧间差分 function framediff(prevframefile,curframefile,nxtframefile,thres,destination) prevframe=imread(prevframefile); curframe=imread(curframefile); nxtframe=imread(nxtframefile); diffa=uint8(abs(int16(curframe(:,:,1))-int16(prevframe(:,:,1)))); diffb=uint8(abs(int16(curframe(:,:,1))-int16(nxtframe(:,:,1)))); [sizex,sizey]=size(diffa); for i=1:sizex for j=1:sizey if diffa(i,j)<thres ||diffb(i,j)<thres %if diffa(i,j)<thres diffa(i,j)=0; else diffa(i,j)=255; end end end imwrite(diffa,destination,'jpg'); %imshow(diffa); end
%自更新的背景差分 function backgrounddiff(videofile,start_index,end_index,step,thres) video=VideoReader(videofile); frame_amount=video.NumberOfFrame; width=video.Width; height=video.Height; if (end_index>frame_amount) end_index=frame_amount; %防止索引出界 end %background=rgb2gray(read(video,start_index)); background=read(video,start_index); background=background(:,:,1)-background(:,:,2); %R-G %prevdiff=logical(zeros(height,width)); prevdiff=imbinarize(background,thres/255); for i=start_index+step:step:end_index imwrite(background,strcat('video','\back',num2str(i),'.jpg'),'jpg'); %curframe=rgb2gray(read(video,i)); curframe=read(video,i); curframe=curframe(:,:,1)-curframe(:,:,2); diffa=uint8(abs(int16(curframe)-int16(background))); diffa=imbinarize(diffa,thres/255); for j=1:height for k=1:width if diffa(j,k)==1&&prevdiff(j,k)==1 background(j,k)=curframe(j,k);%更新背景 diffa(j,k)=0; end end end prevdiff=diffa; %imshow(diffa); imwrite(curframe,strcat('video','\curframe',num2str(i),'.jpg'),'jpg'); imwrite(diffa,strcat('video','\diffb',num2str(i),'.jpg'),'jpg'); end end