File: thinbinvol.m

package info (click to toggle)
octave-iso2mesh 1.9.8%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 11,128 kB
  • sloc: cpp: 11,982; ansic: 10,158; sh: 365; makefile: 59
file content (49 lines) | stat: -rw-r--r-- 1,212 bytes parent folder | download
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
function vol = thinbinvol(vol, layer, nobd)
%
% vol=thinbinvol(vol,layer,nobd)
%
% thinning a binary volume by a given pixel width
% this is similar to bwmorph(vol,'thin',n) except
% this does it in 3d and only run thinning for
% non-zero elements (and hopefully faster)
%
% author: Qianqian Fang, <q.fang at neu.edu>
%
% input:
%     vol: a volumetric binary image
%     layer: number of iterations for the thickenining
%     nobd: (optional) if set to 1, boundaries will not
%            erode. if not given, nobd=0.
%
% output:
%     vol: the volume image after the thinning operations
%
% -- this function is part of iso2mesh toolbox (http://iso2mesh.sf.net)
%

dim = size(vol);
dxy = dim(1) * dim(2);
fulllen = prod(dim);

if (nargin < 3)
    nobd = 0;
end

if (nobd == 1)
    bdmask = vol;
    if (ndims(vol) == 2)
        bdmask(2:end - 1, 2:end - 1) = 0;
    elseif (ndims(vol) == 3)
        bdmask(2:end - 1, 2:end - 1, 2:end - 1) = 0;
    end
end

for i = 1:layer
    idx = find(~vol);
    idxnew = [idx + 1; idx - 1; idx + dim(1); idx - dim(1); idx + dxy; idx - dxy];
    idxnew = idxnew(find(idxnew > 0 & idxnew < fulllen));
    vol(idxnew) = 0;
    if (nobd)
        vol = vol | bdmask;
    end
end