I have a binary image of a bubble. I would like to: 1. Fit a circle onto the bubble (white pixels region); and 2. Mark the centre of the bubble; in the following order.

조회 수: 7 (최근 30일)
  댓글 수: 1
Syamsundar Menon Murali Mohan
Syamsundar Menon Murali Mohan 2021년 9월 2일
*Please note that what I mean by circle is, to fit an equivalent circle that can fit within the region of the bubble; as the bubble is not a perfect circle

댓글을 달려면 로그인하십시오.

채택된 답변

Image Analyst
Image Analyst 2021년 9월 3일
Try this:
% Demo to find three different circles ralted to a blob.
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 20;
markerSize = 40;
%--------------------------------------------------------------------------------------------------------
% READ IN IMAGE
fileName = 'image.jpeg';
grayImage = imread(fileName);
% Get the dimensions of the image.
% numberOfColorChannels should be = 1 for a gray scale image, and 3 for an RGB color image.
[rows, columns, numberOfColorChannels] = size(grayImage)
if numberOfColorChannels > 1
% It's not really gray scale like we expected - it's color.
% Extract the red channel (so the magenta lines will be white).
grayImage = grayImage(:, :, 1);
end
binaryImage = logical(grayImage);
% Crop off white frame.
binaryImage = imclearborder(binaryImage);
% Take largest blob only.
binaryImage = bwareafilt(binaryImage, 1);
% Crop the image
binaryImage = binaryImage(760:840, 290:390);
%--------------------------------------------------------------------------------------------------------
% Display the image.
subplot(2, 1, 1);
imshow(binaryImage, []);
impixelinfo;
axis('on', 'image');
title('Original Binary Image', 'FontSize', fontSize, 'Interpreter', 'None');
hold on
drawnow;
%--------------------------------------------------------------------------------------------------------
% FIND THE CIRCLE THAT CAN FIT COMPLETELY INSIDE.
% Do the distance transform
edtImage = bwdist(~binaryImage);
% Show results
subplot(2, 1, 2);
imshow(edtImage, []);
title('EDT Image', 'FontSize', fontSize);
axis('on', 'image');
impixelinfo;
drawnow;
g = gcf;
g.WindowState = 'maximized'
% Find the max
innerRadius = max(edtImage(:))
[ctrRows, ctrColumns] = find(edtImage == innerRadius)
% Put a inner circle there
subplot(2, 1, 1);
viscircles([ctrColumns, ctrRows], innerRadius);
%----------------------------------------------------------
% FIND THE EQUIVALENT CIRCULAR DIAMETER.
% This is the diameter of a circle that has the same area as our blob.
props = regionprops(binaryImage, 'EquivDiameter', 'Centroid');
% Display the ECD circle
viscircles([props.Centroid(1), props.Centroid(2)], props.EquivDiameter/2);
%----------------------------------------------------------
% FIND THE OUTER CIRCULAR DIAMETER.
% This is the diameter of a circle that will completely enclose our blob.
boundaries = bwboundaries(binaryImage, 'noholes');
xb = boundaries{1}(:, 2);
yb = boundaries{1}(:, 1);
% Show boundary
hold on;
plot(xb, yb, 'g-', 'LineWidth', 2);
% John D'Errico (2021). A suite of minimal bounding objects (https://www.mathworks.com/matlabcentral/fileexchange/34767-a-suite-of-minimal-bounding-objects), MATLAB Central File Exchange. Retrieved September 3, 2021.
[center, radius] = minboundcircle(xb, yb)
% Display the outer circle.
hold on;
viscircles(center, radius);
There are three different kinds of circles. One that fits inside, one that bounds everything on the outside of the blob, and the middle one that is the equivalent circular diameter (diameter of a circle that has the same area as the blob).

추가 답변 (1개)

Image Analyst
Image Analyst 2021년 9월 2일
If it has to fit within, use bwdist to find the radius and centroid. Then place your circle. Here's a start:
edtImage = bwdist(mask); % or maybe bwdist(~mask)
radius = max(edtImage)
% Find centroid
[row, col] = edtImage == radius
% Plot circle
viscircle([col(:), row(:)], radius);
plot(col, row, 'r+', 'LineWidth', 2, 'MarkerSize', 30)
  댓글 수: 1
Syamsundar Menon Murali Mohan
Syamsundar Menon Murali Mohan 2021년 9월 3일
My radius value is a single row vector, hence why the [row,col] does not work.
I was hoping to fit the circle somewhat around the boundary of the bubble

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Image Processing and Computer Vision에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by