How to separate a set of pixels
2 ビュー (過去 30 日間)
古いコメントを表示
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 !
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/883245/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/883250/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/883255/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/883260/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/883335/image.png)
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);
0 件のコメント
採用された回答
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 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Image Processing Toolbox についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!