Detecting bubbles from images

14 views (last 30 days)
Sander Khowaja
Sander Khowaja on 28 Jun 2016
Commented: Vidya Viswanathan on 11 Jul 2016
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);
  1 Comment
Vidya Viswanathan
Vidya Viswanathan on 11 Jul 2016
Hi,
I am not sure if you have come across this already, but for your specific use case, I would suggest you to try out active contour based segmentation technique. The following documentation link has the description of the function and an example for the same:
I hope this helps.
Regards,
Vidya Viswanathan

Sign in to comment.

Answers (0)

Categories

Find more on Image Processing Toolbox in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!