0

I am working on a project in image processing which is based on importance of phase only reconstruction. For more information you can read the answer given by geometrikal in https://dsp.stackexchange.com/questions/16462/how-moving-part-pixel-intensity-values-of-video-frames-becomes-dominant-compared

Project has 2 parts.

  1. Detect moving objects from the video of Traffic on road ( Please download the 1.47 MB video by ( step1) click on the play button then (step2) right clicking on video then ( step3 ) click on save as option )

  2. Perform tracking of any single moving object from the video.

Now,I am quite successful in the 1st part of the project.Algorithm for it is

Algorithm No. 1 The proposed approach

Requirement: An input image sequence I(x, y, n) (where x and y are image dimensions and n represent frame number in a video) which is extracted from video.

Outcome: The segmentation mask of moving object for each frame

  1. For each frame in a input video perform step 2, append step 2 result in resultant array ‘I(x, y, n)’

  2. Smoothen the current frame using 2D Gaussian filter

  3. Perform 3D FFT for the whole sequence I(x, y, n) using (Eq.4.1)

  4. Calculate the phase spectrum using the real and imaginary parts of 3D DFT

  5. Calculate the reconstructed sequence Î(x, y, n) using (Eq.4.2)

  6. For each frame in a input video perform step 7 to step 10 to get segmentation mask for each frame and append step 10 result in resultant segmentation mask array BW(x,y,n)’

  7. Smooth the reconstructed frame of Î(x, y, n) using the averaging filter.

  8. Compute the mean value of the current frame

  9. Convert the current frame into binary image using mean value as the threshold

  10. Perform morphological processing, i.e., filling and closing, to obtain segmented mask of moving object for the current frame

  11. End algorithm.

With the above algorithm I could find all moving object from the video. Now, I want to move to 2nd part i.e.Perform tracking of any single moving object from the video .

enter image description here

As you can see in the figure,I have achieved the results as shown in the 1st column .I have reached till the 1st column results only. But my goal is to track a single vehicle like as shown in the 2nd column of the figure. (I have made results shown in 2nd column using Photoshop)

So can anybody help me ?

 tic
clc;
clear all;
close all;
  
%read video file
video = VideoReader('D:\dvd\Matlab code\test videos\5.mp4');

T= video.NumberOfFrames  ;           %number of frames%

frameHeight = video.Height;          %frame height

frameWidth = video.Width ;           %frameWidth

get(video);                          %return graphics properties of video


i=1;

for t=300:15:550  %select frames between 300 to 550 with interval of 15 from the video  
    frame_x(:,:,:,i)= read(video, t); 
    frame_y=frame_x(:,:,:,i);

    %figure,
    %imshow(f1),title(['test frames :' num2str(i)]);
    frame_z=rgb2gray(frame_y);                 %convert each colour frame into gray
    
    frame_m(:,:,:,i)=frame_y; %Store colour frames in the frame_m array 
     
    %Perform Gaussian Filtering
    h1=(1/8)*(1/8)*[1 3 3 1]'*[1 3 3 1]  ;   % 4*4 Gaussian Kernel  
    convn=conv2(frame_z,h1,'same');
        
    g1=uint8(convn);
    
                    
    Filtered_Image_Array(:,:,i)=g1; %Store filtered images into an array
    i=i+1;
end

%Apply 3-D Fourier Transform on video sequences
f_transform=fftn(Filtered_Image_Array);

%Compute phase spectrum array from f_transform
phase_spectrum_array =exp(1j*angle(f_transform));

%Apply 3-D Inverse Fourier Transform on phase spectrum array and
%reconstruct the frames
reconstructed_frame_array=(ifftn(phase_spectrum_array));


k=i;

i=1;
for t=1:k-1
    
    %Smooth the reconstructed frame of Î(x, y, n) using the averaging filter.
    Reconstructed_frame_magnitude=abs(reconstructed_frame_array(:,:,t));  
    H = fspecial('disk',4);
    circular_avg(:,:,t) = imfilter(Reconstructed_frame_magnitude,H);
        
    
    %Convert the current frame into binary image using mean value as the threshold
    mean_value=mean2(circular_avg(:,:,t));  
    binary_frame = im2bw(circular_avg(:,:,t),1.6*mean_value);
    
    
    %Perform Morphological operations
    se = strel('square',3);
    morphological_closing = imclose(binary_frame,se); 
    morphological_closing=imclearborder(morphological_closing); %clear noise present at the borders of the frames
    
    
    %Superimpose segmented masks on it's respective frames to obtain moving
    %objects
    moving_object_frame = frame_m(:,:,:,i);
    moving_object_frame(morphological_closing) = 255;  
    figure,
    imshow(moving_object_frame,[]), title(['Moving objects in Frame :' num2str(i)]);
    
 i=i+1;
end
toc
Community
  • 1
  • 1
sagar
  • 201
  • 1
  • 8

1 Answers1

0

Once you've identified your object to track implement a Kalman filter and you'll get the desired tracking you're looking for.

There are quite a bit of resources out there, but if you want to do it by hand I suggest you use StudentDave's explanation on YouTube its pretty good. https://www.youtube.com/watch?v=FkCT_LV9Syk

ABC
  • 665
  • 1
  • 6
  • 15
  • Thank you sir for your feedback but as you observed that I have detected **all** the moving objects in each video frames. But now I want to detect **only one** moving object at a time from current frame and **avoid other moving objects**.So what changes should I make in my MATLAB code.? – sagar May 29 '15 at 04:59
  • Ah, this is trickier. Does it matter which car you are tracking? If it doesn't, from what i remember `strel` in matlab returns a set of objects as well as their areas in pixels - you could potentially initially choose the largest one and just track that one with your Kalman filter. Otherwise, you'd need to identify a characteristic of the particular car you want to track and implement that into your algorithm. – ABC May 29 '15 at 15:53
  • sir,I have edited my code and tried it to simplify as much as possible with meaningful names. Now, if possible could you add kalman filter operation in my code and show me tracking of **any** vehicle. So,Could you add the modified code in the your answer box? – sagar May 29 '15 at 16:22
  • From what I can tell matlab does not have a built in Kalman Filter function. StudentDave in the youtube link I provided does have [Matlab code](http://studentdavestutorials.weebly.com/kalman-filter-with-matlab-code.html) you could add to your project. Once you have the object's position - the centers of the objects listed in your variable `se`, you feed these points into your filter. The idea is that given a position your filter tries to predict the next position for your object, and then performs correction on the next frame. If doesn't have position it guesses where the object should be. – ABC May 29 '15 at 18:15
  • You would insert this code to call the Kalman filter after this line `morphological_closing = imclose(binary_frame,se);`. Btw, in case you didnt know, this line `morphological_closing=imclearborder(morphological_closing);` is actually more aesthetic and isn't really necessary to tracking. All the object information is going to be in `se`. – ABC May 29 '15 at 18:17