function user_find_tiles_video addpath /home/wrightc/program/AFMutils figure(1) % read data from file optfile = '/home/wrightc/find/options2'; [inputpath,start,last,outputpath,outputname,conn, a,b,c,d,e,f,g] = ... textread( optfile, '%q %u %u %q %q %q %u %u %u %u %u %u %u' ); global OPTIONS; OPTIONS = [a,b,c,d,e,f,g]; % loop from start to end for n = start:last str = form(n); % load image from AFM and flatten image = showafm([inputpath{1},'.', str], 0) ; image = flatten(image, 1); image = scale(image); image = preprocess( image, (n == start) ); image = modify(zeros(size(image)),image); % distance( image, xave, yave, [outputpath{1}, conn{1}, '.', str]) imwrite( image, [outputpath{1},outputname{1}, '.', str], 'tiff' ); pause; end close all; clear; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function str = form ( in ) % convert in to a 3 digit string % ex: 5 --> '005' , 13 --> '013' , 324 --> '324' if (in < 10) str = ['00',int2str(in)]; elseif (in < 100) str = ['0',int2str(in)]; else str = int2str(in); end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function out = preprocess (image, first) global OPTIONS; % optional pre-processing if ( ~isempty(find(OPTIONS == 6)) ) image = imadjust(image); end figure(1) imagesc(image) colormap gray title 'image file' if ( ~isempty(find(OPTIONS == 1)) ) h = fspecial('gaussian', 3); image = filter2(h, image); end if ( ~isempty(find(OPTIONS == 2)) ) % option: median filter image = medfilt2(image, [3,3]); end if ( ~isempty(find(OPTIONS == 3)) ) global SELECT; if (first == true) disp( 'mark area to mask' ) SELECT = roipoly( image ); end image = SELECT .* double(image); end out = image; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function output_image = modify( input_image , raw_image ) [yy,xx] = find(input_image); output_image = input_image; figure(4) imagesc(raw_image) hold on [i,j] = find( input_image ); plot( j,i , 'b+'); hold off colormap gray truesize title 'LEFT click = create center, RIGHT click = remove center, CENTER to end' [xmax, ymax] = size(input_image); button = 1; while button ~= 2 [x,y,button] = ginput(1); x = round(x); y = round(y); if( x<0 | y<0 | x> xmax | y > ymax) break; end if button == 1 output_image(y,x) = 1; xx = [xx;x]; yy = [yy;y]; hold on plot(x,y,'g+') hold off elseif button == 3 n = findclosest(xx,yy, x,y ); output_image(yy(n),xx(n)) = 0; hold on plot(xx(n),yy(n),'ro') hold off yy(n) = 0; xx(n) = 0; % ?????????????????? this will cause problems end end hold off close(4) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function n = findclosest( x,y, x1,y1 ) xtemp = x - x1; xtemp = xtemp .* xtemp; ytemp = y - y1; ytemp = ytemp .* ytemp; temp = xtemp + ytemp; [minval,n] = min(temp);