How to improve the filtering of a bubble image

5 ビュー (過去 30 日間)
Jórdan Venâncio Leite
Jórdan Venâncio Leite 2020 年 4 月 14 日
コメント済み: Rena Berman 2020 年 10 月 12 日
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 件のコメント
Rik
Rik 2020 年 6 月 11 日
(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 2020 年 10 月 12 日
(Answers Dev) Restored edit

サインインしてコメントする。

採用された回答

Image Analyst
Image Analyst 2020 年 4 月 17 日
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 件のコメント
Image Analyst
Image Analyst 2020 年 4 月 18 日
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 2020 年 4 月 18 日
See step by step instructions in Steve's Image Processing Blog.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeImages についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by