function [stain] = outlinemesh(conn, im2, p, t, lmn, verbose, xy, varargin) % predefined sets of landmark points % border landmark points (row1: corner pt number, row2: angle) % 1: 8 cornerpoints dlmp{1} = [ 1, 87, 177, 88, 25, 23, 161, 143; ... 180, 95, 0, -90, -155, 145, 35, -30 ]; % 2: 16 cornerpoints dlmp{2} = [ 1, 87, 177, 88, 14, 23, 54, 121, 161, 175, 163, 143, 111, 44, 25, 9; ... 180, 95, 0, -90, 160, 150, 130, 65, 35, 17.5, -17.5, -35, -62.5, -132.5, -155, -165 ]; % 3: 4 cornerpoints dlmp{3} = [ 1, 87, 177, 88; ... 180, 95, 0, -90 ]; % other landmark points dlmc{1} = [ 94 ]; dlmc{2} = [ 94 ]; dlmc{3} = [ 94 ]; % assign choosen one to variables lmp = dlmp{lmn}; lmc = dlmc{lmn}; % modification 06/2007: variable arguments for extending the sub-functions args_ms = {}; args_ms_no = 1; if ~isempty(varargin) i = 1; while i <= length(varargin), switch(varargin{i}), case 'meshstaining' i = i+1; args_ms{args_ms_no} = varargin{i}; args_ms_no = args_ms_no + 1; end i = i+1; end end if isempty(conn), % modification 12/2006: conn is empty, use xy dir{1} = ''; coord = xy; else if verbose > 0, fprintf('Querying and loading %s ...\n', filename); end dir = pg_query(conn,0,pg_insitus('path'),filename); if strcmp(dir{1}, 'No Data') error('Path not found'); end coord = pg_query(conn,1, pg_insitus('xy'),filename); end % moved out for consistency % fullname = strcat(rootdir,'/',dir{1},'/',filename); % im = imread(fullname); % im2 = imresize(im, 0.5); if verbose > 1 figure; subplot(2,1,1); hold on; image(im2); end if verbose > 0, fprintf('\tQuerying coordinates ...\n'); end if verbose > 0, fprintf('\tFinding ellipse ...\n'); end ell = fit_ellipse( coord(:,1), coord(:,2) ); if ( isempty(ell.a) ), error('Ellipse detection failed'); end if verbose > 0, fprintf('\tCalculating landmark points ...\n'); end % centered coordinates coord_c = [ coord(:,1) - ell.X0_in, coord(:,2) - ell.Y0_in ]; a = atan2(coord_c(:,2), coord_c(:,1)) + ell.phi; % convert angle to degrees and adjust a = a .* 180/pi + 180; c = find(a > 360); a(c) = a(c) - 360; c = find(a < 0 ); a(c) = a(c) + 360; lmp(2,:) = lmp(2,:) + 180; %pos = []; %for i = 1:length(lmp) % da = a; % if lmp(1,i) == 0, % da = abs(da - 180); % end % da = da - lmp(2,i); % [c, I] = min(da); % pos = [ pos, [ coord(I,1) coord(I,2) ]' ]; %end ar = repmat(a, 1, length(lmp)); lmpr = repmat(lmp(2,:), length(a), 1); c = find(lmp(2,:) == 360); if length(c) > 0 as = find(a < 180); ar(as,c) = ar(as,c) + 360; end mad = abs(ar - lmpr); [c,I] = min(mad, [], 1); pos = [coord(I,1) coord(I,2)]'; lm = [ lmp(1,:) lmc ]; pos = [pos, [ fix(ell.X0_in) fix(ell.Y0_in)]']; if verbose > 0, fprintf('\tAligning the mesh ...\n'); end p_embryo = alignmesh(p, t, pos, lm); if verbose > 1 [m,n] = size(t); for i=1:m plot(p_embryo(t(i,[1:n,1]),1), p_embryo(t(i,[1:n,1]),2),'-') end plot(pos(1,:), pos(2,:), 'gx') plot(coord(:,1), coord(:,2), 'r-') hold off end if verbose > 0, fprintf('\tCalculating the staining ...\n'); end stain = meshstaining(im2, p_embryo, t, 0, args_ms{:}); if verbose > 1, p_scale = [ (p(:,1) + 4) *25+100 (p(:,2)+2)*25+50 ]; subplot(2,1,2); colormap(gray); hold on; for i = 1:size(t,1) roic = fix(p_scale(t(i,:),1)'); roir = fix(p_scale(t(i,:),2)'); fill(roic,roir,stain(i)); end; hold off; end if verbose > 0, fprintf('Finished\n'); end