1.1 diff -r 5edfbd3e7a46 -r 1204ebf9340d PTdecode/CImg-1.3.0/examples/use_greycstoration.cpp 1.2 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.3 +++ b/PTdecode/CImg-1.3.0/examples/use_greycstoration.cpp Mon Aug 03 14:09:20 2009 +0100 1.4 @@ -0,0 +1,138 @@ 1.5 +/* 1.6 + # 1.7 + # File : use_greycstoration.cpp 1.8 + # ( C++ source file ) 1.9 + # 1.10 + # Description : Example of use for the CImg plugin 'plugins/greycstoration.h'. 1.11 + # ( http://www.greyc.ensicaen.fr/~dtschump/greycstoration/ ) 1.12 + # This file is a part of the CImg Library project. 1.13 + # ( http://cimg.sourceforge.net ) 1.14 + # 1.15 + # THIS VERSION IS FOR DEVELOPERS ONLY. IT SHOWS AN EXAMPLE OF HOW THE 1.16 + # INTEGRATION OF THE GREYCSTORATION ALGORITHM CAN BE DONE IN 1.17 + # THIRD PARTIES SOFTWARES. IF YOU ARE A "USER" OF GREYCSTORATION, 1.18 + # PLEASE RATHER LOOK AT THE FILE 'greycstoration.cpp' WHICH IS THE 1.19 + # SOURCE OF THE COMPLETE COMMAND LINE GREYCSTORATION TOOL. 1.20 + # THE EXAMPLE FOCUS ON THE DENOISING ALGORITHM. FOR INPAINTING AND 1.21 + # IMAGE RESIZING, PLEASE LOOK AT THE COMPLETE GREYCSTORATION SOURCE CODE 1.22 + # (FILE 'greycstoration.cpp') 1.23 + # 1.24 + # Copyright : David Tschumperle 1.25 + # ( http://www.greyc.ensicaen.fr/~dtschump/ ) 1.26 + # 1.27 + # License : CeCILL v2.0 1.28 + # ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html ) 1.29 + # 1.30 + # This software is governed by the CeCILL license under French law and 1.31 + # abiding by the rules of distribution of free software. You can use, 1.32 + # modify and/ or redistribute the software under the terms of the CeCILL 1.33 + # license as circulated by CEA, CNRS and INRIA at the following URL 1.34 + # "http://www.cecill.info". 1.35 + # 1.36 + # As a counterpart to the access to the source code and rights to copy, 1.37 + # modify and redistribute granted by the license, users are provided only 1.38 + # with a limited warranty and the software's author, the holder of the 1.39 + # economic rights, and the successive licensors have only limited 1.40 + # liability. 1.41 + # 1.42 + # In this respect, the user's attention is drawn to the risks associated 1.43 + # with loading, using, modifying and/or developing or reproducing the 1.44 + # software by the user in light of its specific status of free software, 1.45 + # that may mean that it is complicated to manipulate, and that also 1.46 + # therefore means that it is reserved for developers and experienced 1.47 + # professionals having in-depth computer knowledge. Users are therefore 1.48 + # encouraged to load and test the software's suitability as regards their 1.49 + # requirements in conditions enabling the security of their systems and/or 1.50 + # data to be ensured and, more generally, to use and operate it in the 1.51 + # same conditions as regards security. 1.52 + # 1.53 + # The fact that you are presently reading this means that you have had 1.54 + # knowledge of the CeCILL license and that you accept its terms. 1.55 + # 1.56 +*/ 1.57 + 1.58 +// Include the CImg Library, with the GREYCstoration plugin included 1.59 +#define cimg_plugin "plugins/greycstoration.h" 1.60 +#include "CImg.h" 1.61 +using namespace cimg_library; 1.62 +#if cimg_OS!=2 1.63 +#include <pthread.h> 1.64 +#endif 1.65 + 1.66 +// The lines below is necessary when using a non-standard compiler as visualcpp6. 1.67 +#ifdef cimg_use_visualcpp6 1.68 +#define std 1.69 +#endif 1.70 +#ifdef min 1.71 +#undef min 1.72 +#undef max 1.73 +#endif 1.74 + 1.75 +#ifndef cimg_imagepath 1.76 +#define cimg_imagepath "img/" 1.77 +#endif 1.78 + 1.79 +// Main procedure 1.80 +//---------------- 1.81 +int main(int argc,char **argv) { 1.82 + 1.83 + // Read algorithm parameters from the command line 1.84 + const char *file_i = cimg_option("-i",cimg_imagepath "milla.bmp","Input file"); 1.85 + const float amplitude = cimg_option("-dt",40.0f,"Regularization strength for one iteration (>=0)"); 1.86 + const unsigned int nb_iter = cimg_option("-iter",3,"Number of regularization iterations (>0)"); 1.87 + const float sharpness = cimg_option("-p",0.8f,"Contour preservation for regularization (>=0)"); 1.88 + const float anisotropy = cimg_option("-a",0.8f,"Regularization anisotropy (0<=a<=1)"); 1.89 + const float alpha = cimg_option("-alpha",0.6f,"Noise scale(>=0)"); 1.90 + const float sigma = cimg_option("-sigma",1.1f,"Geometry regularity (>=0)"); 1.91 + const bool fast_approx = cimg_option("-fast",true,"Use fast approximation for regularization (0 or 1)"); 1.92 + const float gauss_prec = cimg_option("-prec",2.0f,"Precision of the gaussian function for regularization (>0)"); 1.93 + const float dl = cimg_option("-dl",0.8f,"Spatial integration step for regularization (0<=dl<=1)"); 1.94 + const float da = cimg_option("-da",30.0f,"Angular integration step for regulatization (0<=da<=90)"); 1.95 + const unsigned int interp = cimg_option("-interp",0,"Interpolation type (0=Nearest-neighbor, 1=Linear, 2=Runge-Kutta)"); 1.96 + const unsigned int tile = cimg_option("-tile",0,"Use tiled mode (reduce memory usage"); 1.97 + const unsigned int btile = cimg_option("-btile",4,"Size of tile overlapping regions"); 1.98 + const unsigned int threads = cimg_option("-threads",1,"Number of threads used"); 1.99 + 1.100 + // Load input image (replace 'unsigned char' by 'unsigned short' to be able to process 16-bits/pixels). 1.101 + CImg<unsigned char> img(file_i); 1.102 + 1.103 + // Create display window 1.104 + CImgDisplay disp(img,"GREYCstoration"); 1.105 + 1.106 + // Begin iteration loop 1.107 + //--------------------- 1.108 + for (unsigned int iter=0; iter<nb_iter; iter++) { 1.109 + 1.110 + // This function will start a thread running one iteration of the GREYCstoration filter. 1.111 + // It returns immediately, so you can do what you want after (update a progress bar for instance). 1.112 + img.greycstoration_run(amplitude,sharpness,anisotropy,alpha,sigma,1.0f,dl,da,gauss_prec,interp,fast_approx,tile,btile,threads); 1.113 + 1.114 + // Here, we print the overall progress percentage. 1.115 + do { 1.116 + // pr_iteration is the progress percentage for the current iteration 1.117 + const float pr_iteration = img.greycstoration_progress(); 1.118 + 1.119 + // This simply computes the global progression indice (including all iterations) 1.120 + const unsigned int pr_global = (unsigned int)((iter*100 + pr_iteration)/nb_iter); 1.121 + 1.122 + // Display progress on window title and console. 1.123 + std::fprintf(stderr,"\rProgress : %u%%\t",pr_global); 1.124 + disp.set_title("GREYCstoration (%u%%)",pr_global); 1.125 + 1.126 + // Wait a little bit 1.127 + cimg::wait(100); 1.128 + 1.129 + // If the display window is closed, stop the algorithm 1.130 + if (disp.is_closed) img.greycstoration_stop(); 1.131 + 1.132 + } while (img.greycstoration_is_running()); 1.133 + 1.134 + img.display(disp); 1.135 + } 1.136 + std::fprintf(stderr,"\rDone ! \n\n"); 1.137 + 1.138 + disp.close(); 1.139 + img.display("GREYCstoration - Result"); 1.140 + 1.141 + return 0; 1.142 +}