Detecting Contour of bubble

7 次查看(过去 30 天)
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 个评论
Image Analyst
Image Analyst 2021-11-27
编辑:Image Analyst 2021-11-27
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().

请先登录,再进行评论。

采纳的回答

Image Analyst
Image Analyst 2021-11-29
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 个评论
Image Analyst
Image Analyst 2021-11-30
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
Yes, it is the tail that shoots upwards.
I will definitely look into the methods you suggested.

请先登录,再进行评论。

更多回答(2 个)

KSSV
KSSV 2021-11-27
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 2021-11-29
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 个评论
Image Analyst
Image Analyst 2021-11-29
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().

请先登录,再进行评论。

Community Treasure Hunt

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

Start Hunting!

Translated by