LOG斑点检测(附matlab代码)

斑点是数字图像的主要特征,是区域检测的一种特例,是许多特征生成、目标识别等方法的重要预处理环节。斑点通常和关键点(keypoint),兴趣点(intrestpoint)以及特征点(featurepoint)表示同一个概念。
利用高斯拉普通拉斯(Laplace of Gaussian,LOG)算子检测图像斑点是一种十分常用的方法。

function [points]=LoG_Blob(img,num_blobs)
%功能:提取LoG斑点
%img——输入图像
%num——需要检测斑点数目
%point——检测出的斑点
img=double(img(:,:,1));
if nargin==1     %如果输入参数仅有一个(img)
    num=120;    %则将检测斑点数设置为120
else
    num=num_blobs;
end
%设定LoG参数
sigma_begin=2;
sigma_end=15;
sigma_step=1;
sigma_array=sigma_begin:sigma_step:sigma_end;
sigma_nb=numel(sigma_array);
    %n = numel(A) returns the number of elements, n, in array A
    %equivalent to prod(size(A)).
img_height=size(img,1);
img_width=size(img,2);
%计算尺度规范化高斯拉普拉斯算子
snlo=zeros(img_height,img_width,sigma_nb);
for i=1:sigma_nb
    sigma=sigma_array(i);
    snlo(:,:,i)=sigma*sigma*imfilter(img,fspecial('log',...
        floor(6*sigma+1),sigma),'replicate');
end
%搜索局部极值
snlo_dil=imdilate(snlo,ones(3,3,3));
blob_candidate_index=find(snlo==snlo_dil);
blob_candidate_value=snlo(blob_candidate_index);
[temp,index]=sort(blob_candidate_value,'descend');
blob_index=blob_candidate_index(index(1:min(num,numel(index))));
[lig,col,sca]=ind2sub([img_height,img_width,sigma_nb],blob_index);
points=[lig,col,3*reshape(sigma_array(sca),[size(lig,1),1])];
end
function draw(img,pt,str)
%功能:在图像中绘制特征点
%img——输入图像
%pt——特征点坐标
%str——图上显示的名称
figure('Name',str);
imshow(img);
hold on;
axis off;
switch size(pt,2)
    case 2
        s=2;
        for i=1:size(pt,1)
            rectangle('Position',[pt(i,2)-s,pt(i,1)-s,2*s,2*s],'Curvature'...
                ,[0,0],'EdgeColor','b','LineWidth',2);
        end
    case 3
        for i=1:size(pt,1)
            rectangle('Position',[pt(i,2)-pt(i,3),pt(i,1)-pt(i,3),...
                2*pt(i,3),2*pt(i,3)],'Curvature',[1,1],'EdgeColor',...
                'w','LineWidth',2);
        end
end
end

输入图片

在matlab指令窗口输入:

img=imread('jpg.jpg');
imshow(img);
pt=LoG_Blob(rgb2gray(img));
draw(img,pt,'LOG')

即可得到结果图片

  • 2
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
OpenCV提供了多种斑点检测算法,其中包括SimpleBlobDetector、MSER(Maximally Stable Extremal Regions)、SIFT(Scale-Invariant Feature Transform)等。这里以SimpleBlobDetector为例,介绍一下OpenCV中如何实现斑点检测。 1. 首先,需要导入OpenCV库并读入待检测的图像,可以使用cv::imread()函数来读入图像。 ``` #include <opencv2/opencv.hpp> using namespace cv; int main() { Mat image = imread("test.png", IMREAD_GRAYSCALE); if (image.empty()) { std::cout << "Failed to read image." << std::endl; return -1; } // 进行斑点检测 // ... return 0; } ``` 2. 创建SimpleBlobDetector对象,并设置一些参数,如阈值、最小面积、最大面积等。 ``` SimpleBlobDetector::Params params; params.minThreshold = 10; params.maxThreshold = 200; params.filterByArea = true; params.minArea = 100; params.maxArea = 10000; Ptr<SimpleBlobDetector> detector = SimpleBlobDetector::create(params); ``` 3. 使用detector->detect()函数进行斑点检测,该函数返回一个vector类型的数据,其中包含了所有被检测到的斑点的坐标。 ``` std::vector<KeyPoint> keypoints; detector->detect(image, keypoints); ``` 4. 可以使用cv::drawKeypoints()函数将检测到的斑点绘制到图像上。 ``` Mat result; drawKeypoints(image, keypoints, result, Scalar(0,0,255), DrawMatchesFlags::DRAW_RICH_KEYPOINTS); imshow("Result", result); waitKey(0); ``` 这样就完成了斑点检测的过程,可以通过调整参数来适应不同的图像和应用场景。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

猛码Memmat

欢迎支持,随缘打赏 ~

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值