matlab灰度图像分割标记,matlab – 分割灰度图像
这是一个首发……使用circular Hough transform找到圆形部分.为此我最初是threshold the image locally.im=rgb2gray(imread('Ly7C8.png'));imbw = thresholdLocally(im,[2 2]); % thresold localy with a 2x2 window% preparing to find th
这是一个首发……
使用
circular Hough transform找到圆形部分.为此我最初是
threshold the image locally.
im=rgb2gray(imread('Ly7C8.png'));
imbw = thresholdLocally(im,[2 2]); % thresold localy with a 2x2 window
% preparing to find the circle
props = regionprops(imbw,'Area','PixelIdxList','MajorAxisLength','MinorAxisLength');
[~,indexOfMax] = max([props.Area]);
approximateRadius = props(indexOfMax).MajorAxisLength/2;
radius=round(approximateRadius);%-1:approximateRadius+1);
%find the circle using Hough trans.
h = circle_hough(edge(imbw), radius,'same');
[~,maxIndex] = max(h(:));
[i,j,k] = ind2sub(size(h), maxIndex);
center.x = j; center.y = i;
figure;imagesc(im);imellipse(gca,[center.x-radius center.y-radius 2*radius 2*radius]);
title('Finding the circle using Hough Trans.');
只选择圈内的内容:
[y,x] = meshgrid(1:size(im,2),1:size(im,1));
z = (x-j).^2+(y-i).^2;
f = (z<=radius^2);
im=im.*uint8(f);
编辑:
寻找一个开始阈值的地方,通过查看直方图来分割图像,找到它的第一个局部最大值,并从那里迭代直到找到2个单独的段,使用bwlabel:
p=hist(im(im>0),1:255);
p=smooth(p,5);
[pks,locs] = findpeaks(p);
bw=bwlabel(im>locs(1));
i=0;
while numel(unique(bw))<3
bw=bwlabel(im>locs(1)+i);
i=i+1;
end
imagesc(bw);
现在可以通过从圆圈中取出两个标记的部分来获得中间部分,剩下的将是中间部分(一些光环)
bw2=(bw<1.*f);
但经过一些中值滤波后,我们得到了更合理的东西
bw2= medfilt2(medfilt2(bw2));
我们一起得到:
imagesc(bw+3*bw2);
最后一部分是一个真正的“快速和肮脏”,我敢肯定,使用你已经使用的工具,你会得到更好的结果……
魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐


所有评论(0)