分割灰度图像

Ric*_*ard 6 matlab image-processing morphological-analysis image-segmentation mathematical-morphology

我无法实现灰度图像的正确分割:

要分割的图像

基本的事实,即我希望细分看起来像是这样的:

事实真相

我对圈内的三个组成部分最感兴趣.因此,正如您所看到的,我想将顶部图像分成三个部分:两个半圆,以及它们之间的矩形.

我尝试了各种扩张,侵蚀和重建的组合,以及各种聚类算法,包括k-means,isodata和高斯混合 - 所有这些都取得了不同程度的成功.

任何建议,将不胜感激.

编辑:这是我能够获得的最佳结果.这是使用活动轮廓来分割圆形ROI,然后应用等数据聚类获得的:

集群

这有两个问题:

  • 右下方群集周围的白色光环,属于左上角群集
  • 右上角和左下角群集周围的灰色光环,属于中心群集.

bla*_*bla 7

这是一个启动器......使用圆形Hough变换来找到圆形部分.为此,我最初在本地阈值图像.

 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.');
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

只选择圈内的内容:

 [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);
Run Code Online (Sandbox Code Playgroud)

编辑:

寻找一个开始阈值的地方,通过查看直方图来分割图像,找到它的第一个局部最大值,并从那里迭代直到找到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);
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

现在可以通过从圆圈中取出两个标记的部分来获得中间部分,剩下的将是中间部分(+一些光环)

 bw2=(bw<1.*f);
Run Code Online (Sandbox Code Playgroud)

但经过一些中值滤波后,我们得到了更合理的东西

 bw2= medfilt2(medfilt2(bw2));
Run Code Online (Sandbox Code Playgroud)

我们一起得到:

 imagesc(bw+3*bw2); 
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

最后一部分是一个真正的"快速和肮脏",我敢肯定,使用你已经使用的工具,你会得到更好的结果......