4

I wanted to know if there is any full implementation of image-matching by MSER and HOG in Matlab. Currently I am using VLFeat but found difficulties when performing the image matching. Any help?

Btw, I've tried the below code in VLFeat -Matlab environment but unfortunately the matching can't be performed.

%Matlab code
%
pfx = fullfile(vl_root,'figures','demo') ;
randn('state',0) ;
rand('state',0) ;
figure(1) ; clf ;

Ia = imread(fullfile(vl_root,'data','roofs1.jpg')) ;
Ib = imread(fullfile(vl_root,'data','roofs2.jpg')) ;

Ia = uint8(rgb2gray(Ia)) ;
Ib = uint8(rgb2gray(Ib)) ;

[ra,fa] = vl_mser(I,'MinDiversity',0.7,'MaxVariation',0.2,'Delta',10) ;
[rb,fb] = vl_mser(I,'MinDiversity',0.7,'MaxVariation',0.2,'Delta',10) ;

[matches, scores] = vl_ubcmatch(fa, fb);

figure(1) ; clf ;
imagesc(cat(2, Ia, Ib));
axis image off ;
vl_demo_print('mser_match_1', 1);

figure(2) ; clf ;
imagesc(cat(2, Ia, Ib));

xa = ra(1, matches(1,:));
xb = rb(1, matches(2,:)) + size(Ia,2);
ya = ra(2, matches(1,:));
yb = rb(2,matches(2,:));

hold on ;
h = line([xa ; xb], [ya ; yb]);
set(h, 'linewidth', 1, 'color', 'b');

vl_plotframe(ra(:,matches(1,:)));
rb(1,:) = fb(1,:) + size(Ia,2);
vl_plotframe(rb(:,mathces(2,:)));
axis image off ;

vl_demo_print('mser_match_2', 1);

%%%%%%
Dima
  • 38,860
  • 14
  • 75
  • 115
fahmifahim
  • 79
  • 1
  • 9

2 Answers2

1

There are a couple problems. First, the code has several errors and doesn't run as-is. I've pasted my working version below.

More importantly, you're trying to use the SIFT feature-matching function to match the MSER ellipsoids. This won't work at all, since SIFT gives a very high dimensional feature vector based on local image gradients, and the MSER detector is just giving you a bounding ellipsoid.

VLFeat doesn't appear to include an MSER-matching function, so you'll probably have to write your own. Take a look at the original MSER paper to understand how they did matching:

"Robust wide-baseline stereo from maximally stable extremal regions", Matas et al. 2002

% Read the input images
Ia = imread(fullfile(vl_root,'data','roofs1.jpg')) ;
Ib = imread(fullfile(vl_root,'data','roofs2.jpg')) ;

% Convert to grayscale
Ia = uint8(rgb2gray(Ia)) ;
Ib = uint8(rgb2gray(Ib)) ;

% Find MSERs
[ra,fa] = vl_mser(Ia, 'MinDiversity',0.7,'MaxVariation',0.2,'Delta',10) ;
[rb,fb] = vl_mser(Ib, 'MinDiversity',0.7,'MaxVariation',0.2,'Delta',10) ;

% Match MSERs
[matches, scores] = vl_ubcmatch(fa, fb);

% Display the original input images
figure(1); clf;
imagesc(cat(2, Ia, Ib));
axis image off;
colormap gray;

% Display a second copy with the matches overlaid
figure(2) ; clf ;
imagesc(cat(2, Ia, Ib));
axis image off;
colormap gray;

xa = fa(1, matches(1,:));
ya = fa(2, matches(1,:));
xb = fb(1, matches(2,:)) + size(Ia,2);
yb = fb(2, matches(2,:));

hold on ;
h = line([xa ; xb], [ya ; yb]);
set(h, 'linewidth', 1, 'color', 'y');
Steven Bell
  • 622
  • 5
  • 11
1

I don't know how, but MSER matching works in Matlab itself.

The code below

file1 = 'roofs1.jpg';
file2 = 'roofs2.jpg';

I1 = imread(file1);
I2 = imread(file2);

I1 = rgb2gray(I1);
I2 = rgb2gray(I2);

% %Find the SURF features.
% points1 = detectSURFFeatures(I1);
% points2 = detectSURFFeatures(I2); 

points1 = detectMSERFeatures(I1);
points2 = detectMSERFeatures(I2); 

%Extract the features.
[f1, vpts1] = extractFeatures(I1, points1);
[f2, vpts2] = extractFeatures(I2, points2);

%Retrieve the locations of matched points. The SURF featurevectors are already normalized.
indexPairs = matchFeatures(f1, f2, 'Prenormalized', true) ;
matched_pts1 = vpts1(indexPairs(:, 1));
matched_pts2 = vpts2(indexPairs(:, 2));


figure; showMatchedFeatures(I1,I2,matched_pts1,matched_pts2,'montage');
legend('matched points 1','matched points 2');

gives the following picture

enter image description here

Suzan Cioc
  • 29,281
  • 63
  • 213
  • 385