Detecting Contour of bubble

12 views (last 30 days)
I am doing image processing on pictures of a droplet. However on quite a few images, the contour of the droplet is not detected when I try to read the image from left to right. I want all the white boundary to be detected from left to right. I have attached the necessary images too. Kindly help me out in this regard.
  2 Comments
G.N.V.SUDEEPTA VAISHNAVI
G.N.V.SUDEEPTA VAISHNAVI on 27 Nov 2021
This is the original image.
Image Analyst
Image Analyst on 27 Nov 2021
Edited: Image Analyst on 27 Nov 2021
No images are attached. I'm attaching one I got from KSSV.
I have no idea what you mean. What/where is the "contour"?
What do you mean by "I want all the white boundary to be detected from left to right."? To get boundaries (perimeter of white region) you can use bwperim() or bwboundaries().

Sign in to comment.

Accepted Answer

Image Analyst
Image Analyst on 29 Nov 2021
Again, not sure what you want since the description is not precise, but here are some options:
grayImage = imread('Vaishnavi.png');
binaryImage = grayImage(:, :, 1) > 128; % Binarize
% Method 1
perimImage = bwperim(binaryImage); % Get perimeter
rgbImage = imoverlay(binaryImage, perimImage, 'r'); % Show perimeter in the overlay.
imshow(rgbImage);
% Alternatively you can use Method 2
boundaries = bwboundaries(binaryImage); % Get a list of (x,y) coordinates of the perimeter.
x = boundaries{1}(:, 2);
y = boundaries{1}(:, 1);
hold on;
plot(x, y, 'r-', 'LineWidth', 3)
  3 Comments
Image Analyst
Image Analyst on 30 Nov 2021
To find all the coordinates of the white points in a binary image you can do this:
[whiteRows, whiteColumns] = find(binaryImage); % or [y, x] = (NOT [x, y]!!!)
Usually though you don't do that. The image itself is a map of what pixels are white.
I'm not quite sure what the rectangular portion is. Is it that white "tail" that shoots mostly upwards from the 2 O'Clock location on the round blob? If so there is a variety of things you can do to remove it depending on how much or little you're willing to alter the shape of the round part of the blob. The easiest thing to do is to just do a morphological opening with imopen().
You can also try to identify sharp turns in the (x,y) using Roger's method, or now there is a built-in findchangepts() function that you can try. Another option is to use fitpolynomialRANSAC() (if you have the Computer Vision Toolbox), or use movmedian() to identify points far away from the median. You might also try rmoutliers(). Like I said there are several ways it could be done, all with results that are mostly the same but may have small differences.
G.N.V.SUDEEPTA VAISHNAVI
G.N.V.SUDEEPTA VAISHNAVI on 30 Nov 2021
Yes, it is the tail that shoots upwards.
I will definitely look into the methods you suggested.

Sign in to comment.

More Answers (2)

KSSV
KSSV on 27 Nov 2021
I = imread('https://www.mathworks.com/matlabcentral/answers/uploaded_files/814649/image.jpeg') ;
% Remove boundary/ crop
I = I(10:end-10,10:end-10,:) ;
I1 = imbinarize(rgb2gray(I)) ;
% option 1
c = contour(I1) ;
% option 2
[y,x] = find(I1) ;
idx = boundary(x,y) ;
plot(x(idx),y(idx),'k')

yanqi liu
yanqi liu on 29 Nov 2021
clc; clear all; close all;
I = imread('https://www.mathworks.com/matlabcentral/answers/uploaded_files/814649/image.jpeg') ;
I = imcrop(I, [20 20 size(I,2)-40 size(I,1)-40]);
I1 = imbinarize(rgb2gray(I)) ;
figure; imshow(I1,[]); hold on;
[M,c] = contour(bwperim(I1)) ;
% set line
set(c, 'Color', 'r')
set(c, 'Color', 'r', 'LineWidth', 2)
% all the white boundary to be detected from left to right
be = bwperim(I1); [r,c] = find(be);
[~,ind] = min(c);
contour2 = bwtraceboundary(be,[r(ind) c(ind)],'W');
figure; imshow(I1,[]); hold on;
plot(contour2(:,2),contour2(:,1),'c','LineWidth',2)
  1 Comment
Image Analyst
Image Analyst on 29 Nov 2021
Like I said, you can use bwboundaries(). It's advantage is that you do not need to specify a starting point like you do with bwtraceboundary().

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!