How to separate a set of pixels
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Jórdan Venâncio Leite
el 3 de Feb. de 2022
Comentada: Jórdan Venâncio Leite
el 16 de Feb. de 2022
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);
0 comentarios
Respuesta aceptada
Image Analyst
el 3 de Feb. de 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 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Image Processing Toolbox en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!