I have a martrix A representing a 640x480 image and another matrix index_matrix which contains some indices as shown:
[1 639;
212 210;
213 208;
214 209;
215 211;
216 210;
217 211];
The first col is corresponds to the row index in martix A and the second col corresponds to the col index in matrix A, so each row in the index_matrix represents a the index of a pixel in martix A, e.g the first row in the above example of index_matrix represents the index of the pixel located in row_1 col_639. So I want to connect only the points of martix A found in the index_matrix, where each point of those points will be connected to the nearest two other points in the index_matrix. This is like building a tree or a graph between these points. Such that the edges of this graph connecting two points should be drawn on pixels having values greater than zero, so if a pixel of value equal to zero was in the edge path, this edge connecting the two points will not be constructed and the two points will not be connected. So as shown in this if pixels A, B and C's indices where in the index_matrix and A and B will be connected, B and C will be connected, while A and C will not be connected because when constructing the path of the edge will path through a zero valued pixel "circled". So I'm asking if anyone could please advise how can I do this?