How to improve the filtering of a bubble image

3 Ansichten (letzte 30 Tage)
Jórdan Venâncio Leite
Jórdan Venâncio Leite am 14 Apr. 2020
Kommentiert: Rena Berman am 12 Okt. 2020
I need to better filter my image (a bubble) in order to obtain a better filtering than the one I already have (code), in order to get a better approximation of the contour of the bubble.
Would you know of any other filters or what I could change in my code to improve the borders I drew in red and to make the filtered image of the bubble (image 2) better look like the real bubble outline? (it should look like a semi-ellipse)
Thanks in advance
clc
clear
close all
% 1 - Reading the image
image = imread('bubble.png');
figure, imshow(image);
% 2 - Cropping the image
cropped = imcrop(image,[552.9 0 639.2 1080]);
figure, imshow(cropped);
% 3 - Gray scale
gray = rgb2gray(cropped);
figure, imshow(gray);
% 4 - Threshold filter
thresh = im2bw(gray, 0.5);
figure, imshow(thresh);
% 5 - Small pixel cluster removal filter
remove = bwareaopen(thresh, 13200);
figure, imshow(remove);
% 6 - Close connections filter
se = strel('line',300,0);
closing = imclose(remove,se);
figure, imshow(closing);
% 7 - Fill center of objects filter
OriginalLine = closing(1 , :);
OriginalLine2 = closing(end , :);
closing(1, :) = true;
closing(end, :) = true;
fill = imfill(closing, 'holes');
closing(end,:) = false;
closing(1,:) = false;
fill(1, :) = OriginalLine;
fill(end, :) = OriginalLine2;
figure, imshow(fill);
  2 Kommentare
Rik
Rik am 11 Jun. 2020
(Retrieved from Google cache)
Question title:
How to improve the filtering of a bubble image
Question body:
I need to better filter my image (a bubble) in order to obtain a better filtering than the one I already have (code), in order to get a better approximation of the contour of the bubble.
Would you know of any other filters or what I could change in my code to improve the borders I drew in red and to make the filtered image of the bubble (image 2) better look like the real bubble outline? (it should look like a semi-ellipse)
Thanks in advance
clc
clear
close all
% 1 - Reading the image
image = imread('bubble.png');
figure, imshow(image);
% 2 - Cropping the image
cropped = imcrop(image,[552.9 0 639.2 1080]);
figure, imshow(cropped);
% 3 - Gray scale
gray = rgb2gray(cropped);
figure, imshow(gray);
% 4 - Threshold filter
thresh = im2bw(gray, 0.5);
figure, imshow(thresh);
% 5 - Small pixel cluster removal filter
remove = bwareaopen(thresh, 13200);
figure, imshow(remove);
% 6 - Close connections filter
se = strel('line',300,0);
closing = imclose(remove,se);
figure, imshow(closing);
% 7 - Fill center of objects filter
OriginalLine = closing(1 , :);
OriginalLine2 = closing(end , :);
closing(1, :) = true;
closing(end, :) = true;
fill = imfill(closing, 'holes');
closing(end,:) = false;
closing(1,:) = false;
fill(1, :) = OriginalLine;
fill(end, :) = OriginalLine2;
figure, imshow(fill);
Rena Berman
Rena Berman am 12 Okt. 2020
(Answers Dev) Restored edit

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Image Analyst
Image Analyst am 17 Apr. 2020
Can you assume the ellipse axes will be vertical and horizontal? If not, see the FAQ: Click here
Otherwise you can use bwferet() to get the caliper dimension in one direction. Call it 2*a. Use sum() or regionprops() to get the area and centroid,
binaryImage = bwareafilt(binaryImage, 1); % Take largest blob only.
props = regionprops(binaryImage, 'Area', 'Centroid');
area = props.Area;
xCenter = props.Centroid(1);
yCenter = props.Centroid(2);
hold on;
plot(xCenter, yCenter, 'r+', 'MarkerSize', 60, 'LineWidth', 2); % Plot crosshairs at the centroid.
then, since the area of an ellipse is pi*a*b,
b = area / (pi * a);
Create an ellipse from the code in the FAQ:
xCenter = 12.5;
yCenter = 10;
xRadius = 2.5;
yRadius = 8;
theta = 0 : 0.01 : 2*pi;
x = xRadius * cos(theta) + xCenter;
y = yRadius * sin(theta) + yCenter;
plot(x, y, 'LineWidth', 3);
grid on;
where xRadius = b and yRadius = a (if vertical is the feret diameter direction you picked).
Or you might try activecontour(). See attached demo.
  2 Kommentare
Image Analyst
Image Analyst am 18 Apr. 2020
You have an old version then. Try using regionprops() and getting the MajorAxisLength and MinorAxisLength, which are the axes of an ellipse fit to your blob.
Image Analyst
Image Analyst am 18 Apr. 2020
See step by step instructions in Steve's Image Processing Blog.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Images finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by