% function bwim = hairpin( centers, rotim, xrange, yrange ) function hairpin(path); % bwim : 1 = normal tile, 2 = hairpined tile, 0 = background % method 1: look in region of tile, take mean/median value , cluster 2 % groups % q1 : is there a better idicator than mean/median? % average upper 1/4 of gray values % q2 : is the time tradeoff worth this better indicator? % uncomment to test without interfacing to program % function hairpin % centers = imread('/home/wrightc/find/test/test/result.091','tiff'); % centers = double(centers); % rotim = imread('/home/wrightc/find/test/rotim.091','tiff'); % % yrange = 9; % xrange = 5; load('-mat', path, 'xave','yave','N', 'xmax','ymax', 'x', 'y', 'rotim'); xrange = ceil(xave/3); yrange = ceil(yave/3); gray1 = zeros(N,1); gray2 = zeros(N,1); gray3 = zeros(N,1); for n = 1:N ylow = y(n)-yrange; yhigh = y(n)+yrange; xlow = x(n)-xrange; xhigh = x(n)+xrange; if ( ylow > 0 & xlow > 0 & yhigh < ymax & xhigh < xmax ) area = rotim( (y(n)-yrange):(y(n)+yrange), (x(n)-xrange):(x(n)+xrange) ); % mean of top 1/4 brightest values temp = sort(area(:), 'descend'); len = length(temp); r = ceil(len/2); gray3(n) = temp(1) - temp( r ); end end h = hist(gray3, 40); figure (3) plot(h) % no seperation % median % median of top 1/4 % mean of top 1/4 % seperation % mean % difference of max and min % difference in means of top1/2 and bottom 1/2 % difference of max and median *best* %%%%%%%%%%%%%%%%%%%% CLUSTERING [ind1,int1] = kmeans(gray3,2,'replicates',3); % problem with clustering : gray values are not distinct enough, continuous % spectrum of gray values makes it hard to cluster % median clusters sssssssssslightly better, because of indifference to % extreme values -- more seperable % other problem: image not sufficiently flattened if int1(1) > int1(2) hair = 1; nohair = 2; else hair = 2; nohair = 1; end % the one with the larger cluster value is the hairpin cluster hair1 = find( ind1 == hair); nohair1 = find( ind1 == nohair); figure(4) imagesc(rotim) colormap gray hold on plot(x(hair1),y(hair1), 'r+') plot(x(nohair1),y(nohair1), 'b+') for n = 1:N if ind1(n) == hair centers(y(n),x(n)) = 2; end end % correcting hairpins button =1; while button ~= 2 [xx,yy,button] = ginput(1); n = findclosest( x,y ,xx,yy); % hairpin if button == 1 ind1(n) = hair; plot(x(n),y(n), 'r+') % not hairpin elseif button == 3 ind1(n) = nohair; plot(x(n),y(n), 'b+') end end hold off hair = (ind1 == hair); save( path, 'hair', '-mat','-append');