如何对具有不同数量孔的对象进行分类?

时间:2019-05-02 17:02:27

标签: matlab image-processing computer-vision

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

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

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

Sample image Cell with two nucleus(holes)

0 个答案:

没有答案