compConn : calculates the connectivity of each pixel INPUT : imInput : input image conn : values accepted are 4 and 8 4 two-dimensional four-connected neighborhood 8 two-dimensional eight-connected neighborhood (default) OUTPUT : im : output image Copyright (C) 2016 Wiggins Lab Written by Stella Stylianidou, Paul Wiggins. University of Washington, 2016 This file is part of SuperSegger. SuperSegger is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. SuperSegger is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with SuperSegger. If not, see <http://www.gnu.org/licenses/>.
0001 function im = compConn( imInput, conn ) 0002 % compConn : calculates the connectivity of each pixel 0003 % 0004 % INPUT : 0005 % imInput : input image 0006 % conn : values accepted are 4 and 8 0007 % 4 two-dimensional four-connected neighborhood 0008 % 8 two-dimensional eight-connected neighborhood (default) 0009 % OUTPUT : 0010 % im : output image 0011 % 0012 % Copyright (C) 2016 Wiggins Lab 0013 % Written by Stella Stylianidou, Paul Wiggins. 0014 % University of Washington, 2016 0015 % This file is part of SuperSegger. 0016 % 0017 % SuperSegger is free software: you can redistribute it and/or modify 0018 % it under the terms of the GNU General Public License as published by 0019 % the Free Software Foundation, either version 3 of the License, or 0020 % (at your option) any later version. 0021 % 0022 % SuperSegger is distributed in the hope that it will be useful, 0023 % but WITHOUT ANY WARRANTY; without even the implied warranty of 0024 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0025 % GNU General Public License for more details. 0026 % 0027 % You should have received a copy of the GNU General Public License 0028 % along with SuperSegger. If not, see <http://www.gnu.org/licenses/>. 0029 0030 0031 if ~exist( 'conn' ); 0032 conn = 8; 0033 end 0034 0035 im = uint8(imInput>0); 0036 ss = size(im); 0037 imPadded = zeros(2+ss(1),2+ss(2)); 0038 imPadded(2:ss(1)+1,2:ss(2)+1) = im; 0039 0040 if conn == 8 0041 im = (imPadded(1:ss(1),1:ss(2)) + imPadded(2:ss(1)+1,1:ss(2)) + imPadded(3:ss(1)+2,1:ss(2))... 0042 +imPadded(1:ss(1),2:ss(2)+1) + imPadded(3:ss(1)+2,2:ss(2)+1)... 0043 +imPadded(1:ss(1),3:ss(2)+2) + imPadded(2:ss(1)+1,3:ss(2)+2) + imPadded(3:ss(1)+2,3:ss(2)+2) ); 0044 elseif conn == 4; 0045 im = (imPadded(2:ss(1)+1,1:ss(2))... 0046 +imPadded(1:ss(1),2:ss(2)+1) + imPadded(3:ss(1)+2,2:ss(2)+1)... 0047 +imPadded(2:ss(1)+1,3:ss(2)+2)); 0048 else 0049 disp('error in function CompConn') 0050 end 0051 0052 im = double(im).*double(imInput); 0053 0054 0055 end 0056