How can I fit a circle to a region of pixels?

24 次查看(过去 30 天)
I have a series of 2D CT slices of trabecular bone. I have binarized them and detected the boundaries of the bone, and now I would like to do a bit more processing. I am trying to fit the largest possible circle into each slice in the black pixel regions. I've included an image so you can see what I mean.
I've tried something like this:
stats = regionprops('table',bw,'Centroid','EquivDiam');
where bw is my binary image without the boundaries drawn in.
Any help would be great! I'm struggling to find other examples which match mine.
Thanks in advance!

回答(3 个)

Massimo Zanetti
Massimo Zanetti 2016-10-7
You can manage by exploiting the "shape measurements" and other properties that function regionprops allows you to use:
  3 个评论
Kelsey Hilton
Kelsey Hilton 2016-10-7
I've attached an example of what I get if I use that option. Maybe it'll help.
Massimo Zanetti
Massimo Zanetti 2016-10-7
You are considering "on" pixels the white ones. Try negate the input of bwconncomp. For example instead of using:
C = bwconncomp(BW)
use
C = bwconncomp(~BW)
This way you will consider the black areas.

请先登录,再进行评论。


Bert
Bert 2016-10-7
I'm not familiar with this toolbox. But have you tried simply scanning all point? you could do something like this:
% create indexes
ix = repmat([1:size(bw,2)],size(bw,1),1);
iy = repmat([1:size(bw,1)]',1,size(bw,1));
% all in vector
bw = bw(:);
ix = ix(:);
iy = iy(:);
% init loop
center = [];
radius = 0;
% indexes of all black points, possibally the center
I = 1:length(bw);
I = I(bw==0);
for i = I
% all distances from thi point to white ones
distances = sqrt( (ix(i)-ix(bw==1)).^2 + (iy(i)-iy(bw==1)).^2 );
% smallest distance
distance = min(distances);
if distance>radius % this point has the biggest minimal distance to a white one yet
radius = distance;
center = [iy(i) ix(i)];
end
end

Gianluca Iori
Gianluca Iori 2018-7-24
dear Kelsey, the problem is called "Maximum Inscribed Circle". Solution is provided here: https://de.mathworks.com/matlabcentral/fileexchange/30805-maximum-inscribed-circle-using-distance-transform

Community Treasure Hunt

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

Start Hunting!

Translated by