matlab - 如何对不同孔数的物体进行分类?
问题描述
我的对象是对给定图像中的单元格进行分类。分类基于核(孔)的形状和数量。一些细胞具有圆形类型,而另一些则没有。有些有一个孔(核),而另一些有更多。
经过一些清理和预处理,到目前为止,我已经对圆形和重叠单元格进行了分类。但是有一个带有两个孔(核)的细胞应该属于另一类。但我做不到。如果我能数出孔的数量,我想我也可以对那个细胞进行分类。
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
解决方案
推荐阅读
- java - 使用 AES scala 进行文件加密和解密
- android - 房间数据库的类型转换器不起作用
- laravel-fortify - laravel fortify 登录后如何获取用户信息
- javascript - 向对象添加键值
- node.js - 运行 npm run watch 并在 laravel-vue 项目中出现此错误。如何解决?
- http-status-code-500 - 使用管理 API 更新“JSON”类型的 Pulsar 模式时出现 500 错误
- ios - 如何在真正的 Apple Watch 上调试快捷方式意图?
- c# - 我只想在 Xamarin.Forms 不旋转屏幕的情况下获取设备的旋转状态
- java - 在 Spring 自定义查询中找不到类型的属性
- assembly - MASM 相当于 NASM