how to add edges to nodes using matlab code.
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/162462/image.jpeg)
i want to add edges to the every node in a image please give me some code for edge insertion
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 = 5;
h = 5;
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
%CYY(isnan(CYY)) = [];
%CXX(isnan(CXX)) = [];
end
I=I+w;
U1=U1+h;
J=1;
U2=h;
end
%kl(isnan(kl(:,1)),:) = [];
imshow(R)
hold on
hold on
plot(CYY,CXX,'.c','Markersize',8)
hold off
r = imread('empty.jpg');
re = imresize(r,[100,100]);
figure,imshow(re)
hold on
hold on
p = plot(CYY,CXX,'k*','Markersize',8);
hold off
CXX(isnan(CXX)) = [0]
CYY(isnan(CYY)) = [0]
0 Kommentare
Antworten (1)
Vidhi Agarwal
am 5 Nov. 2024
To add edges between nodes in an image, you can use the coordinates of the nodes (centroids) you have calculated and draw lines between them. This involves iterating over the node coordinates and using a function like "plot" to draw lines between each pair of nodes. Below is the sample code to implement the same.
hold on;
plot(CYY, CXX, '.c', 'Markersize', 8);
% Add edges between nodes
for i = 1:length(CXX)
for j = i+1:length(CXX)
line([CYY(i), CYY(j)], [CXX(i), CXX(j)], 'Color', 'r');
end
end
hold off;
Hope that helps!
0 Kommentare
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!