Primitive Detection

Primitive detection

Concept: Primitive detection refers to the process of detecting and identifying basic shapes or specific local patterns in images in the field of computer vision and pattern recognition. Primitives can be simple geometric shapes, such as line segments, circles, rectangles, etc., or more complex local image structures, such as corners, textures, etc.

1. Edge detection
Edge is the discontinuous result of drastic changes in the gray value of pixels in the image. An edge is a property assigned to an individual pixel that is related to the gradient properties of an image function within a neighborhood of that pixel.

Edge magnitude: the magnitude of the gradient.
Edge direction: gradient direction rotated -90 degrees.
Edge detection principle
(Edge detection is both the basis of common primitive detection and the first step in boundary-based image segmentation.)
Edge detection algorithms: Sobel, Laplacian, and Canney operators.

2. Corner (Conner) Detection
Concept: Corner detection is a key task in the field of computer vision. It aims to detect the position of corner points in images. A corner point is a special pixel position in the image, and its surrounding area has large gradient changes in different directions. Corner points usually represent intersections or turning points of object edges and have the property of maintaining stability at different viewing angles and scales.

The main goal of corner detection is to find pixel locations in the image that have the following characteristics :
1. Gray gradient changes: The area around the pixel at the corner has obvious gray gradient changes in different directions, which means that in different directions The edges that undergo grayscale changes will converge at this point.
2. Isolation: Corner points are usually relatively isolated feature points in the image, with obvious grayscale differences from pixels in the surrounding area.

Common corner detection algorithms include the following:
1. Harris corner detection algorithm: evaluate the response value of the corner point by calculating the gray gradient and covariance matrix of the neighborhood around the pixel. Pixels with high response values ​​are considered corner points.
2. Shi-Tomasi corner detection algorithm: Based on an improved version of the Harris algorithm, using the minimum eigenvalue as the corner responsivity measure, it can better select corner points.
3.FAST corner detection algorithm: A fast corner detection algorithm that determines corner points through efficient pixel comparison on the circular neighborhood around the pixel.
4. SIFT (Scale Invariant Feature Transform) algorithm: a feature detection and description algorithm based on scale space, capable of detecting corner points under scale and rotation changes.
Corner detection

3. Hough Transform
concept: Hough Transform is a technology commonly used in image processing and computer vision. It is used to detect geometric shapes in images, especially straight lines and circles.

Common Hough transform detection applications:

1. Straight line detection: Hough transform can be used to detect straight lines in images. It finds all possible straight lines in an image and gives their parametric representation (usually in polar form). This is useful for edge detection and line segmentation in images.

2. Circle detection: Hough transform can also be used to detect circles in images. Similar to line detection, it can find all possible circles in the image and give their parametric representations. This is useful for detection and tracking of circular objects, such as target recognition and tracking in computer vision.

3. Curve detection: In addition to straight lines and circles, Hough transform can also be used to detect curves of other shapes. For example, if you know the mathematical equation form of the curve you want to detect, you can use the Hough transform to find the curves in the image that fit that equation.

Linear detection

! ! !
The following example uses the SUSAN operator for corner point detection and the Hough Transform for straight line detection;

exhibitmatlab代码

1. SUSAN operator corner detection

clear;
clc;
% 读取图像
Image=imread('susan.tif');  
% 转化为灰度图像
%Image=rgb2gray(Image);
% 显示图像
%imshow(Image);
% 获取图像高宽(行烈)
[ImageHeight,ImageWidth]=size(Image);
% 这一步没太大必要
%Image=double(Image);
% 判断灰度相近的阈值
threshold=45;  
% 当前像素和窗体内像素差别在t以下的个数,即相似的个数
usan=[];
% 计算以像素为中心的窗体内包含的
% 包含37个像素的圆窗口,面积为12*pi=37,因此是以sqrt(12)为半径的原
% 没有在外围扩展图像,最终图像会缩小
for i=4:ImageHeight-3         
   for j=4:ImageWidth-3 
        %从原图中截取7*7的区域再在其中挑选圆窗
        tmp=Image(i-3:i+3,j-3:j+3);  
        %c表示灰度值相近的程度,越大越相近
        c=0;
        for p=1:7
           for q=1:7
               %7*7的区域中选取圆窗包含的像素
                if (p-4)^2+(q-4)^2<=12 
                    %usan(k)=usan(k)+exp(-(((img(i,j)-tmp(p,q))/t)^6));
                    %判断灰度是否相近,t是自己设置的
                    if abs(Image(i,j)-tmp(p,q))<threshold  
                        c=c+1;
                    end
                end
           end
        end
        usan=[usan c];
   end
end
%相当于进一步调整阈值,在threshold的基础上进一步减少角点个数
g=2*max(usan)/3;
for i=1:length(usan)
   if usan(i)<g 
       usan(i)=g-usan(i);
   else
       usan(i)=0;
   end
end
% 由于usan是一维的,所以要重新变换为二维,对应图像位置
imgn=reshape(usan,[ImageWidth-6,ImageHeight-6])';
%figure;
%imshow(imgn)
%非极大抑制
[m n]=size(imgn);
re=zeros(m,n);
for i=2:m-1
   for j=2:n-1 
        if imgn(i,j)>max([max(imgn(i-1,j-1:j+1)) imgn(i,j-1) imgn(i,j+1) max(imgn(i+1,j-1:j+1))]);
            re(i,j)=1;
        else
            re(i,j)=0;
        end
   end
end
figure;
imshow(Image)
hold on;
[x,y]=find(re==1);
plot(y,x,'*')

Running result display:

Grayscale image: Grayscale image
edge detection:
edge detection
corner detection:
Corner detection

2. Hough Transform straight line detection

exhibitmatlab代码

clear;
close all;

img = imread('hough.jpg');
figure(1),
subplot(1,2,1);
imshow(img);  
title('原始图像'); 
img=rgb2gray(img);  % 灰度图像
subplot(1,2,2);
imshow(img);  
title('灰度图像'); 
thresh=[0.01,0.10];  %敏感度阈值
sigma=3;%定义高斯参数  

f = edge(double(img),'canny',thresh,sigma);  %边缘检测
figure(2),
imshow(f);  
title('canny 边缘检测');  
 
% 检测函数;
[H, theta, rho]= hough(f,'Theta', 20:0.1:75);  %0-1
% H->累计数组 , thetaH:对应的θ,实际上H的大小就是Rho×Theta
% Rho:H对应的ρ

peak=houghpeaks(H,5);  %峰值提取
hold on  %保留当前的图和特定的坐标轴属性,以便后续的绘图命令添加到现有的图表。
%得到线段信息
lines=houghlines(f,theta,rho,peak);  

figure(3);
imshow(f,[]);
title('霍夫变换检测结果');
hold on  ;

for k=1:length(lines)  
    xy=[lines(k).point1;lines(k).point2];  
    plot(xy(:,1),xy(:,2),'LineWidth',4,'Color',[1,0,0]);  
end  

Running result display:

Original image and grayscale image
canny edge detection
Hough transform detection

Summarize:

The SUSAN (Smallest Univalue Segment Assimilating Nucleus) operator is a corner detection algorithm commonly used in image processing, while the Hough transform is a technique used for straight line detection. Below I will introduce their respective characteristics:

Features of SUSAN operator for corner detection:

  1. Does not rely on the gradient information of the image: The SUSAN operator is based on the gray value statistical information around the pixel and does not need to calculate the gradient of the image. This makes it more robust to noise.
  2. It has certain robustness to illumination changes: the SUSAN operator determines the corner point by comparing the grayscale difference between the pixels in the neighborhood around the pixel and the central pixel. Therefore, effective corner detection can be performed even if there are certain illumination changes in the image.
  3. Scale invariance: The SUSAN operator can detect corner points on images of different scales. It uses an adjustable radius parameter to control the size of the neighborhood to achieve corner detection at different scales.

Features of Hough transform for straight line detection:

  1. Robustness: Hough transform has certain robustness to image noise and local interference. Since the Hough transform detects straight lines by accumulation in parameter space, it can ignore isolated points and interfering line segments in the image.
  2. For the detection of multiple straight lines: Hough transform can detect multiple straight lines existing in the image, not just one straight line. Its accumulation process in parameter space can detect different straight line parameter combinations.
  3. Sensitivity to local shape changes: Hough transform is more sensitive to local shape changes when detecting straight lines. Therefore, even if the straight line is interrupted to some extent or has discontinuities, the Hough transform can detect the corresponding straight line segment.

It should be noted that the SUSAN operator and Hough transform are both classic methods in the field of image processing, and each has its own characteristics and scope of application. In practical applications, according to specific scenarios and needs, appropriate algorithms can be selected for corner detection and straight line detection.

Guess you like

Origin blog.csdn.net/weixin_52374973/article/details/130625933