mattfoster (owner)

Revisions

gist: 14348 Download_button fork
public
Public Clone URL: git://gist.github.com/14348.git
Embed All Files: show embed
Matlab #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
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