8#include "tpcclibConfig.h"
23static char *info[] = {
24 "Cloak a 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]",
31 " Cloak the mask in 3D (default) or 2D.",
34 "See also: maskdila, maskeros, imgmask, masksize, imgthrs",
36 "Keywords: image, mask, dilation",
65 if(img==NULL)
return(1);
67 if(dimx<1 || dimy<1 || dimz<1)
return(2);
69 for(
int z=0; z<dimz; z++) {
70 for(
int y=0; y<dimy; y++) {
71 for(
int x=0; x<dimx; x++)
if(!(img->
m[z][y][x][0]<0.5) && img->
m[z][y][x][0]!=
id) {
72 int x1=x, x2=x, y1=y, y2=y, z1=z, z2=z;
81 for(
int nz=z1; nz<=z2; nz++)
82 for(
int ny=y1; ny<=y2; ny++)
83 for(
int nx=x1; nx<=x2; nx++)
84 if(z!=nz || y!=ny || x!=nx)
85 if(img->
m[nz][ny][nx][0]<0.5)
86 img->
m[nz][ny][nx][0]=id;
100int main(
int argc,
char **argv)
102 int ai, help=0, version=0, verbose=1;
104 char maskfile[FILENAME_MAX], outfile[FILENAME_MAX];
112 if(argc==1) {
tpcPrintUsage(argv[0], info, stderr);
return(1);}
113 maskfile[0]=outfile[0]=(char)0;
115 for(ai=1; ai<argc; ai++)
if(*argv[ai]==
'-') {
116 cptr=argv[ai]+1;
if(*cptr==
'-') cptr++;
if(cptr==NULL)
continue;
118 if(strcasecmp(cptr,
"XYZ")==0) {
120 }
else if(strcasecmp(cptr,
"XY")==0) {
123 fprintf(stderr,
"Error: invalid option '%s'.\n", argv[ai]);
128 if(help==2) {
tpcHtmlUsage(argv[0], info,
"");
return(0);}
133 if(ai<argc) {
strlcpy(maskfile, argv[ai], FILENAME_MAX); ai++;}
134 if(ai<argc) {
strlcpy(outfile, argv[ai], FILENAME_MAX); ai++;}
135 if(ai<argc) {fprintf(stderr,
"Error: too many arguments.\n");
return(1);}
139 fprintf(stderr,
"Error: missing command-line argument; use option --help\n");
146 printf(
"maskfile := %s\n", maskfile);
147 if(outfile[0]) printf(
"outfile := %s\n", outfile);
148 printf(
"dim := %d\n", dim);
153 if(!outfile[0]) strcpy(outfile, maskfile);
161 if(verbose>0) {printf(
"reading %s\n", maskfile); fflush(stdout);}
164 fprintf(stderr,
"Error: %s\n", mask.
statmsg);
165 if(verbose>1) printf(
"ret := %d\n", ret);
169 fprintf(stderr,
"Error: mask cannot be dynamic image.\n");
175 fprintf(stderr,
"Warning: initial mask contains no positive voxels.\n");
179 long long pxlNr=(
long long)mask.
dimz*mask.
dimy*mask.
dimx;
181 fprintf(stderr,
"Warning: initial mask contains all positive voxels.\n");
186 printf(
"initial_nr_of_positive_voxels := %lld\n", mn);
194 if(
imgMax(&mask, &
id)!=0 ||
id<0.9) {
195 fprintf(stderr,
"Error: invalid mask ID.\n");
200 if(verbose>1) printf(
"new mask ID := %.0f\n",
id);
206 if(verbose>0) {printf(
"cloaking\n"); fflush(stdout);}
209 fprintf(stderr,
"Error: cannot cloak the mask.\n");
210 if(verbose>1) printf(
"ret := %d\n", ret);
216 fprintf(stdout,
"Cloak consists of %lld voxel.\n", mnn-mn);
223 if(verbose>2) printf(
"writing mask\n");
226 fprintf(stderr,
"Error: %s\n", mask.
statmsg);
230 if(verbose>0) printf(
"dilated 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)
int imgMax(IMG *img, float *maxvalue)
Header file for libtpcimgio.
Header file for libtpcimgp.
long long imgMaskCount(IMG *img)
int imgMaskCloak(IMG *img, int dim, float id)
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)