首页 > 解决方案 > 如何对不同孔数的物体进行分类?

问题描述

我的对象是对给定图像中的单元格进行分类。分类基于核(孔)的形状和数量。一些细胞具有圆形类型,而另一些则没有。有些有一个孔(核),而另一些有更多。

经过一些清理和预处理,到目前为止,我已经对圆形和重叠单元格进行了分类。但是有一个带有两个孔(核)的细胞应该属于另一类。但我做不到。如果我能数出孔的数量,我想我也可以对那个细胞进行分类。

im =imread('blood.jpg'); % Reading target image
figure(1),imshow(im), title('Original Image');
imGray = rgb2gray(im); % Converting image RGB to gray-level (2-Dimensional).
gray_thresh = graythresh(imGray);
bw = im2bw(imGray, gray_thresh);  figure(2), imshow(bw), title('Binary Image'); % Converting image to binary.
bw = imcomplement(bw); % Taking image's complement.
figure(3), imshow(bw), title('Complement of Image');
%bw=imfill(bw,'holes');
bw = imclearborder(bw);
figure(4), imshow(bw), title('Objects touching image borders removed');
bw = bwareaopen(bw,500); % Remove objects smaller than 500px.
figure(5),imshow(bw); title('Small objects removed');

label = bwlabel(bw);

[B,L] = bwboundaries(bw,'noholes');
stats = regionprops(L,'Area','Centroid');
threshold = 0.70;

figure(6), imshow(bw)
hold on
for k = 1:length(B)  
  % obtain (X,Y) boundary coordinates corresponding to label 'k'
  boundary = B{k};
  % compute a simple estimate of the object's perimeter
  delta_sq = diff(boundary).^2;    
  perimeter = sum(sqrt(sum(delta_sq,2)));
  % obtain the area calculation corresponding to label 'k'
  area = stats(k).Area;
  % compute the roundness metric
  metric = 4*pi*area/perimeter^2;

  if metric > threshold
    plot(boundary(:,2),boundary(:,1),'r','LineWidth',2)
    %Circular
  else
    plot(boundary(:,2),boundary(:,1),'g','LineWidth',2)
    %Overlapped
  end
end

示例图像 有两个核(孔)的细胞

标签: matlabimage-processingcomputer-vision

解决方案


推荐阅读