How to improve the filtering of a bubble image

조회 수: 3 (최근 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 CenterFile Exchange에서 Images에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by