1.1 diff -r 5edfbd3e7a46 -r 1204ebf9340d PTdecode/CImg-1.3.0/examples/pde_heatflow2d.cpp 1.2 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.3 +++ b/PTdecode/CImg-1.3.0/examples/pde_heatflow2d.cpp Mon Aug 03 14:09:20 2009 +0100 1.4 @@ -0,0 +1,113 @@ 1.5 +/* 1.6 + # 1.7 + # File : pde_heatflow2D.cpp 1.8 + # ( C++ source file ) 1.9 + # 1.10 + # Description : A simple Heat flow on 2D images. 1.11 + # This file is a part of the CImg Library project. 1.12 + # ( http://cimg.sourceforge.net ) 1.13 + # 1.14 + # Copyright : David Tschumperle 1.15 + # ( http://www.greyc.ensicaen.fr/~dtschump/ ) 1.16 + # 1.17 + # License : CeCILL v2.0 1.18 + # ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html ) 1.19 + # 1.20 + # This software is governed by the CeCILL license under French law and 1.21 + # abiding by the rules of distribution of free software. You can use, 1.22 + # modify and/ or redistribute the software under the terms of the CeCILL 1.23 + # license as circulated by CEA, CNRS and INRIA at the following URL 1.24 + # "http://www.cecill.info". 1.25 + # 1.26 + # As a counterpart to the access to the source code and rights to copy, 1.27 + # modify and redistribute granted by the license, users are provided only 1.28 + # with a limited warranty and the software's author, the holder of the 1.29 + # economic rights, and the successive licensors have only limited 1.30 + # liability. 1.31 + # 1.32 + # In this respect, the user's attention is drawn to the risks associated 1.33 + # with loading, using, modifying and/or developing or reproducing the 1.34 + # software by the user in light of its specific status of free software, 1.35 + # that may mean that it is complicated to manipulate, and that also 1.36 + # therefore means that it is reserved for developers and experienced 1.37 + # professionals having in-depth computer knowledge. Users are therefore 1.38 + # encouraged to load and test the software's suitability as regards their 1.39 + # requirements in conditions enabling the security of their systems and/or 1.40 + # data to be ensured and, more generally, to use and operate it in the 1.41 + # same conditions as regards security. 1.42 + # 1.43 + # The fact that you are presently reading this means that you have had 1.44 + # knowledge of the CeCILL license and that you accept its terms. 1.45 + # 1.46 +*/ 1.47 + 1.48 +// Include library header file 1.49 +#include "CImg.h" 1.50 + 1.51 +// Make a simpler namespace alias if one wants to avoid 'using namespace cimg_library' 1.52 +namespace cil = cimg_library; 1.53 + 1.54 +#ifndef cimg_imagepath 1.55 +#define cimg_imagepath "img/" 1.56 +#endif 1.57 + 1.58 +//--------------------- 1.59 +// Begin main procedure 1.60 +//--------------------- 1.61 +int main(int argc,char **argv) { 1.62 + 1.63 + // Read command line arguments, and init images and displays 1.64 + //----------------------------------------------------------- 1.65 + cimg_usage("Perform a simple Heat Flow on 2D images"); 1.66 + cil::CImg<> img(cimg_option("-i",cimg_imagepath "milla.bmp","Input image")), veloc(img); 1.67 + const double dt = cimg_option("-dt",3.0,"Adapting time step"); 1.68 + img. 1.69 + noise(cimg_option("-ng",0.0,"Add gaussian noise"),0). 1.70 + noise(cimg_option("-nu",0.0,"Add uniform noise"),1). 1.71 + noise(cimg_option("-ns",0.0,"Add Salt&Pepper noise"),2); 1.72 + cil::CImgDisplay profile(400,300,"Intensity Profile",0,false,true), disp(img,"Heat flow 2D",0,false,true); 1.73 + disp.move((cil::CImgDisplay::screen_dimx()-disp.dimx()-profile.dimx())/2, 1.74 + (cil::CImgDisplay::screen_dimy()-disp.dimy())/2); 1.75 + 1.76 + profile.move(disp.window_x + 8 + disp.window_width, disp.window_y); 1.77 + CImg_3x3(I,float); 1.78 + float white[] = { 255,255,255 }; 1.79 + bool run_PDE = true; 1.80 + 1.81 + // Begin PDE iteration loop 1.82 + //------------------------- 1.83 + for (int iter=0; !disp.is_closed && !profile.is_closed && !disp.is_keyQ && !disp.is_keyESC && !profile.is_keyQ && !profile.is_keyESC;) { 1.84 + 1.85 + // Compute one iteration of PDE explicit scheme 1.86 + if (run_PDE) { 1.87 + cimg_forV(img,k) cimg_for3x3(img,x,y,0,k,I) veloc(x,y,k) = Inc + Ipc + Icn + Icp - 4*Icc; 1.88 + float m, M = veloc.maxmin(m); 1.89 + const double xdt = dt/(M-m); 1.90 + img += veloc*xdt; 1.91 + cil::CImg<>(img).draw_text(2,2,"iter = %d",white,0,1,13,iter).display(disp.wait(25)); 1.92 + } 1.93 + 1.94 + // Plot (R,G,B) intensity profiles and display it 1.95 + if (disp.mouse_x>=0) { 1.96 + const int 1.97 + mx = disp.mouse_x, my = disp.mouse_y, 1.98 + mnx = mx*profile.dimx()/disp.dimx(); 1.99 + const unsigned char red[] = { 255,0,0 }, green[] = { 0,255,0 }, blue[] = { 0,0,255 }, white[] = { 255,255,255 }; 1.100 + cil::CImg<unsigned char>(profile.dimx(),profile.dimy(),1,3,0). 1.101 + draw_graph(img.get_shared_line(my,0,0),red,1,1,0,255,0). 1.102 + draw_graph(img.get_shared_line(my,0,1),green,1,1,0,255,0). 1.103 + draw_graph(img.get_shared_line(my,0,2),blue,1,1,0,255,0). 1.104 + draw_line(mnx,0,mnx,profile.dimy()-1,white,0.5f,cil::cimg::rol(0xFF00FF00,iter%32)). 1.105 + draw_text(2,2,"(x,y)=(%d,%d)",white,0,1,13,mx,my). 1.106 + display(profile); 1.107 + } 1.108 + 1.109 + // Mouse button stops/starts PDE evolution. 1.110 + if (disp.button || profile.button) { disp.button = profile.button = 0; run_PDE = !run_PDE; } 1.111 + profile.resize(); 1.112 + disp.resize(disp); 1.113 + if (run_PDE) ++iter; 1.114 + } 1.115 + 1.116 + return 0; 1.117 +}