Dear Experts, I am trying to detect bubbles from a glass image which is attached with this post. I have written a piece of code, I am able to detect some bubbles but still some bubbles/circles are left out, somebody can help me out what to do in this case. I am also facing problems while I use different sized image, as the same threshold doesn't work for all images, threshold refers to all the values, related to sensitivity, edge threshold and radius of the circle in this case. Awaiting for the guidance from the experts.
close all clear all clc warning off
image = imread('STILL095.jpg'); % read image
% get image dimensions: an RGB image has three planes % reshaping puts the RGB layers next to each other generating % a two dimensional grayscale image
[height, width, planes] = size(image);
rgb = reshape(image, height, width * planes);
imagesc(rgb); % visualize RGB planes
r = image(:, :, 1); % red channel
g = image(:, :, 2); % green channel
b = image(:, :, 3); % blue channel
threshold = 100; % threshold value
imagesc(b < threshold); % display the binarized image
% apply the blueness calculation
blueness = double(b) - max(double(r), double(g));
imagesc(blueness); % visualize RGB planes
H = fspecial('average',125); % Creating a low pass filter
filtimg = imfilter(blueness,H); % applying a low pass filter to the image
imagesc(filtimg)
hfiltimg = filtimg - blueness; % converting it to a high pass filtered image for enhancing edges
imagesc(hfiltimg)
B = im2bw(hfiltimg); % converting the image in black and white
se = strel('disk',3); % creating a structure element of radius 3
er = imclose(B,se); % perfoming image closing operation
[centersBright2, radiiBright2, metricBright2] = imfindcircles(er,[6 90], ... 'ObjectPolarity','bright','Sensitivity',0.65,'EdgeThreshold',0.4);
imshow(image) %Plotting the circles on the original image
h2 = viscircles(centersBright2, radiiBright2);