Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Matlab 如何在分支点和端点之间绘制中点_Matlab_Image Processing_Pattern Matching - Fatal编程技术网

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

Matlab 如何在分支点和端点之间绘制中点,matlab,image-processing,pattern-matching,Matlab,Image Processing,Pattern Matching,这是我的图像,我已经找到了端点和分支点,但我想在这两点之间绘制一个点,因为我将帮助我在点之间添加边。请给我一些代码来找出两点之间的中点或质心 clc; clear all; % read in a sample image -- also see letters.png, bagel.png J=imread('ds2.jpg'); % Normalize and Binarization b = imresize(J,[100,100]); th = graythresh(b); BW1 =

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

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

% 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];

 figure;imshow(skelimg);

 hold on;

 plot(branchpts(:,2),branchpts(:,1),'g*');
 plot(Endpts(:,2),Endpts(:,1),'g*');
 hold on;

bwdistoGeodesic
()可以帮助您实现这一点。你可以这样做:

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)
编辑-所有检测点之间的中心:

Allpts = [Endpts;branchpts]; % all possible points
n = size(Allpts,1);
Cntrpts = nan(n^2,2);
for ii = 1:n
    for jj = [1:(ii-1) (ii+1):n]            
        % distance from start & end points
        dEnd = bwdistgeodesic(skelimg, Allpts(ii,2), Allpts(ii,1), 'quasi-euclidean');
        dStart = bwdistgeodesic(skelimg, Allpts(jj,2), Allpts(jj,1), 'quasi-euclidean');
        D = dStart + dEnd;
        D = round(D * 8) / 8;
        D(isnan(D)) = inf;
        if all(isinf(D)) % seed points not connected
            Cntrpts(ii,:) = [nan nan];
        end
        % distance of center point (just half the distance)
        paths = imregionalmin(D);
        dCenter = bwdistgeodesic(paths, Allpts(ii,2), Allpts(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-1)*n + jj,:) = [yc,xc];
    end
end
figure;imshow(skelimg);
hold on;
plot(Cntrpts(:,2),Cntrpts(:,1),'r.')
plot(branchpts(:,2),branchpts(:,1),'g.');
plot(Endpts(:,2),Endpts(:,1),'b.');

非常感谢,如果可以在分支点或两个端点之间绘制中心,当然可以。只需将其他种子点作为参数放在定义
dEnd
dStart
的行中。请注意,两个未连接的种子点(在二进制文件
skelimg
上)将产生一个
inf
,因此中心将绘制在
(1,1)
-因为
D
将只不过是
inf
的。我添加了一段代码来计算所有检测点之间的中心。如果你只需要其中的一部分,你应该确定需要哪对点。我得到了分支、端点和中心点。有什么方法连接这些点吗??因为我想将这些点添加到结果图中,并且我想将边添加到节点中,请给我一些代码。