3. Demo step by step for one scale.
This code is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License.This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
This code is written for the paper [1]. It was initially developed by Gang and Liming, and cleaned up by Liming in Jan 2008. It's tested under Matlab 7.0. The version number is now 1.0beta.
The main part of the code uses improved Shape Context as feature descriptor and fit into a Hough Voting framework to detect objects. It can be used for initial hypothesis proposal. I hope you find this code helpful!
Note:
1) Currently, this code does not include the False Positive Pruning (FPP) procedure using bottom-up segmentation, which is the second part of the paper [1].
% load codebook, which are set of model features (How does codebook look like?)
load(codebook_file);
% Take 'FudanPed00001.png' as an example,only scale 4 is demonstrated.
% Please see how to detect object across scales here.
% Only some code fragments are shown here, please refer to 'demo_one_image.m' for details
img_name = 'FudanPed00001.png';
img= imread(img_name); % read image data in.
imshow(img); % Figure 1
% edge detection on image using pb edge detector
I_edge = compute_edge_pb(img);
imshow(I_edge.edge); % Figure 2
% sample feature points on test image and remove those nearly-zero features
testpos = sample_grid_location([imgh,imgw], para_fea.sample_step);
hold on;
plot(testpos(:,1),testpos(:,2), '*'); % Figure 3
extract_sc_feature;
![]() |
![]() |
![]() |
| Fig 1. Input image. | Fig 2. Edge detection result of input image. | Fig 3. Sample points on input image to extract features on. |
% compute matching for each feature points, each test feature point will look for best K matches among codebook
compute_matching_scores_bestK;
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
||
| Fig 4. 'A' is a point on input image. | Fig 5. These 7 images are from codebook, which are model images. 'B' - 'H' are matches to 'A' in Fig 4. Each match will indicate where the body center could possibly be. |
|||
% each match votes for possible candidate positions
get_candidate_pos; % Figure 5
% generate hypotheses acording to vote map
get_hypo_center; %Figure 6, Figure 7
![]() |
![]() |
| Fig 6. Vote result. High value indicate high possiblity that position could be a hypothesis center. | Fig 7. Select hypotheses postition from vote map(Fig. 6), indicated by magenta cross. |
% For each possible hypotheses, trace back to get its vote mask and boundary box.
generate_mask_and_bbox; % Figure 8
% Enforce one-to-one feature point and model point match, Figure and figure show the score computed before this enforcement and after
compute_unique_vote_score; % Figure 9
![]() |
![]() |
| Fig 8. For each hypothesis, trace back to find its voters and each vote predict the foreground/background labeling of the input image, which gives a hypothesis mask, and boundary boxs can be easily derived from this mask. | Fig 9. After force one-to-one unique matching, we get an new score for each hypothesis. |
[1] Object Detection Combining Recognition and Segmentation, Liming Wang, Jianbo Shi, Gang Song, I-Fan Shen, Eighth Asian Conference on Computer Vision (ACCV), 2007 [Database: Penn-Fudan Pedstrian Database ]
[2] Normalized Cuts and Image Segmentation Jianbo Shi and Jitendra Malik IEEE Transactions on Pattern Analysis and Machine Intelligence(PAMI) 2000
wanglm AT fudan DOT edu DOT cn.