File: vquickmorph3d.c

package info (click to toggle)
via 1.6.0-3
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 2,480 kB
  • ctags: 2,266
  • sloc: ansic: 30,757; makefile: 101; sh: 46
file content (140 lines) | stat: -rwxr-xr-x 3,615 bytes parent folder | download | duplicates (2)
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/****************************************************************
 *
 * Copyright (C) Max Planck Institute 
 * for Human Cognitive and Brain Sciences, Leipzig
 *
 * Author Gabriele Lohmann, 2004, <lipsia@cbs.mpg.de>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 * $Id: vquickmorph3d.c 3177 2008-04-01 14:47:24Z karstenm $
 *
 *****************************************************************/

/*! \brief vquickmorph3d - 3D morphological operators using distance transforms

\par Description
3D morphological operators using distance transforms.

\par Usage

        <code>vquickmorph3d</code>

        \param -in     input image
        \param -out    output image
        \param -op     type of operation (dilate | erode | open | close). Default: dilate
        \param -radius radius of spherical structuring element. Default: 3


\par Examples
<br>
\par Known bugs
none.

\file vquickmorph3d.c
\author G.Lohmann, MPI-CBS, 2004
*/



/* From the Vista library: */
#include <viaio/Vlib.h>
#include <viaio/mu.h>
#include <via.h>
#include <viaio/option.h>

/* From the standard C libaray: */
#include <stdio.h>
#include <stdlib.h>


VDictEntry OPDict[] = {
  { "dilate", 0 },
  { "erode", 1 },
  { "open", 2 },
  { "close", 3 },
  { NULL }
};


int main (int argc, char **argv)
{
  static VDouble radius = 3.0;
  static VLong op = 0;
  static VOptionDescRec options[] = {
    { "op", VLongRepn, 1, &op, VOptionalOpt, OPDict,"type of operation" },
    { "radius", VDoubleRepn, 1, & radius, VOptionalOpt, NULL,
      "radius of structuring sphere" }
  };
  FILE *in_file, *out_file;
  VAttrList list;
  VImage src, dest=NULL;
  VAttrListPosn posn;
  char prg[50];	
  sprintf(prg,"vquickmorph3d V%s", getVersion());
  fprintf (stderr, "%s\n", prg);

  /* Parse command line arguments: */
  VParseFilterCmd (VNumber (options), options, argc, argv, &in_file, &out_file);


  /* Read source image(s): */
  if (! (list = VReadFile (in_file, NULL))) exit (1);
  fclose(in_file);


  /* Perform morphological filtering */
  for (VFirstAttr (list, & posn); VAttrExists (& posn); VNextAttr (& posn)) {
    if (VGetAttrRepn (& posn) != VImageRepn)
      continue;
    VGetAttrValue (& posn, NULL, VImageRepn, & src);

    switch (op) {
    case 0:
      dest = VDTDilate(src,NULL,radius);
      if (dest == NULL) exit (1);
      break;

    case 1:
      dest = VDTErode(src,NULL,radius);
      if (dest == NULL) exit (1);
      break;

    case 2:
      dest = VDTOpen(src,NULL,radius);
      if (dest == NULL) exit (1);
      break;

    case 3:
      dest = VDTClose(src,NULL,radius);
      if (dest == NULL) exit (1);
      break;

    default:
      ;
    }

    VSetAttrValue (& posn, NULL, VImageRepn, dest);
    VDestroyImage (src);
    break;
  }

  /* Write the results to the output file: */
  VHistory(VNumber(options),options,prg,&list,&list);
  if (VWriteFile (out_file, list))
    fprintf (stderr, "%s: done.\n",argv[0]);
  return 0;
}