📄 relaxation.cc
字号:
const char *help = "\progname: relaxation.cc\n\code2html: This program reads a pgm image (grayscale) and normalizes the lighting conditions according to the Gross and Brajovic algorithm (resolution with Gauss-Seidel relaxation).\n\\n\A diffusion process is applied to the input image, in order to find the luminance estimate.\n\The discretized version of the PDE describing the diffusion process is solved using\n\the Gauss-Seidel relaxation method. The input image is then divided by the luminance estimate\n\so as to find the reflectance estimate (illumination free)\n\'Gross and Brajovic [2003] - Preprocessing algorithm for Illumination Invariant Face Recognition'\n\\n\version: Torch3 vision2.0, 2004-2005\n\(c) Guillaume Heusch (heusch@idiap.ch)\n";#include "ImageGray.h"#include "DiskXFile.h"#include "CmdLine.h"#include "ipRelaxation.h"#include "ipHistoEqual.h"#include "Timer.h"using namespace Torch;int main(int argc, char **argv){ char *image_filename; char *out_filename; real lambda; bool verbose; int type; int steps; bool light; bool histo; // --------------------- COMMAND LINE ------------------------------------------------------------------------- CmdLine cmd; cmd.setBOption("write log", false); cmd.info(help); cmd.addText("\nArguments:"); cmd.addSCmdArg("image_filename", &image_filename, "input image filename"); cmd.addSCmdArg("out_filename", &out_filename, "processed image filename"); cmd.addText("\nOptions:"); cmd.addICmdOption("-steps", &steps, 20, "numbers of relaxation steps"); cmd.addBCmdOption("-verbose", &verbose, false, "verbose"); cmd.addRCmdOption("-lambda", &lambda, 1, "relative importance of the smoothness constraint"); cmd.addICmdOption("-type", &type, 1, "type of diffusion: 0 = Isotropic, 1 = Anisotropic (Weber contrast)"); cmd.addBCmdOption("-light", &light, false, "saves the light estimate image"); cmd.addBCmdOption("-histo", &histo, false, "performs histogram equalization on the result"); cmd.read(argc, argv); Timer timer; Allocator *allocator = new Allocator; // ----------------------- LOAD IMAGE -------------------------------------------------------------------------- DiskXFile *image_file = NULL; Image *image_in = NULL; image_in = new(allocator) ImageGray(); image_in->setBOption("verbose", verbose); image_file = new(allocator) DiskXFile(image_filename, "r"); image_in->loadXFile(image_file); if(verbose) { print("Image info:\n"); print(" width = %d\n", image_in->width); print(" height = %d\n", image_in->height); print(" format = %s (%d)\n", image_in->coding, image_in->n_planes); } // ---------------------- PROCESSING IMAGE MACHINE ------------------------------------------------------------ ipCore *relax = NULL; relax = new(allocator) ipRelaxation(lambda, type, steps, image_in->width, image_in->height, "gray"); relax->setBOption("verbose", verbose); relax->process(image_in); ipCore *histoEq = NULL; if (histo) { histoEq = new(allocator) ipHistoEqual(image_in->width, image_in->height, "gray"); histoEq->process(relax->seq_out); } // ----------------------- SAVE IMAGE(S) -------------------------------------------------------------------------- Image *image_out = NULL; image_out = new(allocator) ImageGray(); image_out->setBOption("verbose", verbose); if (histo) image_out->copyFrom(image_in->width, image_in->height, histoEq->seq_out->frames[0], "gray", 255); else image_out->copyFrom(image_in->width, image_in->height, relax->seq_out->frames[0], "gray", 255); image_out->updatePixmapFromData(); image_out->save(out_filename); print("time elapsed: %g\n", timer.getTime()); if (light) { image_out->copyFrom(image_in->width, image_in->height, relax->seq_out->frames[1], "gray", 255); image_out->updatePixmapFromData(); image_out->save("light_estimate.pgm"); } // ---------------------- CLEAN UP ----------------------------------------------------------------------------- delete allocator; return(0); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -