Contiguous - Determine a patch of contiguous points. Given a matrix of zeros and ones, where ones form 'patches' of contiguous items, find all items that belong to the same patch as item (i,j). USAGE y = Contiguous(x,i,j) x input matrix i,j starting coordinates (row first) OUTPUT Y output matrix, where for all k and l * y(k,l) = 0 if x(k,l) = 0 * y(k,l) = 1 if x(k,l) = 1 but (k,l) is not in the same patch as (i,j) * y(k,l) = 2 if x(k,l) = 1 and (k,l) is in the same patch as (i,j)
0001 %Contiguous - Determine a patch of contiguous points. 0002 % 0003 % Given a matrix of zeros and ones, where ones form 'patches' of contiguous 0004 % items, find all items that belong to the same patch as item (i,j). 0005 % 0006 % USAGE 0007 % 0008 % y = Contiguous(x,i,j) 0009 % 0010 % x input matrix 0011 % i,j starting coordinates (row first) 0012 % 0013 % OUTPUT 0014 % 0015 % Y output matrix, where for all k and l 0016 % * y(k,l) = 0 if x(k,l) = 0 0017 % * y(k,l) = 1 if x(k,l) = 1 but (k,l) is not in the same 0018 % patch as (i,j) 0019 % * y(k,l) = 2 if x(k,l) = 1 and (k,l) is in the same patch 0020 % as (i,j) 0021 0022 % Copyright (C) 2013 by Michaƫl Zugaro 0023 % 0024 % This program is free software; you can redistribute it and/or modify 0025 % it under the terms of the GNU General Public License as published by 0026 % the Free Software Foundation; either version 3 of the License, or 0027 % (at your option) any later version.