int main(int argc, char **argv) { programparams Params; image f = NullImage, u = NullImage; int Status = 1; if(!ParseParams(&Params, argc, (const char **)argv)) goto Catch; /* Read the input image */ if(!ReadImageObj(&f, Params.InputFile)) goto Catch; else if(!AllocImageObj(&u, f.Width, f.Height, f.NumChannels)) { fputs("Out of memory.\n", stderr); goto Catch; } if(!TvDeconv(u, f, Params.Kernel, Params.Lambda, Params.Noise)) goto Catch; /* Write the deconvolved image */ if(!WriteImageObj(u, Params.OutputFile, Params.JpegQuality)) fprintf(stderr, "Error writing to \"%s\".\n", Params.OutputFile); Status = 0; Catch: FreeImageObj(u); FreeImageObj(f); FreeImageObj(Params.Kernel); return Status; }
/** @brief Read a matrix from a text or image file */ int ReadMatrixFromFile(image *f, const char *FileName, int (*RescaleFun)(image *f)) { char Type[8]; if(!f) return 0; /* If the file is not a known image type, attempt to read it as a text file. */ if(!IdentifyImageType(Type, FileName)) return ReadMatrixFromTextFile(f, FileName); /* The file appears to be an image type, attempt to read it. */ if(!ReadImageObjGrayscale(f, FileName)) { fprintf(stderr, "Error reading \"%s\".\n", FileName); return 0; } if(RescaleFun && !RescaleFun(f)) { FreeImageObj(*f); *f = NullImage; return 0; } return 1; }
/** * @brief Read a kernel from the command line option stirng * @param Kernel pointer to kernel image * @param String command line optionstring * @return 1 on success, 0 on failure * * The syntax of string can be "disk:<radius>" or "gaussian:<sigma>". * Otherwise, the string is assumed to be a file name. */ int ReadKernel(image *Kernel, const char *String) { if(Kernel->Data) { FreeImageObj(*Kernel); *Kernel = NullImage; } if(MakeNamedKernel(Kernel, String) || ReadMatrixFromFile(Kernel, String, KernelRescale)) return 1; else return 0; }