How can I fit a circle to a region of pixels?
조회 수: 17 (최근 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!
댓글 수: 0
답변 (3개)
Massimo Zanetti
2016년 10월 7일
You can manage by exploiting the "shape measurements" and other properties that function regionprops allows you to use:
댓글 수: 3
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
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
댓글 수: 0
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
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Image Segmentation and Analysis에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!