No BSD License  

ConnectFunc

by

 

A function connecting two points in an image with a line of ones.

newout=ConnectFunc(binimg,row1,col1,row2,col2)
function newout=ConnectFunc(binimg,row1,col1,row2,col2)
%=======================================================
% CONNECTFUNC Connects two pixels in a binary image with string of 1's
%		NEWOUT = CONNECTFUNC(BINIMG,ROW1,COL1,ROW2,COL2)	first looks
%		for diagonal routes to connect the pixels and once is the same
%		row or column, it will continue draw a straight line in that column.
%
%	Class Support
%	-------------
%	This function should work on all images, but has been only tested on binary
%	images.
%
%	Example
%  -------
%
%	matr = zeros(10);
%	matr([1 7],[3 9])=2;
%  newmat = ConnectFunc(matr,1,3,7,9)
%	newmat =
%
%     0     0     1     0     0     0     0     0     1     0
%     0     0     0     1     0     0     0     0     0     0
%     0     0     0     0     1     0     0     0     0     0
%     0     0     0     0     0     1     0     0     0     0
%     0     0     0     0     0     0     1     0     0     0
%     0     0     0     0     0     0     0     1     0     0
%     0     0     1     0     0     0     0     0     1     0
%     0     0     0     0     0     0     0     0     0     0
%     0     0     0     0     0     0     0     0     0     0
%     0     0     0     0     0     0     0     0     0     0
%
% Paul L. Nuschke 1-20-2000
% NuschkePL@npt.nuwc.navy.mil
% Version 1.0

while row1<row2 & col1<col2
   row1=row1+1;
   col1=col1+1;
   binimg(row1,col1)=1;
end
while row1<row2 & col2<col1
   row1=row1+1;
   col1=col1-1;
   binimg(row1,col1)=1;
end
while row2<row1 & col2<col1
   row1=row1-1;
   col1=col1-1;
   binimg(row1,col1)=1;
end
while row2<row1 & col1<col2
   row1=row1-1;
   col1=col1+1;
   binimg(row1,col1)=1;
end
while row1<row2
   row1=row1+1;
   binimg(row1,col1)=1;
end
while row2<row1
   row1=row1-1;
   binimg(row1,col1)=1;
end
while col1<col2
   col1=col1+1;
   binimg(row1,col1)=1;
end
while col2<col1
   col1=col1-1;
   binimg(row1,col1)=1;
end

newout=binimg;
return;

Contact us