How can I count no. of holes in an image and measure their diameter using matlab morphological operators?
<p>So I have a graylevel image that demonstrates an electronic circuit card and I'm supposed to inspect the number of holes and the diameter of the holes, and I'm also allowed to use morphology operators in Matlab. The image is as follows:</p>

<p><a href="https://i.stack.imgur.com/UHHFr.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/UHHFr.jpg" alt="pcb.jpg"></a></p>

<p>I could wrote some codes that can count number of holes, but I don't know how to measure their diameters!</p>

<pre><code>clear; close all; clc; warning off

im = imread('input\pcb.jpg');
im1 = im2bw(im,0);
% im1 = ~im2bw(im,0);
figure; imshow(im1);

strel1 = strel('disk',2);
im2 = imclose(im1,strel1);
figure; imshow(im2);

im3 = imfill(im2,'holes');
figure; imshow(im3);

im4 = im3 &amp; ~im1;
figure; imshow(im4);

strel2 = strel('disk',3);
im5 = imopen(im4,strel2);
figure; imshow(im5);

[~,numCC] = bwlabel(im5);
fprintf('Number of holes equals:\t%d\n',numCC);
</code></pre>

<p>I appreciate any comments in advance!</p>