/home/oan/prosjekt/gotools/segmentation/gpl_distro/lsseg_1.0_gpl/app/LIC_test.C

Go to the documentation of this file.
00001 //===========================================================================
00002 // The Level-Set Segmentation Library (LSSEG)
00003 //
00004 //
00005 // Copyright (C) 2000-2005 SINTEF ICT, Applied Mathematics, Norway.
00006 //
00007 // This program is free software; you can redistribute it and/or          
00008 // modify it under the terms of the GNU General Public License            
00009 // as published by the Free Software Foundation version 2 of the License. 
00010 //
00011 // This program is distributed in the hope that it will be useful,        
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of         
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          
00014 // GNU General Public License for more details.                           
00015 //
00016 // You should have received a copy of the GNU General Public License      
00017 // along with this program; if not, write to the Free Software            
00018 // Foundation, Inc.,                                                      
00019 // 59 Temple Place - Suite 330,                                           
00020 // Boston, MA  02111-1307, USA.                                           
00021 //
00022 // Contact information: e-mail: tor.dokken@sintef.no                      
00023 // SINTEF ICT, Department of Applied Mathematics,                         
00024 // P.O. Box 124 Blindern,                                                 
00025 // 0314 Oslo, Norway.                                                     
00026 // 
00027 //
00028 // Other licenses are also available for this software, notably licenses
00029 // for:
00030 // - Building commercial software.                                        
00031 // - Building software whose source code you wish to keep private.        
00032 //
00033 //===========================================================================
00034 #include "LIC.h"
00035 #include "cimg_dependent.h"
00036 #include <stdexcept>
00037 
00038 using namespace std;
00039 using namespace lsseg;
00040 
00041 // function taken from the Sintef Applied Mathematics GoTools library ('utils' module)
00042 inline void uniformNoise(double* res, double lval, double uval, int num_samples)
00043 {
00044     if (uval <= lval) {
00045         throw runtime_error("uniformNoise(...) : erroneous range.");
00046     }
00047     double range = uval - lval;
00048     double scale_factor = range / double(RAND_MAX);
00049     for (int i = 0; i < num_samples; ++i) {
00050         res[i] = double(rand()) * scale_factor + lval;
00051     }
00052 }
00053 
00054 
00055 double gauss(double t) 
00056 {
00057     //return 1;
00058     return exp(-(t*t) / 1000);
00059 }
00060 
00061 int main()
00062 {
00063     const int X = 200;
00064     const int Y = 200;
00065 
00066     Image<double> noise(X, Y);
00067     uniformNoise(noise.begin(), -128, 128, noise.size());
00068     blur_image(noise, 0.5);
00069     permanent_display(noise);
00070     Image<double> vecfield(X, Y, 1, 2);
00071     for (int y = 0; y < Y; ++y) {
00072         for (int x = 0; x < X; ++x) {
00073 
00074             //vecfield(x, y, 0, 0) = 0.1 * 1;
00075             //vecfield(x, y, 0, 1) = 0.1 * sin(double(x)/90);
00076 
00077 //          vecfield(x, y, 0, 0) = double(x)/100;
00078 //          vecfield(x, y, 0, 1) = 0;
00079 
00080 //          double xx = double(x-50)/50;
00081 //          double yy = double(y-50)/50;
00082 //          double krull = 1;//sqrt(xx * xx + yy * yy);
00083 //          vecfield(x, y, 0, 0) = xx / krull;
00084 //          vecfield(x, y, 0, 1) = yy / krull;
00085 
00086 //          vecfield(x, y, 0, 0) = x < 50 ? 1 : -1;;
00087 //          vecfield(x, y, 0, 1) = 0;
00088             
00089 
00090 //          vecfield(x, y, 0, 0) = cos(double(y)/10);
00091 //          vecfield(x, y, 0, 1) = sin(double(x)/10);
00092 
00093             double dx = x - X/2;
00094             double dy = y - Y/2;
00095             double tmp = double(1) / sqrt(dx * dx + dy * dy);
00096             vecfield(x, y, 0, 0) = -dy * tmp;
00097             vecfield(x, y, 0, 1) = dx * tmp;
00098         }
00099     }
00100 //    display_image(krull);
00101     Image<double> target(noise,false);
00102     LIC_2D(noise, vecfield, target, &gauss, 10);
00103     display_image(target);
00104 
00105     return 1;
00106 }

Generated on Tue Nov 28 18:35:47 2006 for lsseg by  doxygen 1.4.7