quickat
quickat
181 0 0

写脚本数大米颗粒数

借助图像识别来数大米粒。在一张黑纸上,倒上一定数量的大米,尽量铺开(米粒之间不要有叠加和接触)

matlab写脚本数大米颗粒数

I = imread('rice.png'); 
subplot(1,2,1); imshow(I)
subplot(1,2,2); image(I); hold on; axis image

SD = strel('disk',25);
background = imopen(I,SD);
I = I - background;
bw = imbinarize(I);
[L, num] = bwlabel(bw,4);

k = 0;
for i = 1:num
    [y, x] = find(L==i);
    s = length(y)
    if s>30 & s<3000
        k = k + 1;
        text(mean(x),mean(y), num2str(k))
    end
end

测试源图

大米照片

来源 https://www.zhihu.com/question/548249436/answer/2625027636

0

See Also

Nearby


Discussion

Login Topics