joel_1993 2021-08-30 22:54 采纳率: 100%
浏览 156
已结题

我有一张这样的图片,如何提取里面的红色圈圈坐标,并且连接这些坐标形成两个封闭的环路?我有很多类似的图片,需要批处理

下面是给出的图片,我还有很多类似的图片,处理起来需要返回圆圈的像素坐标,最后连接封闭图形的顺序坐标
img

  • 写回答

2条回答 默认 最新

  • slandarer MATLAB领域优质创作者 2021-08-31 11:48
    关注

    大概写了一下不知道是否有帮助:

    function redPnt
    oriPic=imread('test1.png');
    subplot(2,2,1)
    imshow(oriPic)
    
    % 删除红色外的部分并构造二值图
    grayPic=rgb2gray(oriPic);
    grayPic(oriPic(:,:,1)<255)=255;
    grayPic(grayPic<250)=0;
    subplot(2,2,2)
    imshow(grayPic)
    
    % 图像膨胀,使未连接边缘连接
    SE=[0 1 0;1 1 1;0 1 0];
    bwPic=imerode(grayPic,SE);
    
    % 边缘清理:保留圆圈联通区域
    bwPic=imclearborder(bwPic);
    subplot(2,2,3)
    imshow(bwPic)
    
    % 获取每一个联通区域
    LPic=bwlabel(bwPic);
    labelNum=max(max(LPic));
    
    % 计算每一个联通区域 坐标均值
    pointSet=zeros(labelNum,2);
    for i=1:labelNum
        [X,Y]=find(LPic==i);
        Xmean=mean(X);
        Ymean=mean(Y);
        pointSet(i,:)=[Xmean,Ymean];
    end
    
    subplot(2,2,4)
    imshow(bwPic)
    hold on
    scatter(pointSet(:,2),pointSet(:,1),'r','LineWidth',1)
    
    n=1;
    while ~isempty(pointSet)
        circleSetInd=1;
        for j=1:length(pointSet)
            disSet=sqrt(sum((pointSet-pointSet(circleSetInd(end),:)).^2,2));
            [~,ind]=sort(disSet);
            ind=ind(1:5);
            [~,~,t_ind]=intersect(circleSetInd,ind);
            ind(t_ind)=[];
            if ~isempty(ind)
                circleSetInd=[circleSetInd;ind(1)];
            else
                circleSet{n}=pointSet(circleSetInd,:);
                pointSet(circleSetInd,:)=[];
                n=n+1;
                break
            end
        end
    end
    
    figure
    imshow(oriPic)
    hold on
    for i=1:n-1
    plot(circleSet{i}(:,2),circleSet{i}(:,1),'LineWidth',2)
    end
    
    end
    

    没有用霍夫圆形检测之类算法,只是单纯的图像膨胀,边缘清理,寻找联通区域,计算联通区域坐标均值
    大概过程如下图所示:

    img

    img

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 9月9日
  • 已采纳回答 9月1日
  • 创建了问题 8月30日

悬赏问题

  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据