如何使用最小生成树方法将边连接到图像中的节点 [英] how to connect edges to nodes in a image using minimum spanning tree approach
问题描述
我在手写图像中进行图形匹配的项目,我想用图表表示给定的单词图像,使用下面的算法
I am doing my project on graph matching in hand written image, i want to represent a given word image in graph, am using the below algorithm
Algorithm:
input: Binary image B, Grid width w, Grid height h
Output: Graph g = (V, E) with nodes V and edges E
1: function Grid(B,w,h)
2: for i ← 1 to number of columns C = Width of B/w do
3: for j ← 1 to number of rows R = Height of B/h do
4: V = V ∪ {(xm, ym) | (xm, ym) is the centre of mass of segment sij}
5: for Each pair of nodes (u, v) ∈ V × V do
6: E = E ∪ (u, v) if associated segments are connected by NNA, MST, or DEL
7: return g
am已经找到质量中心使用这个绘制点之后绘制点我不知道如何使用最小生成树approch添加边缘
am already find the center of mass using this am plotting the points after plotting the points i do not know how to add the edges to using minimum spanning tree approch
这个我的代码
clc;
clear all;
close all;
X=imread('i2.jpg');
imfinfo('i2.jpg')
figure,imshow(X)
b = imresize(X,[100,100]);
si = size(b,1);
sj = size(b,2);
figure;imshow(b);
% Binarization
th = graythresh(b);
I = im2bw(b,th);
w = 10;
h = 10;
c=si/w;
r=sj/h;
kl=bwmorph(~I,'thin',inf);
figure,imshow(kl)
R(:,:)=kl(:,:);
I=1;
U1=w;
J=1;
U2=h;
E=1;
for i=1:r
for j=1:c
B(I:U1,J:U2)=R(I:U1,J:U2);
[x,y]=find(B==1);
CX=mean(x);
CY=mean(y);
CXX(E)=CX
CYY(E)=CY
T(I:U1,J:U2)=B(I:U1,J:U2);
J=J+w;
U2=U2+h;
E=E+1;
clear B x y
end
I=I+w;
U1=U1+h;
J=1;
U2=h;
end
imshow(R)
hold on
hold on
plot(CYY,CXX,'.c')
hold off
% CXX(isnan(CXX)) = [];
% CYY(isnan(CYY)) = [];
r = imread('empty.jpg');
n = imresize(r,[100,100]);
figure,imshow(n);
hold on
hold on
plot(CYY,CXX,'.k')
hold off
我正在使用 CXX
和 CYY
值进行绘图我不知道如何使用最小生成树方法请给我一些代码,它将帮助我完成我的项目
am plotting using the CXX
and CYY
values i do not know how to add the edges to plotted points using minimum spanning tree approach please give me some code it will help me to complete my project
推荐答案
很难从你的问题中得知,但是我假设你要表示一个图表,其中所有节点都在坐标 [CXX,CYY]
,权重矩阵是节点之间的距离 i
和节点 j
Hard to tell from your question, but I'm assuming you want to represent a graph where all nodes are at coordinates [CXX,CYY]
and the weight matrix is the distance between node i
and node j
您可以使用 pdist2()
A = pdist2([CXX,CYY],[CXX,CYY]);
构建基于 A
的图表(请注意,此图表不包含有关原始位置的信息,只有距离)
G = graph(A,...);
确定 G
Determine the MST for G
T = minspantree(G);
T.Edges
将是一个表格MST中包含的节点 i
和 k
,以及它们的距离权重。你可以使用图形函数来显示它,虽然它只会影响距离向量,而不是原始坐标位置
T.Edges
will be a table of nodes i
and k
that are included in the MST, as well as their distance weight. You can use graph functions to visualize this, although it will only factor distance vectors, not original coordinate locations
这篇关于如何使用最小生成树方法将边连接到图像中的节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!