function [common,s] = identify( path, s) % [common,s] = identify(dir,name1, name2, num) % dir : directory to find necessary files in % name1 : name of first file, bw image of centers % name2 : name of second file, ascii format connections data % num : image number % common : structure of tile signatures (neighborhoods determined by % connections) % s : size of neighborhood used % % find and record neighborhoods of each tile % method: % record existance or absense of all paths from a node length [2,3]. [4,6] directions load( '-mat', path, 'conn','N', 'x','y','rotim') image = rotim; conn2 = conn(:,[2,3,5,6]); % method for choosing s? if nargin < 2 if N < 100 s = 16; elseif N < 1000 s = 36; elseif N < 10000 s = 64; else s = 216; end end common = struct( 'ID', zeros(s,0), 'count', [], 'n', [] , 'length', 0); for n = 1:N % determine neighborhood for node n tempID = zeros(s,1); switch s % improve more? case 16 for s1 = 1:4 for s2 = 1:4 n2 = conn2(n,s1); if n2 ~= 0 if conn2(n2,s2) ~= 0 tempID(4*(s1-1)+s2) = 1; end end end end case 36 for s1 = 1:6 for s2 = 1:6 n2 = conn(n,s1); if n2 ~= 0 if conn(n2,s2) ~= 0 tempID(6*(s1-1)+s2) = 1; end end end end case 64 for s1 = 1:4 for s2 = 1:4 for s3 = 1:4 n2 = conn2(n,s1); if n2 ~= 0 n3 = conn2(n2,s2); if n3 ~= 0 if conn2(n3,s3) ~= 0 tempID(16*(s1-1)+4*(s2-1)+s3) = 1; end end end end end end case 216 for s1 = 1:6 for s2 = 1:6 for s3 = 1:6 n2 = conn(n,s1); if n2 ~= 0 n3 = conn(n2,s2); if n3 ~= 0 if conn(n3,s3) ~= 0 tempID(36*(s1-1)+6*(s2-1)+s3) = 1; end end end end end end end %%--------------------%%-----------------%%---------------------%% % determine where to put this node. if common.length == 0 % add to list, bc list is empty common.ID = [common.ID, tempID]; common.count = [common.count, 1]; common.n = [common.n, n]; common.length = common.length + 1; else % repeat current ID until is same size as common temp = repmat(tempID, [1, common.length]); % compare current ID to each ID in common list temp = xor( temp, common.ID ); % sum up the results of each comparison % if sums to zero, perfect match temp = sum( temp ); % gives column of perfect match if it exists, empty otherwise temp = find ( temp == 0 ); % if a match exists, increase count if ~isempty( temp ) common.count(temp) = common.count(temp) + 1; else % add to list if matach doesnt exist common.ID = [common.ID, tempID]; common.count = [common.count, 1]; common.n = [common.n, n]; common.length = common.length + 1; end end end imagesc(image) plotconn(x,y,conn,N) hold on % plot locations of unique signatures in red for n = 1:common.length if common.count(n) == 1 a = common.n(n); plot ( x(a), y(a), 'ro'); end end hold off