以字母“B”的图像为例:
.
如果我们在字母“B”的 4 侧绘制直线,那么它将创建一个矩形框。我必须在上图中的这个边界框(Recangle Box)中找到前景和背景像素的数量。我没有得到结果。请帮助我。谢谢你。
这是我的代码:
E = imread('1.jpg');
label = graythresh(E);
BW = im2bw(E, label);
imshow(BW)
L = bwlabel(E);
z = regionprops(L,'BoundingBox');
nBlackpixel = sum(z(:))
nWhitepixel = numel(z) - nBlack