I tried to select borders and then calculate the area. Вut I'm having some difficulty with this. Here's my original image.
After after some processing of the original image I obtained this image:
Here's my code:
clear;
I=imread('C:\Users\Sashka\Desktop\calculator.jpg');
i=rgb2gray(I);
background = imopen(i,strel('disk',20));
im=histeq(background, 64);
uns=fspecial('unsharp') ;
uns1=imfilter(im, uns);
bw = im2bw(uns1,0.3);
bw2=bwmorph(bw, 'close', Inf);
bw3=bwmorph(bw2, 'majority', Inf);
bw4=bwmorph(bw3, 'erode', 18);
c=[30 30 440 440];
r=[480 680 680 480];
bw5=bwselect(bw4,c,r,4);
I2=imcrop(bw5, [30 25 1300 1090]);
Can You please help me to count the number of medium-sized buttons?
Just use
regionprops
and define a threshold of the maximum or minimum area of the desired buttons, example:your code plus...
which for example gives,