ChamferMatching
Project summary This project is to use Chamfer matching to find the head of human in the kinect depth image. Main steps including: (1) Estimate the size of the head of person in the image as a circle and create such a circle. (2) Run Canny edge detection algorithm to generate the edge images. (3) Use distance transform (fast sweeping method) to get distance image. (4) Use a modified version of chamfer matching which is resistant to clutter, to locate the head.
Algorithm description Step 1, build template The radius of head is estimated to be 27, so a template whose size is slightly larger than the diameter is used. The following code create the template in which only the circle boundary is 1. template = double(abs(x.^2 + y.^2-radius^2) < cw); Fig.1. Circle template. Step 2, edge detection A canny edge detector with 0.02 threshold and 1.4 sigma is used. [edge_map,thresh] = edge(I,'canny', 0.02,1.4);
Fig. 2. Edge image for ‘Depth1’ and ‘Depth2’ Step 2, distance transform Fast sweeping method is used to get the distance image. Details about this method can be found in the reference article attached1. The core part of this method is that the unsigned distance field function is the solution of equation:
The fast sweeping method sweeps 4 times along different directions (left down, right down, left up, right up), to finish a calculation of the distance field. Speed Issue: When find the minimum of two quantities, the matlab function min is very slow, so it is replaced by compare and switch, e.g.: uxmin=min([u(i-1,j),u(i+1,j)]); Is replaced by: if u(i-1,j)<u(i+1,j) uxmin=u(i-1,j); else uxmin=u(i+1,j); end This reduced the execution time from 9 seconds to 0.3 seconds. Fig. 3. Distance image of ‘Depth1’ and ‘Depth2’. The left down corner of ‘Depth2’ has certain background clutter.
Step 4, chamfer matching Normal chamfer matching: Chamfer matching: find placement of template in an image that minimizes the sum, M, of the distance transform multiplied by the pixel values in template.2 This can be implemented as find the minimum of the convolution of the template and distance image. C = conv2(dt_euclidean,template,'valid'); [ColumnMin, Y]= min(C); [Gmin, X]= min(ColumnMin); min_x = X min_y = Y(X) Here ‘valid’ mode is used, so the there’s no zero-padding, and invalid boundary is discarded.
Fig. 4. Normal chamfer matching. It works on ‘Depth1’, but in ‘Depth2’ false positive is obtained in the background clutter, where the distance field is small throughout the region.
Modified chamfer matching: To get rid of the false positive in background clutter, I noticed that there’s a difference between real match position and false match position; for a real match, the regions inside the template are of large distance, while for a background clutter, all regions are of small distance, as shown in Fig. 5.
Fig. 5. Illustration of modified chamfer matching.
So I use another solid circle template, and have another convolution with the distance image: template2 = double(x.^2+y.^2<r2); % template for background clutter removal C2 = conv2(dt_euclidean,template2,'valid'); In the obtained error threshold image C2, as shown in Fig.6, the background clutter will have very small value, so a threshold is used to rule out the background region. In other words, a real match position should have a C2 value large than Cthres: Cthres = (2 * tplt_sz + 1)^2 * 3; Here the Cthres have an average value of 3.
Fig. 6. Error threshold image. Then in C, all these false regions are set as maximum, as shown in Fig. 7. C(C2<Cthres) = max(max(C)); Then the minimum of this modified C will give the real match position:
Fig. 7. Modified chamfer matching. It works on both images. Result The final match result is shown in Fig. 8. Fig. 8. Final result of the modified chamfer matching. It works on both images. Matlab source code description ChamferMatch.m main function for chamfer match dist_FC.lm fast sweeping method for distance transform
To execute the main function, call: ChamferMatch('Depth2.png') ChamferMatch('Depth2.png') Reference 1. Zhao, Hongkai. "A fast sweeping method for eikonal equations." Mathematics of computation 74.250 (2005): 603-627. 2. Tony X. Han, “ImageProc_16_Matching.ppt” from http://web.missouri.edu/~hantx/img_proc/ |