48 static int ParseParams(
programparams *Param,
int argc,
char *argv[]);
54 printf(
"Zhang-Wu LMMSE demosaicing demo, P. Getreuer 2010-2011\n\n");
55 printf(
"Usage: dmzhangwu [options] <input file> <output file>\n\n"
58 printf(
" -p <pattern> CFA pattern, choices for <pattern> are\n");
59 printf(
" RGGB upperleftmost red pixel is at (0,0)\n");
60 printf(
" GRBG upperleftmost red pixel is at (1,0)\n");
61 printf(
" GBRG upperleftmost red pixel is at (0,1)\n");
62 printf(
" BGGR upperleftmost red pixel is at (1,1)\n");
63 printf(
" -e <estimate> Estimation of the local signal mean, choices for\n");
64 printf(
" <estimate> are\n");
65 printf(
" paper as in Zhang and Wu's paper (default)\n");
66 printf(
" zhangcode as in Zhang's MATLAB code\n");
68 printf(
" -q <number> Quality for saving JPEG images (0 to 100)\n\n");
71 " dmzhangwu -p RGGB frog.bmp frog-dm.bmp\n");
75 int main(
int argc,
char *argv[])
78 float *Input = NULL, *Output = NULL;
79 int Width, Height, Status = 1;
82 if(!ParseParams(&Param, argc, argv))
86 if(!(Input = (
float *)
ReadImage(&Width, &Height,
90 if(Width < 4 || Height < 4)
92 ErrorMessage(
"Image is too small (%dx%d).\n", Width, Height);
96 if(!(Output = (
float *)
Malloc(
sizeof(
float)*3*
97 ((
long int)Width)*((
long int)Height))))
121 static int ParseParams(
programparams *Param,
int argc,
char *argv[])
123 static char *DefaultOutputFile = (
char *)
"out.bmp";
143 for(i = 1; i < argc;)
145 if(argv[i] && argv[i][0] ==
'-')
147 if((OptionChar = argv[i][1]) == 0)
149 printf(
"Invalid parameter format.\n");
154 OptionString = &argv[i][2];
156 OptionString = argv[i];
159 printf(
"Invalid parameter format.\n");
166 if(!strcmp(OptionString,
"RGGB")
167 || !strcmp(OptionString,
"rggb"))
172 else if(!strcmp(OptionString,
"GRBG")
173 || !strcmp(OptionString,
"grbg"))
178 else if(!strcmp(OptionString,
"GBRG")
179 || !strcmp(OptionString,
"gbrg"))
184 else if(!strcmp(OptionString,
"BGGR")
185 || !strcmp(OptionString,
"bggr"))
191 printf(
"CFA pattern must be RGGB, GRBG, GBRG, or BGGR.\n");
194 if(!strcmp(OptionString,
"paper"))
196 else if(!strcmp(OptionString,
"zhangcode"))
199 printf(
"Estimation must be paper or zhangcode.\n");
207 printf(
"JPEG quality must be between 0 and 100.\n");
216 if(isprint(OptionChar))
217 printf(
"Unknown option \"-%c\".\n", OptionChar);
219 printf(
"Unknown option.\n");