필터 지우기
필터 지우기

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

조회 수: 11 (최근 30일)
Kelsey Hilton
Kelsey Hilton 2016년 10월 7일
답변: Gianluca Iori 2018년 7월 24일
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