Skip to content

Instantly share code, notes, and snippets.

@mattfoster
Created October 2, 2008 13:09
Show Gist options
  • Save mattfoster/14348 to your computer and use it in GitHub Desktop.
Save mattfoster/14348 to your computer and use it in GitHub Desktop.
function [seg] = im_to_snake(mov, seg, in_im_us)
flag_thresh = 0.15;
its = 5;
% Default is to _not_ create an avi
if nargin < 1
mov = 0;
end
% load mat file
% load_tec_mat
if nargin < 2
load data/images.mat
% get edges
% edges = e_edge(in_im_us);
% segment
seg = morpho_segment(in_im_us);
end
if mov
aviobj = setup_aviobj('contrast', 2);
end
for ii = 1:size(in_im_us, 3)
map = colormap(jet(256));
image(uint8(in_im_us(:,:,ii)));
axis xy
axis off
axis tight
axis off
set(gca, 'position', [0.01 0.01 0.99 0.99]);
hold on
for jj = 1:numel(seg(ii).blob)
% plot_blob(sample_chain(seg(ii).blob(jj).chain), 'k-');
plot( [seg(ii).blob(jj).chain(:,2); seg(ii).blob(jj).chain(1,2)], ...
[seg(ii).blob(jj).chain(:,1); seg(ii).blob(jj).chain(1,1)], 'k-');
end
if mov
aviobj = append_frame(gcf, aviobj);
end
end % images
if mov
aviobj = teardown_aviobj(aviobj);
end
end % im_to_snake
function aviobj = append_frame(ax, aviobj)
F = getframe(ax);
aviobj = addframe(aviobj,F);
end
function aviobj = setup_aviobj(fname, fps)
aviobj = avifile(fname);
aviobj.compression = 'None'
aviobj.fps = fps;
end
function aviobj = teardown_aviobj(aviobj)
aviobj = close(aviobj)
end
function plot_blob(points, linespec)
points = points';
% Plot the snake using cubic splines to interpolate.
fnplt(csape(1:size(points,2)+1, [points([2,1],:), points([2,1],1)], 'periodic', 'second'), linespec);
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment