Diese Präsentation wurde erfolgreich gemeldet.
Wir verwenden Ihre LinkedIn Profilangaben und Informationen zu Ihren Aktivitäten, um Anzeigen zu personalisieren und Ihnen relevantere Inhalte anzuzeigen. Sie können Ihre Anzeigeneinstellungen jederzeit ändern.

Block Matching Project

Block matching for motion Estimation

  • Loggen Sie sich ein, um Kommentare anzuzeigen.

Block Matching Project

  1. 1. 1 ECE 565 Computer Vision and Image Processing Spring 2010 Computer Assignment # 2 Block Matching Based Motion Prediction Method By Dhawal Subodh Wazalwar A20249257 ECE Dept Illinois Institute of Technology Due date 30th April 2010 1
  2. 2. Block Matching Based Motion Estimation 1. Introduction The main aim of the Block Matching(BM) Motion Estimation is to compare images taken at two different time frames and estimate the direction of motion taken place between the two frames. Here, the challenge is to get the best motion vector by using a pixel domain search method and proper manipulation of BM parameters. Fig 1.1 tries to demonstrate the basic concept of block matching motion estimation. Here, two blocks Reference and Target Block are shown and the Target block is the translated version of Reference block. The key aspect in this method is how accurately can we estimate motion direction with appropriate Motion Vectors Column i,j i+v1,j+v2 Row Reference Block at i,j Target Block at i+v1,j+v2 Direction of Motion Vector v1,v2 Motion Vector Magnitude Fig 1.1 Basic Understanding of Block Matching Any BM Motion Estimation method needs following parameters to be selected beforehand : • The Matching Criteria Various metrics like Sum of Absolute Differences(SAD),Mean Square Error(MSE). Mean Absolute Difference(MAD) can be used for quantitatively proving that the two blocks in comparison are matching. Here, in this implementation SAD is used which is represented as where, It+1(i,j) -----> Target Frame It (i,j) -----> Reference Frame k,l -----> The block location N -----> Block size [v1;v2] ----> Motion Vector for that block • Search Strategy The search strategy influences the quality of Motion Field and also the overall computation time as demonstrated in later parts. There are various search strategies like Full Exhaustive Search, 3-point Search, Cross Search Method and many more versions of it. In this implementation, we have used full exhaustive search method. 2
  3. 3. • Search Window and Block Size The Block size(N) is the size of the block of target and reference frame to be compared for estimating the motion vectors. On the other hand, Search Window(M) is the resolution for which the search over the block is done. 2. Algorithm 2.1 Implementation Steps Flow chart in Fig 2.1 shows the important steps in the Full Exhaustive Search Block Matching Motion Estimation Method. Reference Image Target Image Initialize N,M,th Select the appropriate Target block It+1(i,j) of NXN Yes No Reference Calculate Checked Calculate for all Block SAD(0) Motion SAD vectors It(i+v1,j+v2) Is No Is SAD(v)>SAD(0) SAD -th*N*N min No Yes Yes Motion Store Vectors =0 Motion Vectors Display Assign block Determine Motion In the DFD,FD Field Predicted Image Fig 2.1 Flow Chart showing the Implementation steps for Full Exhaustive BM Method 3
  4. 4. 2.2 Key Aspects and Findings in the Algorithm Implementation • If the block size is not multiples of the Frame size,we get the problem of addressing pixels outside the frame. In such cases, here, we restrict the block size to the the last boundary( i.e row and col value) when 'v' addresses outside the frame boundary. On the other hand, when it addresses pixels before the boundary, it is restricted to the start position i.e '1'. • Also, in some cases the motion vector v=[v1;v2] can also cause the same addressing problem. In this situation, we put a condition and check for such cases. If this situation is detected, we ignore that motion vector and carry on for the next motion vector. The reason for doing this is, we can estimate motion happening inside the frame, not outside the frame. So, there is no harm in ignoring the motion vectors addressing outside the frame. • Displaced Frame Difference(DFD) and Frame Difference(FD) is obtained by DFD= ∑(abs(Estimated Frame – Target Frame)), FD = ∑(abs(Reference Frame – Target Frame)) • We get negative values for DFD and FD. So, for proper display we need to map those negative values in the positive domain. So, we find the minimum value for DFD and FD frame and simply add the absolute of that value respectively to get the proper DFD and FD frame. Another way of doing this is converting both the frames in 'uint8' form but in this case all the negative values become '0' and we lose the exact pattern in DFD and FD frames. So, the former method of adding the absolute of minimum value serves the purpose and helps getting better display results. • The threshold condition used for detecting the most appropriate motion vector is SAD(v')<SAD(0) – th*N*N where N is block size, th is the threshold value given initially • The Total SAD is calculated by adding the minimum SAD values for each block. • A check for getting the number of iterations performed and also the time required for the entire analysis is also added. 3. Experimental Results The algorithm determines the motion vectors, predicted image and displays motion vector field, Displaced Frame Difference(DFD),Frame Difference(FD) along with the predicted Image. 3.1 Analysis on Example Image 1: Case 1: Block size NXN=16X16, Search Window M=16,Threhold=0 The results are shown below in Figure 3.1 to 3.4 Fig 3.1 Reference Image 4
  5. 5. Fig 3.2 Target and Predicted Image for Example 1 with N=16,M=16,th=0 Fig 3.3 FD and DFD for the Image 1 with N=16,M=16,th=0 Now, finally the most important of all Motion Vector Field is shown below in Fig 3.4 Fig 3.4 Motion Vector Field showing the estimated motion direction for N=16,M=16,th=0 Here, in this motion vector field diagram, we can see that it clearly shows the motion for the displacement of face and shoulder part, while the random fields near the boundary are for the background part which has Camera 5
  6. 6. effect and is not a part of actual motion displacement. Note: The Direction shown is for the motion from Predicted ie Target Image to the Reference Image since the algorithm tries to find the target block in the reference block translated by the appropriate motion vector. Also, if we see the reference and the target image, we can see that actual information is approximately in the following region: Face: Row 15:100, Column 50:150 Shoulders: Row 95:144, Column 1:176 So ideally, we should have motion vectors at the following coordinate range shown in the Figure 3.5 Fig 3.5 Range of Ideal Motion Vector Field So by changing the threshold value, we can neglect the unwanted motion vectors which came because of the background random motion, which we need not consider. Case 2: Block size NXN=16X16, Search Window M=16,Threshold=0.5 The results for Case 2 are shown in Fig 3.6 and 3.7 Fig 3.6 Predicted and DFD for N=16,M=16,th=0.5 6
  7. 7. Motion Vector Field Columns 1 2 3 4 5 6 7 8 9 10 11 0 1 2 3 4 Rows 5 6 7 8 9 Fig 3.7 Motion Vector Field for Image 1 with N=16,M=16,th=0.5 We can see in Fig 3.7, we get better Motion Field Representation than obtained in Fig 3.4 for Case 1. Also, after comparing the Reference and Target Image in Fig 3.1 and 3.2 , it was found that the max displacement in any direction is not more than 5-6 pixels approximately. This was determined by using 'pixval' command in Matlab and finding the displacement at key positions in Image like Person's Face, Eyes and other such features visible. Therefore, in optimal Motion field matrix, we can expect max absolute value to be not more than 5-6 in this case. So here in Case 2 with th=0.5, although we see almost expected Motion Vector, after checking matrix values, we find that max absolute value here is 8. So, th=0.5 is not the optimal threshold. Note: Here, one important observation can be made regarding 'Search Range' M. As mentioned above, max displacement was approximately found to be 5-6. So, if we give search range less than this value(say M=4), it would be interesting to see the Motion Field, shown in Fig 3.8 Fig 3.8 Motion Vector Field for N=16,M=4,th=0.5 7
  8. 8. If we compare direction of motion vectors in Fig 3.7 and Fig 3.8, we can see the difference, in that for th=4, we don't get the expected direction. Also in this case, Total SAD=86609 as compared to 67616 for N=16,M=16,th=0.5. Therefore, we should always keep Search Range M greater than the absolute of maximum displacement between Reference and Target Image to get the accurate motion estimation direction. So, after continuing the changes in the threshold value, it was found that we get better possible motion vector field when threshold value is in the range of 1.5 to 2, and it was found that the best results were seen at th=1.7, after which there was not much change in the motion field. Case 3: N=16,M=16,th=1.7 Predicted ,DFD images and the corresponding Motion Vector Field are shown in Fig 3.9 and Fig 3.10 Fig 3.9 Predicted and DFD Image for N=16, M=16, th=1.7 Motion Vector Field Columns 1 2 3 4 5 6 7 8 9 10 11 1 2 3 4 Rows 5 6 7 8 9 Fig 3.10 Example 1 Motion Vector Field for N=16,M=16,th=1.7 (Close to desired results) Here, after the absolute value of maximum displacement shown by Motion vectors is 6. So, visually as well as theoretically its is proved that Optimum threshold for Example 1 Image is '1.7' Now, we will change the block size N=8, keeping same M=16 and Threshold th=1.7, and Fig 3.11 and Fig 3.12 show the obtained results. 8
  9. 9. Case 4: Image 1 with N=8,M=16,th=1.7 Here if we compare DFD in Fig 3.11 and Fig 3.9 for N=16, we can see that for N=8, we seem to be getting results because almost see very sketchy outline of shoulder area compared to that in Fig 3.9 for N=16. This is also demonstrated by that Total SAD value has reduced from 70343 to 60450, which is testimony of the fact we have obtained better Prediction Image. This is true because smaller the block of Target Image used for comparison, more is the possibility of detecting it in the Reference Image, meaning when we reduce the block size, we start getting minor details which were missed for N=16. Fig 3.11 Example 1 Predicted and DFD Image with N=8,M=16,th=1.7 Fig 3.12 Motion Field for N=8,M=16, th=1.7 On the other hand, if we compare Motion vector fields in Fig 3.12 for N=8 and Fig 3.10 at N=16, we actually the reverse effect. In that, yes we are able to get finer details but missing out on few border motion vectors for same threshold value(here th=1.7).That means, the same threshold value is not optimal in all case but only for that particular block size. The quality of Motion Vector depends on the condition expressed below SAD(V')<SAD(0) - th*N*N Now here, if all factors reduce by same amount then the same threshold value will give optimal results. However, it was found that Total SAD value reduces by different amount(here from 70343 to 60450) compared to the 'th*N*N' which becomes 1/4th. The total SAD(0) value remains same. This shows that all factors have different reduction factors and so results depends on the particular block situation. Therefore, we see mismatch in the 9
  10. 10. Motion Vector Field results for N=8 and N=16 for same Threshold value. So, every time we change the block size, we should freshly determine the optimal threshold value for that block size. Now, here one more thing to be taken into consideration is the computational time. For example for N=16,M=16 the number of iterations/computations were found to be 107812, while for N=8, M=16, there number was 431245. in terms of time the later analysis took almost 25 seconds more. This can be explained by reducing the block size, we have to get motion vectors for more number of blocks and so the increase in computation time. Also, if we decrease the search window ( say M=8), the computation time would be less. Fig 3.13 and fig 3.14 shows results for N=8,M=8,th=1.7. Fig 3.13 Predicted and DFD for N=8,M=8 and th=1.7 Fig 3.14 Motion Field Vector for N=8,M=8,th=1.7 If we compare the DFD for N=8,M=8 in Fig 3.14 and N=8,M=16 in Fig 3.12, we don't see much changes due to the fact that actual displacement between Reference and Target frame is not more than 6 pixels approximately. So for fixed N, if we change M above 6-7, we should not find much difference. This is also demonstrated by the fact that Total SAD value doesn't change much as in the Tabular Summary for all cases applied on Image1 shown in Tab 3.1 10
  11. 11. Block Size(N) Search Threshold(th) Number of Time in secs Total SAD Total SAD(0) Range(M) Iterations 16 16 0 107812 10.13 65986 231549 16 16 0.5 107812 9.43 67616 231549 16 16 1.7 107812 16 70343 231549 8 16 1.7 431245 30.98 60450 231549 8 8 1.7 114445 4.92 60491 231549 Tab 3.1 Overall Summary of all cases analyzed 3.2 Analysis on Example Image 2 Similar Analysis was done for the Example Image 2 and the results for all the cases are shown in Fig 3.15 to Fig 3.24 Case 1: N=16,M=16,th=0 Fig 3.15 Reference Example Image 2 Fig 3.16 Target and Predicted Image for Example 2 with N=16,M=16,th=0 11
  12. 12. Fig 3.17 DFD and FD Image for Example 2 with N=16,M=16,th=0 Motion Vector Field Columns 0 5 10 15 20 25 0 2 4 6 Rows 8 10 12 14 16 Fig 3.18 Motion vector Field for Image 2 with N=16,M=16 and th=0 If we compare Reference and Target Image, we can see there are some regions which because of motion get occluded, for example the surrounding region behind the Vehicle. So, we can't estimate motion for such areas, even though we see some motion vectors in that region. This problem is called “Occlusion” Problem and is one of the limitations of Basic Block Matching method. Another limitation is “Aperture Problem”, in which we have blocks of same intensity values multiple times in the regions successively and so we don't get any motion estimation for such cases, since in actual mathematically there is no motion. However, if the region is sub block of bigger block, we need to have motion vectors since there is a motion. Although not exactly, but we see a similar case at Vehicles Door region at approximately Block(10,5) in Motion Vector field. In Fig 3.18 we still see some motion vector of small magnitude because actually we don't have same intesnity throughout that region, but it has similar texture, which can be proved by the fact that the region at Block(10,5) is not much visible even in Frame Difference(FD). Now, for N=16,M=16 and th=0, we are almost getting the desired Motion vector field indicating motion at all places, which is actually true if we compare the Reference and Target Image. This is unlike Example image 1 where we were concerned in estimating motion in particular region. 12
  13. 13. Now, if here th=0 will be the best possible Threshold Value. Now, if we change the threshold we expect little degraded results, since some required motion vectors will not satisfy the threshold condition. Case 2: Image 2 with N=16,M=16, th=1 Fig 3.19 to Fig 3.20 shows the results for Case 2 Fig 3.19 Predicted and DFD Image for N=16,M=16,th=1 Fig 3.20 Motion Vector Field for N=16,M=16,th=1 Here, if we compare the DFD for th=1 in Fig 3.19 and for th=0 in Fig 3.17, we can't see much of the difference visually. However, if we compare Total SAD value for both cases, we find that it has increased from 692509 to 694021. Also, if we compare Motion Vector Field in Fig 3.20 and Fig 3.18, as expected we see some required motion vectors missing. This proves the point made earlier that th=0 is the most optimal threshold value. Case 3: N=8,M=16,th=0 Fig 3.21 and Fig 3.22 shows the Predicted, DFD and Motion Vector Field for N=8,M=16,th=0 13
  14. 14. Fig 3.21 Predicted and DFD Image for N=8,M=16,th=0 If we compare DFD image for N=8 in Fig 3.21 and for N=16 in Fig 3.17 with th=0, we can clearly see for N=8, the bright spot on the vehicle is missing, and thus giving more accurate predicted Image. This is because for smaller block size 8X8, the bright spot couldn't be a part of matching block in the Target Frame, so we don't see it in the predicted image. Thus, with smaller block size, we start getting finer details in the Target Image. If we compare Motion Vector field in Fig 3.22 and Fig 3.16, we can see that for same threshold value i.e th=0, we get the optimal results. So, in this case, the quality of Motion Field is actually improved for N=8,M=16 and th=0. This is unlike the Example 1 Image where the situation was reverse and we had to track motion at some part of whole Image. Finally, for N=8,M=8,th=0, results are shown in Fig 3.23 and Fig 3.24 and then all the cases analyzed are tabulated in Table 3.2. Fig 3.22 Motion vector Field for N=8,M=16,th=0 Fig 3.23 Predicted and DFD Image with N=8,M=8,th=0; 14
  15. 15. Motion Vector Field Columns 0 5 10 15 20 25 30 35 40 45 0 5 10 Rows 15 20 25 30 Fig 3.24 Motion Vector Field for N=8,M=8,th=0 Block Size(N) Search Threshold(th) Number of Time in secs Total SAD Total SAD(0) Range(M) Iterations 16 16 0 375706 35.98 692509 1714664 16 16 0.5 375706 35.57 692812 1714664 16 16 1 375706 36.39 694021 1714664 8 16 0 1470151 114.9 619854 1714664 8 8 0 390151 17.11 623930 1714664 Tab 3.2 Summary for All case analyzed For Example Image 2 3.3 Changing the Search Method From the analysis shown in Tab 3.1 and Tab 3.2, we can see that Full exhaustive search method gives very good motion estimation prediction. The main reason for getting such good results is because we try searching over entire Search Window Resolution. On the flip side, this method takes a lot of computational effort. So, there are various methods as mentioned in the introduction part for getting faster and almost close to Full Exhaustive Method Results. As regarding the quality of Motion Vector Field, we may miss some Object motion vector fields, since we scan at few specific points rather than at each and every location in Search Range M as done in Full Exhaustive Search Method. Thus, the quality of Motion vector field depends on the search method's accuracy. For example, here in the same implementation if we put the Threshold Condition ( SAD(v') < SAD(0) -th*N*N) inside the loop of Motion Vector Search Range and if the condition is not satisfied, we break out of the loop and assume that there is no motion and assign '0' value to the motion vector, we get following Motion Vector Field for N=16,M=16,th=0 shown in Fig 3.25. We can easily see that many required motion vectors are missing but still we get a rough estimate of the motion estimation. The number of iterations/computations performed reduces to 46547 as compared to 107812 in Full Search Method. If we use methods like 3 point, Cross Search Methods, we can get better accuracy in Motion Vector Field results. 15
  16. 16. Fig 3.25 Motion Vector Field for Modified Search Method with N=16,M=16,th=0 4. Conclusion Based on summary obtained in Table 3.1 for Example Image 1 and Table 3.2 for Example Image 2, following conclusions can be drawn: • Effect of Changing BM parameters on Motion Estimation Accuracy ◦ Block Size(N): Smaller the Block size, we get finer details of the target Image in the predicted image i.e lower Total SAD value. However, the computational effort increases. ◦ Search Window(M): Theoretically, greater the value of M, better the quality of predicted image, lower total SAD value and more accurate Motion Vector Field Representation. Practically, we need to ensure that the value of M is greater than the absolute maximum displacement between Reference and Target image in any direction. Also, higher the value, more is the computational effort. ◦ Threshold(th): The optimal value of 'th' depends on the images. If we need to estimate for entire Image, optimal value will be independent of N and is equal to zero. However, if we have to consider only a particular region in image for motion estimation, every time we change N and M, we need to get optimal threshold value. In general , increasing 'th' results in increased total SAD value. • Full Exhaustive Search Method gives a very accurate Motion vector Field Representation, however the computational effort required is more. Using other search methods like 3 point search method, can help getting faster results. • Block Matching based motion estimation method cannot estimate motion for the part when it is occluded in between the frames or if it has Aperture problem. 5. References [1] 'Digital Video Processing', A. Murat Tekalp, Chapter 6 Block Based Methods [2] 'ECE 565 Computer Vision and Image Processing' class notes, Professor Jovan Brankov 16
  17. 17. 6. Appendix 6.1 MATLAB Code for Block Matching based Motion Estimation function [f_e dfd fd tot_sad tot_sado comp]=blockmatching(f_r,f_t,N,M,th) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % %%%%%%%%%%Full Exhaustive Block Matching Motion Estimation Method%%% % Inputs % f_r ---> Reference Image % f_t ---> Target Image % N ---> Block Size % M ---> Search Window % th ---> Threshold Value % Outputs % f_e ---> Estimated Image % dfd ---> Displaced Frame Difference % fd ---> Frame Difference % tot_sad ---> Total SAD value % tot_sado ---> Total SAD value at v=0 % comp --> Number of Iterations/Computations Performed %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%% %Converting the images from uint8 to Double Format f_r=double(f_r); f_t=double(f_t); %Determining the Image Size [row col]=size(f_t); %Initializing a Estimated Image f_e=zeros(row,col); f_e=double(f_e); a=1; b=1; %Initiating the Total SAD variable tot_sad=0; tot_sado=0; it=1; %Number of Computations comp=1; tic for i=1:N:row for j=1:N:col %Initializing Motion Vectors and SAD matrices v1_min=0; v2_min=0; sad=[]; v1_mat=[]; v2_mat=[]; it=1; 17
  18. 18. %Searching for the optimal motion vector over the entire search range M for v1=-M:M for v2=-M:M %Incrementing the number of Computations comp=comp+1; %Determining the Row start points for Target and Reference Blocks to be compared for Motion Estimation start_t_i=i; start_r_i=v1+i; %Determining the Row end points for Target and Reference Blocks if(start_t_i+N>row) end_t_i=row; end_r_i=v1+row; else end_t_i=start_t_i+N-1; end_r_i=start_r_i+N-1; end; %Determining the Column Start Points for Target and Reference Blocks start_t_j=j; start_r_j=j+v2; %Determining the Column end points for Target and Reference Blocks if(start_t_j+N>col) end_t_j=col; end_r_j=v2+col; else end_t_j=start_t_j+N-1; end_r_j=start_r_j+N-1; end; if(end_r_i<row && end_r_j<col && start_r_i>0 && start_r_j>0) %Calculating the SAD value for the current motion vector dif=f_t(start_t_i:end_t_i,start_t_j:end_t_j)-f_r(start_r_i:end_r_i,start_r_j:end_r_j); dif=abs(dif); sadx=sum(sum(dif)); if(it==1) sad=sadx; v1_mat=v1; v2_mat=v2; it=it+1; else sad=[sad ;sadx]; v1_mat=[v1_mat; v1]; v2_mat=[v2_mat; v2]; it=it+1; 18
  19. 19. end; end; end; end; % Finding the Motion vectors for Minimum SAD value if(isempty(sad)==0) pos=find(sad==min(sad)); v1_min=v1_mat(pos(1),1); v2_min=v2_mat(pos(1),1); end; %Calculating SAD(0) sado=abs(f_t(start_t_i:end_t_i,start_t_j:end_t_j)-f_r(start_t_i:end_t_i,start_t_j:end_t_j)); sado=sum(sum(sado)); tot_sado=tot_sado+sado; %Checking for the Threshold Condition if(min(sad)>=sado-th*N*N) v1_min=0; v2_min=0; tot_sad=tot_sad+sado; else tot_sad=tot_sad+min(sad); end; %Storing the determined motion vectors in an array V1(a,b)=v1_min; V2(a,b)=v2_min; b=b+1; %Calculating the start and end points in the Predicted and to be %assigned Reference Block start_r_j=j+v2_min; start_r_i=v1_min+i; if(start_r_j+N-1>col && start_t_j+N-1<=col) end_r_j=2*start_r_j+N-col -1; end_t_j=col; end; if(start_t_j+N-1>col&&start_r_j+N-1<=col) end_r_j=start_r_j+start_t_j+N-col -2; end_t_j=col; end; if(start_t_j+N-1>col && start_r_j+N-1>col ) end_t_j=col; end_r_j=start_r_j+end_t_j-start_t_j; end; if(start_t_j+N-1<=col ) end_r_j=start_r_j+N-1; end_t_j=start_t_j+N-1; end; if(start_r_i+N-1>row || start_t_i+N-1<=row) 19
  20. 20. end_r_i=2*start_r_i+N-row -1; end_t_i=row; end; if(start_t_i+N-1>row || start_r_i+N-1<=row) end_r_i=start_r_i+start_t_i+N-row -2; end_t_i=row; end; if(start_t_i+N-1>row && start_r_i+N-1>row ) end_t_i=row end_r_i=start_r_i+end_t_i-start_t_i; end; if(start_t_i+N-1<=row ) end_t_i=start_t_i+N-1; end_r_i=start_r_i+N-1; end; f_e(start_t_i:end_t_i,start_t_j:end_t_j)=f_r(start_r_i:end_r_i,start_r_j:end_r_j); end; b=1; a=a+1; end; %Getting the Displaced Difference Frame Image dfd=imsubtract(f_e,f_t); %Getting the minimum value so as to properly match -ve values for better %display min_dfd=min(min(dfd)); dfd=dfd+abs(min_dfd); %Getting the Frame Difference fd=imsubtract(f_r,f_t); %Getting the minimum value so as to properly match -ve values for better %display min_fd=min(min(fd)); fd=fd+abs(min_fd); figure,imshow(mat2gray(f_r)); title('Reference Image'); figure,subplot(1,2,1),imshow(mat2gray(f_t)); title('Target Image'); subplot(1,2,2),imshow(mat2gray(f_e)); title('Predicted Image'); figure,subplot(1,2,1),imshow(mat2gray(dfd)); title('Displaced Frame Difference'); subplot(1,2,2),imshow(mat2gray(fd)); title('Frame Difference'); figure,quiver(V2,V1); set(gca,'xaxislocation','top','yaxislocation','left','xdir','default','ydir','reverse'); title('Motion Vector Field'); xlabel('Columns'); ylabel('Rows'); toc 20