如何在分支点和终点之间绘制中点

时间:2017-03-26 09:42:56

标签: matlab image-processing pattern-matching

这是我的图像我已经找到了终点和分支点,但我想在这两点之间绘制一个点,因为我将帮助我在点之间添加边。请给我一些代码来找到两点之间的中点或质心。

Ref55465

reference image

1 个答案:

答案 0 :(得分:0)

choices = ['INT', 'US', 'UK', 'China'] print('\n'.join('{}) {}'.format(i+1, choice) for i, choice in enumerate(choices))) tries = 0 while tries < 3: geo = raw_input('Please choose the Geography:') if not (geo and geo.isdigit() and 1 <= int(geo) <= len(choices)): print('Error: Provide proper input and tool terminated. Please re Run the tool ') tries += 1 else: break helpful link)可以帮助您。你可以这样做:

bwdistgeodesic

编辑 - 所有检测点之间的中心:

clc;
clear all;
% read in a sample image -- also see letters.png, bagel.png
J=im2double(imread('circles.png'));

% Normalize and Binarization
b = imresize(J,[100,100]);
th = graythresh(b);
BW1 = im2bw(b, th);
figure;
imshowpair(b, BW1, 'montage');

% the standard skeletonization:
skelimg = bwmorph(BW1,'thin',inf);

mn = bwmorph(skelimg,'branchpoints');
[row, column] = find(mn);
branchpts = [row column];


Endimg = bwmorph(skelimg,'endpoints');
[row,column] = find(Endimg);
Endpts = [row column];

n = size(Endpts,1);
Cntrpts = zeros(n,2);
for ii = 1:n
    % compute end & branch points geodesic distance transform
    dEnd = bwdistgeodesic(skelimg, Endpts(ii,2), Endpts(ii,1), 'quasi-euclidean');
    [~,closestBranchIdx] = min(dEnd(mn));
    dStart = bwdistgeodesic(skelimg, branchpts(closestBranchIdx,2), branchpts(closestBranchIdx,1), 'quasi-euclidean');
    D = dStart + dEnd;
    D = round(D * 8) / 8;
    D(isnan(D)) = inf;
    paths = imregionalmin(D);
    % compute geodesic distance on found path from end point and divide max distance by 2 for center point
    dCenter = bwdistgeodesic(paths, Endpts(ii,2), Endpts(ii,1), 'quasi-euclidean');
    dCenter(isinf(dCenter)) = nan;
    c = nanmax(dCenter(:)) / 2;
    [~,idx] = nanmin(abs(dCenter(:) - c));
    [yc,xc] = ind2sub(size(dCenter),idx);
    Cntrpts(ii,:) = [yc,xc];
end

figure;imshow(skelimg);
hold on;
plot(Cntrpts(:,2),Cntrpts(:,1),'ro')

plot(branchpts(:,2),branchpts(:,1),'g.');
plot(Endpts(:,2),Endpts(:,1),'b.');
hold on;
disp(B)