Question

After MSER detection in Matlab, the returned MSER regions are ellipses. How do we get the exact points that make up each region?

The simple code:

REGIONS = detectMSERFeatures(I)

In OpenCV, we get both the fitted ellipses as well as the points of the region (as a contour). I could not find any direct mapping of the Matlab MSER parameters to the OpenCV parameters. So stuck with using Matlab for detecting MSERs.

However instead of the fitted ellipse, is there any way to get the actual points that comprise a region?

Was it helpful?

Solution

Edit: You can get the points you want using the Plot MSER regions property , for example (from matlab documentation):

regions = detectMSERFeatures(I);
imshow(I);hold on;
plot(regions);

Plot MSER Regions

figure; imshow(I);hold on;
plot(regions,'showPixelList',true, 'showEllipses',false);
hold off;

Original answer:

REGIONS will give you info regarding the Centroid (X0,Y0) the orientation angle (phi) and the minor and major axes (or their half: the a,b parameters of the ellipse).

Centroid: An M-by-2 array of [x y] centroid coordinates of ellipses that have the same second moments as the MSER regions. Axes: A two-element vector, [majorAxis minorAxis]. This vector specifies the major and minor axis of the ellipse that have the same second moments as the MSER regions. Orientation: A value in the range from -pi/2 to +pi/2 radians. This value represents the orientation of the ellipse as measured from the X-axis to the major axis of the ellipse.

You can loop using the code below on each of the stored regions (or COUNT property).

To draw a contour of the ellipse you can use the following code:

% These are just values to play with
a=10;
b=20;
phi=0.5236;
X0=40;
Y0=50;

 R  = [ cos(phi) sin(phi); -sin(phi) cos(phi) ];
 theta_r         = linspace(0,2*pi);
 ellipse_x_r     = X0 + a*cos( theta_r );
 ellipse_y_r     = Y0 + b*sin( theta_r );
 rotated_ellipse = R * [ellipse_x_r;ellipse_y_r];

 plot( rotated_ellipse(1,:),rotated_ellipse(2,:),'b' );

enter image description here

OTHER TIPS

You can get the all coordinates in each region by using:

for i=1:length(regions) 
    coordinates=getfield(regions(i),'PixelList');
end
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top