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