我有一组相连的 Blob ,我想区分图中更规则的(a
、c
和 d
)来自更不规则的,例如 b
。
我尝试使用卷积区域(在 blob_area/convolved_blob_area 上设置阈值),shape factor and roundness但它们都不能很好地区分 d 和类似香蕉的形状。您建议使用哪些参数?谢谢!
最佳答案
我想到的一个想法是,您可以使用每个 Blob 大小
的角数
来确定规则性/不规则性
。测试结果似乎也符合我们的假设。这是代码 -
im = imread(input_image_path);
bw= im2bw(im);
%// Parameter for cutting into four slices into the third dimsensions
%// corresponding to the four objects
common_width = 270;
%// Threshold to decide between regular and irregular ones
factor1_th = 0.01;
bw1 = bw(:,1:common_width*floor(size(bw,2)/common_width)); %// Cropped image
objs =reshape(bw1,size(bw1,1),common_width,[]);%//Objects stored as dim3 slices
for objc=1:size(objs,3) %// Object counter
disp(['-------------- Processing Obj #' num2str(objc)]);
obj = objs(:,:,objc);
corners = corner(obj);
factor1 = size(corners,1)/nnz(obj)
if factor1 > factor1_th
disp('This is an irregular one.'); %//'
else
disp('This is a regular one.'); %//'
end
end
输出 -
-------------- Processing Obj #1
factor1 =
0.0050
This is a regular one.
-------------- Processing Obj #2
factor1 =
0.0109
This is an irregular one.
-------------- Processing Obj #3
factor1 =
0.0052
This is a regular one.
-------------- Processing Obj #4
factor1 =
0.0078
This is a regular one.
如果有人有兴趣运行代码,这里是删除了符号 a、b、c、d 的输入图像 -
链接 - /image/uPpUU.jpg
关于python - 区分规则和不规则形状的 Blob ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25608619/