How to separate a set of pixels

11 views (last 30 days)
Hello,
After filtering my image (attached) that contains a large bubble, I arrived at image 5. My goal is to measure, even with low precision, the position of the tip of the larger bubble. Could you suggest any alternative so that I can separate the first set of white pixels from the bottom of the others? My goal is to exclude any pixel set other than the bottom one in image 5 so i can measure the position of the tip of the larger bubble.
Thanks in advance !
image = imread("image.jpg");
cropped = imcrop(image,[41 0 382 1024]);
figure, imshow(cropped);
gray = rgb2gray(cropped);
figure, imshow(gray);
threhsold = im2bw(gray, 0.5);
figure, imshow(threhsold);
remove = bwareaopen(threhsold,3500);
figure, imshow(remove);
se = strel('line',410,0);
closing = imclose(remove,se);
figure, imshow(closing);
originalLine = closing(1 , :);
originalLine2 = closing(end , :);
closing(1, :) = true;
closing(end, :) = true;
filtered = imfill(closing, 'holes');
closing(end,:) = false;
closing(1,:) = false;
filtered(1, :) = originalLine;
filtered(end, :) = originalLine2;
figure, imshow(filtered);
props = regionprops(filtered, 'BoundingBox');
for k = 1 : length(props)
thisBB = props(k).BoundingBox;
y(k) = thisBB(2) + thisBB(4);
end
[~, indexOfLowest] = max(y);
% Label the image
labeledImage = bwlabel(filtered);
% Extract the lowest blob
lowestBlob = ismember(labeledImage, indexOfLowest);
figure, imshow(lowestBlob);

Accepted Answer

Image Analyst
Image Analyst on 3 Feb 2022
You can get the bounding box of all of them, then find the one with the lowest bottom edge. Something like (untested)
props = regionprops(mask, 'BoundingBox');
for k = 1 : length(props)
thisBB = props(k).BoundingBox;
y(k) = thisBB(2) + thisBB(4);
end
[~, indexOfLowest] = max(y);
% Label the image
labeledImage = bwlabel(mask);
% Extract the lowest blob
lowestBlob = ismember(labeledImage, indexOfLowest);
Or you can use find() to find the row and column of the lowest pixel and use imreconstruct() to extract the blob that contains that pixel. Something like (untested)
[r, c] = find(mask); % Get coordinates of all white pixels.
% Find lowest (max r)
[rMax, indexOfLowest] = max(r)
% Make a marker image
markerImage = false(size(mask));
% Set that one pixel to true
markerImage(rMax, c(indexOfLowest)) = true;
% Use imreconstruct() to extract the lowest blob.
lowestBlob = imreconstruct(markerImage, mask);
  8 Comments
yanqi liu
yanqi liu on 7 Feb 2022
yes,sir,may be use watershed method to get image segment
Jórdan Venâncio Leite
Jórdan Venâncio Leite on 16 Feb 2022
Thanks for your answer yanqi liu

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!