how to find number of foreground pixel and background pixel of an english alphabet

3 views (last 30 days)
I have to find number of foreground pixel and background pixel within in the boundingbox. For example the letter B ,If we draw the straight line 4-side of the letter B then it will create a rectangle box ,inside rectangle box letter B is there. Within in the bounding box I have to find number of foreground and background Pixel. This is my code:
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

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!