MATLAB: Finding circles in a thresholded image

image analysisImage Processing ToolboximfindcirclesMATLAB

I am trying to find the center, radius and area of a circle. The circles edge is a gradient from black to white so I am trying to threshold it so I can manipulate where the circles edge starts.
The image is:
My current code is:
clear all
clc
T1 = imread('T2.png');
figure(1)
imshow(T1)
% Threshold to find circles
BI = T1 < 10;
% Removes elements less than 10 pixels
BI = bwareaopen(BI, 10);
figure(2)
imshow(BI)
[centers, radii, metric] = imfindcircles(BI,[10 200]);%Finds circles between a b pixels
viscircles(centers, radii,'EdgeColor','b');%Draws on edge
Ar = radii'*3.14;%Finds area
%Outputs center, radius and Area
centers
radii
Ar

Best Answer

This is what I ended up doing:
clear all, clc
T2 = imread('T2.png');
%Threshold image
BW = T2 > 100;%Lower number = more white
BW2 = BW;
ext = logical(ones(numel(BW(:,1)),1));
BW2 = [ext BW2 ext];
BW2 = imdilate(BW2,ones(3));
BW2 = imfill(BW2,'holes');
BW2 = imerode(BW2,ones(3));
BWout = BW2(:,2:end-1);
imshow(T2)
[centers, radii, metric] = imfindcircles(BWout,[10 200]);%Finds circles between a b pixels
viscircles(centers, radii,'EdgeColor','b');%Draws on edge
Ar = radii'*3.14;%Finds area
%Outputs center, radius and Area
centers
radii
Ar
Related Question