필터 지우기
필터 지우기

How to separate a set of pixels

조회 수: 2 (최근 30일)
Jórdan Venâncio Leite
Jórdan Venâncio Leite 2022년 2월 3일
댓글: Jórdan Venâncio Leite 2022년 2월 16일
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
Jórdan Venâncio Leite
Jórdan Venâncio Leite 2022년 2월 16일
Thanks for your answer yanqi liu

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by