29 #define DEFAULT_ALPHA 1.8
30 #define DEFAULT_EPSILON 0.15
31 #define DEFAULT_SIGMA 0.6
32 #define DEFAULT_TOL 0.001
33 #define DEFAULT_MAXITER 250
69 static int ParseParams(
programparams *Param,
int argc,
char *argv[]);
75 printf(
"Contour stencils weighted L1 demosaicing demo, P. Getreuer 2010-2011\n\n");
76 printf(
"Usage: dmcswl1 [options] <input file> <output file>\n\n"
79 printf(
" -p <pattern> CFA pattern, choices for <pattern> are\n");
80 printf(
" RGGB upperleftmost red pixel is at (0,0)\n");
81 printf(
" GRBG upperleftmost red pixel is at (1,0)\n");
82 printf(
" GBRG upperleftmost red pixel is at (0,1)\n");
83 printf(
" BGGR upperleftmost red pixel is at (1,1)\n\n");
84 printf(
" -s Show estimated contours instead of demosaicing.\n"
85 " The output is written as an EPS file.\n");
86 printf(
" -E Display energy value after each iteration.\n\n");
87 printf(
" -a <number> alpha, chroma weight (default 1.8)\n");
88 printf(
" -e <number> epsilon, graph weight (default 0.15)\n");
89 printf(
" -f <number> sigma, graph spatial filtering parameter (default 0.6)\n");
90 printf(
" -t <number> convergence tolerance (default 0.001)\n");
91 printf(
" -m <number> maximum number of iterations (default 250)\n\n");
93 printf(
" -q <number> Quality for saving JPEG images (0 to 100)\n\n");
96 " dmcswl1 -p RGGB frog.bmp frog-dm.bmp\n"
97 " dmcswl1 -p RGGB -s frog.bmp frog-contours.eps\n");
101 int main(
int argc,
char *argv[])
105 int Width, Height, Status = 1;
107 if(!ParseParams(&Param, argc, argv))
111 if(!(Image = (
float *)
ReadImage(&Width, &Height,
112 Param.
InputFile, IMAGEIO_FLOAT | IMAGEIO_RGB | IMAGEIO_PLANAR)))
115 if(Width < 4 || Height < 4)
117 ErrorMessage(
"Image is too small (%dx%d).\n", Width, Height);
128 printf(
"Output written to \"%s\".\n", Param.
OutputFile);
144 IMAGEIO_FLOAT | IMAGEIO_RGB | IMAGEIO_PLANAR, Param.
JpegQuality))
151 printf(
"Output written to \"%s\".\n", Param.
OutputFile);
163 static int ParseParams(
programparams *Param,
int argc,
char *argv[])
165 static char *DefaultOutputFile = (
char *)
"out.bmp";
190 for(i = 1; i < argc;)
192 if(argv[i] && argv[i][0] ==
'-')
194 if((OptionChar = argv[i][1]) == 0)
201 OptionString = &argv[i][2];
203 OptionString = argv[i];
213 if(!strcmp(OptionString,
"RGGB")
214 || !strcmp(OptionString,
"rggb"))
219 else if(!strcmp(OptionString,
"GRBG")
220 || !strcmp(OptionString,
"grbg"))
225 else if(!strcmp(OptionString,
"GBRG")
226 || !strcmp(OptionString,
"gbrg"))
231 else if(!strcmp(OptionString,
"BGGR")
232 || !strcmp(OptionString,
"bggr"))
238 ErrorMessage(
"CFA pattern must be RGGB, GRBG, GBRG, or BGGR\n");
249 Param->
Alpha = (float)atof(OptionString);
251 if(Param->
Alpha <= 0)
258 Param->
Epsilon = (float)atof(OptionString);
267 Param->
Sigma = (float)atof(OptionString);
276 Param->
Tol = (float)atof(OptionString);
280 ErrorMessage(
"Convergence tolerance must be positive.\n");
285 Param->
MaxIter = atoi(OptionString);
289 ErrorMessage(
"Maximum number of iterations must be nonnegative.\n");
300 ErrorMessage(
"JPEG quality must be between 0 and 100.\n");
309 if(isprint(OptionChar))