How to separate a set of pixels

2 次查看(过去 30 天)
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);

采纳的回答

Image Analyst
Image Analyst 2022-2-3
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 个评论
yanqi liu
yanqi liu 2022-2-7
yes,sir,may be use watershed method to get image segment

请先登录,再进行评论。

更多回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by