我有一个骨架图像。如下面的链接所示。
http://www.flickr.com/photos/92388309@N03/8397759970/in/photostream/
我检测到了分支点和端点并标记了图像。现在我在每个分支上绘制圆圈,我使用以下代码在每个分支上绘制一个圆圈。
mn=bwmorph(y,'branchpoints');
[row column] = find(mn);
branchPts = [row column];
endImg = bwmorph(y, 'endpoints');
[row column] = find(endImg);
endPts = [row column];
figure;imshow(y);
hold on ;
plot(branchPts(:,2),branchPts(:,1),'rx');
hold on; plot(endPts(:,2),endPts(:,1),'*');
% Labeling the Branches
branches = (y & ~mn); % set branch points to zero
figure; imshow(branches);
branchesLabeled = bwlabel( branches); % label connected components
vislabels(branchesLabeled)
% Calculation of Length of Branches and Circular Neighbourhood Method for
% for detection of normal and abnormal branches.
sts = regionprops( branchesLabeled,'Area', 'Perimeter','MajorAxisLength','Centroid' );
% extract properties
% Loop for circles
for i=1:size(sts)
r= sts(i).MajorAxisLength/2 ; %desired radius
centerx = sts(i).Centroid(1);
centery = sts(i).Centroid(2);
th = 0:pi/50:2*pi;
xunit = r * cos(th) + centerx;
yunit = r * sin(th) + centery;
figure; imshow(branchesLabeled);hold on;h = plot(xunit, yunit);
end
我对此代码有几个问题。
圆圈在骨架的中心线上绘制(它不是骨架中心线的分支) http://www.flickr.com/photos/92388309@N03/8402753918/in/photostream
此代码为我提供了一些图像(每个分支一个)。我希望在同一张图片上的每个分支上都有圆圈。
我想通过使用圆形neighourhood方法(通过在每个brach上绘制圆圈并检查圆圈中有多少背景像素)来找到分支程度。
答案 0 :(得分:0)
对于问题1,您正在为sts
结构中的所有内容绘制圆圈。您需要弄清楚如何仅在sts
中获取分支位置。
对于问题2,您需要调用figure
并在循环外绘制图像。然后在循环中调用plot
绘制每个圆圈。像这样:
figure
imshow(branchesLabeled)
hold on
for i=1:size(sts)
% your other code here...
plot(xunit, yunit);
end