• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • Examples
  • File List
  • File Members

/home/hauberg/Dokumenter/Capture/humim-tracker-0.1/src/OpenTissue/OpenTissue/utility/image_analysis/image_analysis_compute_default_labels.h

Go to the documentation of this file.
00001 #ifndef OPENTISSUE_UTILITY_IMAGE_ANALYSIS_IMAGE_ANALYSIS_COMPUTE_DEFAULT_LABELS_H
00002 #define OPENTISSUE_UTILITY_IMAGE_ANALYSIS_IMAGE_ANALYSIS_COMPUTE_DEFAULT_LABELS_H
00003 //
00004 // OpenTissue Template Library
00005 // - A generic toolbox for physics-based modeling and simulation.
00006 // Copyright (C) 2008 Department of Computer Science, University of Copenhagen.
00007 //
00008 // OTTL is licensed under zlib: http://opensource.org/licenses/zlib-license.php
00009 //
00010 #include <OpenTissue/configuration.h>
00011 
00012 #include <iostream>
00013 #include <fstream>
00014 #include <cmath>
00015 #include <algorithm>
00016 
00017 #include <OpenTissue/core/containers/grid/grid.h>
00018 #include <OpenTissue/utility/image_analysis/image_analysis_compute_intensity_gradient_histogram.h>
00019 #include <OpenTissue/core/math/math_basic_types.h>
00020 
00021 namespace OpenTissue
00022 {
00023   namespace image_analysis
00024   {
00033     template<typename image_type>
00034     void compute_default_labels(image_type & U)
00035     {
00036       using std::max;
00037       using std::log;
00038 
00039       OpenTissue::grid::Grid<size_t,math::default_math_types> index_grid;
00040       size_t histogram[512][128];
00041 
00042       compute_intensity_gradient_histogram(U,512,128,histogram,index_grid);
00043 
00044       //--- Take the logarithm of histogram
00045       double log_histogram[512][128];
00046       for(size_t j=0;j<128;++j)
00047         for(size_t i=0;i<512;++i)
00048           log_histogram[i][j] = log(1.0*histogram[i][j]+1.0);
00049 
00050       //--- Find maximum value in log histogram
00051       double max_value = 0;
00052       for(size_t j=0;j<128;++j)
00053         for(size_t i=0;i<512;++i)
00054           max_value = max(max_value,log_histogram[i][j]);
00055 
00056       //--- Write out log histogram as a matlab matrix, great for inspection.
00057       //--- Try examine the matrix with matlab's imaging toolbox
00058       std::ofstream file("histogram.m");
00059       file << " H = [ ";
00060       for(size_t j=0;j<128;++j)
00061       {
00062         for(size_t i=0;i<512;++i)
00063           file << " " << log_histogram[i][j];
00064         if(j<127)
00065           file << ";" << std::endl;
00066       }
00067       file << "];" << std::endl;
00068       file << "imagesc(H);" << std::endl;
00069       file << "colormap(gray);" << std::endl;
00070       file.flush();
00071       file.close();
00072 
00073       //--- Now use histogram to search for features and regions in the image and label them.
00074       size_t labels[512][128]; //--- Think of this as a color or transfer function.
00075       for(size_t j=0;j<128;++j)
00076         for(size_t i=0;i<512;++i)
00077           labels[i][j] = static_cast<size_t>( log_histogram[i][j] );
00078 
00079       //--- Use index map to assign labels to each voxel of U
00080       for(size_t x=0; x<U.I(); ++x)
00081         for(size_t y=0; y<U.J(); ++y)
00082           for(size_t z=0; z<U.K(); ++z)
00083           {
00084             size_t idx = index_grid(x,y,z);
00085             size_t i_idx = (idx >> 16) & 0x00FF;
00086             size_t g_idx = idx & 0x00FF;
00087             U(x,y,z) = labels[i_idx][g_idx];
00088           }
00089 
00090           std::cout << "default_labelling done..." << std::endl;
00091     }
00092 
00093 
00094   }// end namespace image_analysis
00095 
00096 } // namespace OpenTissue
00097 
00098 //  OPENTISSUE_UTILITY_IMAGE_ANALYSIS_IMAGE_ANALYSIS_COMPUTE_DEFAULT_LABELS_H
00099 #endif

Generated on Thu Dec 1 2011 12:53:44 for HUMIM Tracker by  doxygen 1.7.1