如何在图像上绘制包括surfPoints对象的矩形?

问题描述

我有一个灰度图像,我想使用detectSURFFeatures()提取感兴趣的区域。使用此函数,我得到一个surfPoints对象。 通过在图像上显示该对象,我将圆圈作为感兴趣的区域。 就我而言,我想要包含这些圆的矩形区域。 更清楚地说,我有一张图片1:

initial image

我想使用:detectSURFFeatures()提取感兴趣区域(ROI),我们获得图像

image after detection

如果您看到我们有一个圆形区域,那么我希望包含圆形区域的矩形投资回报率:

results desired

解决方法

半径似乎完全由points.Scale参数确定。

% Detection of the SURF features:
I = imread('cameraman.tif');
points = detectSURFFeatures(I);
imshow(I); hold on;

% Select and plot the 10 strongest features 
p = points.selectStrongest(10)
plot(p);


% Here we add the bounding box around the circle.
c = 6; % Correction factor for the radius
for ii = 1:10
    x = p.Location(ii,1); % x coordinate of the circle's center
    y = p.Location(ii,2); % y coordinate of the circle's center
    r = p.Scale(ii);      % Scale parameter
    rectangle('Position',[x-r*c y-r*c 2*r*c 2*r*c],'EdgeColor','r')
end

我们得到以下结果:

enter image description here

在此示例中,半径的校正因子为6。我猜想这个值对应于SURFPoints对象(即12.0)的默认Scale属性的一半。但是由于文档中没有关于此的信息,所以我可能是错的。而且要小心,每个ROI的比例 parameter SURFPoints对象的比例 propertie 不同。