8#include "tpcclibConfig.h"
23static char *info[] = {
24 "Erode mask image in ECAT 6.3 or 7.x, NIfTI-1, or Analyze 7.5 format.",
25 "Original mask image file is overwritten if name for new file is not given.",
27 "Usage: @P [Options] maskfile [newmaskfile]",
30 " -struct=<<cube>|<rcube>|<star>>",
31 " Select the structuring element for erosion; either 3x3x3 cube (default),",
32 " rounded cube (3x3x3 cube without corners), or star (cube on its corner,",
33 " consisting of 7 voxels).",
36 "See also: maskdila, imgmask, imgthrs, imgmax, imgbox",
38 "Keywords: image, mask, erosion, threshold",
57int main(
int argc,
char **argv)
59 int ai, help=0, version=0, verbose=1;
61 char maskfile[FILENAME_MAX], outfile[FILENAME_MAX];
62 int structuring_element=1;
70 if(argc==1) {
tpcPrintUsage(argv[0], info, stderr);
return(1);}
71 maskfile[0]=outfile[0]=(char)0;
73 for(ai=1; ai<argc; ai++)
if(*argv[ai]==
'-') {
74 cptr=argv[ai]+1;
if(*cptr==
'-') cptr++;
if(cptr==NULL)
continue;
76 if(strncasecmp(cptr,
"STRUCT=", 7)==0) {
78 if(strncasecmp(cptr,
"CUBE", 1)==0) {structuring_element=1;
continue;}
79 if(strncasecmp(cptr,
"RCUBE", 1)==0) {structuring_element=2;
continue;}
80 if(strncasecmp(cptr,
"STAR", 1)==0) {structuring_element=3;
continue;}
82 fprintf(stderr,
"Error: invalid option '%s'.\n", argv[ai]);
87 if(help==2) {
tpcHtmlUsage(argv[0], info,
"");
return(0);}
92 if(ai<argc) {
strlcpy(maskfile, argv[ai], FILENAME_MAX); ai++;}
93 if(ai<argc) {
strlcpy(outfile, argv[ai], FILENAME_MAX); ai++;}
94 if(ai<argc) {fprintf(stderr,
"Error: too many arguments.\n");
return(1);}
98 fprintf(stderr,
"Error: missing command-line argument; use option --help\n");
105 printf(
"maskfile := %s\n", maskfile);
106 if(outfile[0]) printf(
"outfile := %s\n", outfile);
107 printf(
"structuring_element := %d\n", structuring_element);
112 if(!outfile[0]) strcpy(outfile, maskfile);
120 if(verbose>0) {printf(
"reading %s\n", maskfile); fflush(stdout);}
123 fprintf(stderr,
"Error: %s\n", mask.
statmsg);
124 if(verbose>1) printf(
"ret := %d\n", ret);
128 fprintf(stderr,
"Error: mask cannot be dynamic image.\n");
134 fprintf(stderr,
"Warning: initial mask contains no positive voxels.\n");
139 printf(
"initial_nr_of_positive_voxels := %u\n", mn);
150 fprintf(stderr,
"Error: cannot make structuring element.\n");
159 if(verbose>0) {printf(
"eroding\n"); fflush(stdout);}
162 fprintf(stderr,
"Error: cannot erode the mask.\n");
163 if(verbose>1) printf(
"ret := %d\n", -ret);
168 fprintf(stdout,
"No voxels eroded.\n");
173 fprintf(stdout,
"%d mask voxel(s) eroded.\n", ret);
179 fprintf(stderr,
"Warning: all voxels eroded; empty mask not saved.\n");
184 printf(
"nr_of_positive_voxels := %u\n", mn);
192 if(verbose>2) printf(
"writing mask\n");
195 fprintf(stderr,
"Error: %s\n", mask.
statmsg);
199 if(verbose>0) printf(
"eroded mask written in %s.\n\n", outfile);
void imgEmpty(IMG *image)
int imgRead(const char *fname, IMG *img)
int imgWrite(const char *fname, IMG *img)
Header file for libtpcimgio.
Header file for libtpcimgp.
long long imgMaskCount(IMG *img)
int imgStructuringElement(IMG *img, const int structuring_element, int verbose)
int imgMaskErode(IMG *img, IMG *se)
Header file for libtpcmisc.
int tpcProcessStdOptions(const char *s, int *print_usage, int *print_version, int *verbose_level)
size_t strlcpy(char *dst, const char *src, size_t dstsize)
int tpcHtmlUsage(const char *program, char *text[], const char *path)
void tpcPrintBuild(const char *program, FILE *fp)
void tpcPrintUsage(const char *program, char *text[], FILE *fp)