source: aedes_roifill.m @ 151

Last change on this file since 151 was 148, checked in by tjniskan, 9 years ago
  • Added aedes_roifill.m for doing binary flood fill operation. This is

much slower than using the imfill-function, but does not dependend on
Image Processing toolbox. The goal is to make Aedes run with just the
base Matlab install. DICOM support will probably be the last obstacle
in achieving this, because it's going to be a great pain in the a to
code...

  • Fixed overwriting ROIs in aedes_roi_copy_gui.m and added additional

information in the ROI copy button tooltips.

  • Some further iterations to the new readvnmr-function.

M aedes_roi_copy_gui.m
M aedes_getmatlabversion.m
M aedes_readvnmr.m
M aedes.m
M aedes_helpabout.m
M aedes_readfid.m
M aedes_revision.m
A aedes_roifill.m

File size: 2.3 KB
Line 
1function bw_out = aedes_roifill(bw,seed)
2% AEDES_ROIFILL - Do flood fill operation (4-conn) for binary image
3%   
4%
5% Synopsis:
6%        bw_out = aedes_roifill(bw_in,seed);
7%
8% Description:
9%       Flood fill operation (4-connected) for binary 2D images.
10%
11% Examples:
12%
13% See also:
14%       AEDES
15
16% This function is a part of Aedes - A graphical tool for analyzing
17% medical images
18%
19% Copyright (C) 2006 Juha-Pekka Niskanen <Juha-Pekka.Niskanen@uku.fi>
20%
21% Department of Physics, Department of Neurobiology
22% University of Kuopio, FINLAND
23%
24% This program may be used under the terms of the GNU General Public
25% License version 2.0 as published by the Free Software Foundation
26% and appearing in the file LICENSE.TXT included in the packaging of
27% this program.
28%
29% This program is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
30% WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
31
32% Flood fill algorithm to be used
33method = 1;
34
35% matrix of linear indices
36sz = size(bw);
37bw = ~bw; % Image complement
38lind = reshape(1:prod(sz),sz(1),sz(2));
39
40% Matrix of row and column indices
41[xind,yind] = ndgrid(1:sz(1),1:sz(2));
42
43switch method
44  case 1
45    % This is the simplest and slowest flood fill method...
46    Q = [];
47    bw_out = false(size(bw));
48    if ~bw(lind(seed(1),seed(2)))
49      return
50    end
51    Q(end+1) = lind(seed(1),seed(2));
52    while ~isempty(Q)
53      n = Q(1);
54      ni = [xind(n) yind(n)];
55      if bw(n)
56        bw_out(n) = true;
57      end
58      Q=Q(2:end);
59      %Q(1)=[];
60     
61      % Go west
62      if ni(2)~=1
63        nn = lind(ni(1),ni(2)-1);
64        if bw(nn) && ~bw_out(nn)
65          bw_out(nn) = true;
66          Q(end+1) = nn;
67        end
68      end
69     
70       % Go east
71      if ni(2)~=sz(2)
72        nn = lind(ni(1),ni(2)+1);
73        if bw(nn) && ~bw_out(nn)
74          bw_out(nn) = true;
75          Q(end+1) = nn;
76        end
77      end
78     
79       % Go south
80      if ni(1)~=sz(1)
81        nn = lind(ni(1)+1,ni(2));
82        if bw(nn) && ~bw_out(nn)
83          bw_out(nn) = true;
84          Q(end+1) = nn;
85        end
86      end
87     
88       % Go north
89      if ni(1)~=1
90        nn = lind(ni(1)-1,ni(2));
91        if bw(nn) && ~bw_out(nn)
92          bw_out(nn) = true;
93          Q(end+1) = nn;
94        end
95      end
96     
97     
98    end
99   
100  case 2
101    % To be written...
102   
103end
104
105bw_out = ~bw | bw_out;
Note: See TracBrowser for help on using the repository browser.

Powered by Trac 1.0.9.Copyright © Juha-Pekka Niskanen 2008