/Src/Dependencies/Boost/libs/gil/example/histogram.cpp

http://hadesmem.googlecode.com/ · C++ · 53 lines · 28 code · 10 blank · 15 comment · 2 complexity · 3f2d78e1eb42dcf18476e00ed8d606dc MD5 · raw file

  1. /*
  2. Copyright 2005-2007 Adobe Systems Incorporated
  3. Use, modification and distribution are subject to the Boost Software License,
  4. Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  5. http://www.boost.org/LICENSE_1_0.txt).
  6. See http://opensource.adobe.com/gil for most recent version including documentation.
  7. */
  8. /*************************************************************************************************/
  9. /// \file
  10. /// \brief Example file to demonstrate a way to compute histogram
  11. /// \author Lubomir Bourdev and Hailin Jin
  12. /// \date February 27, 2007
  13. #include <algorithm>
  14. #include <fstream>
  15. #include <boost/gil/image.hpp>
  16. #include <boost/gil/typedefs.hpp>
  17. #include <boost/gil/color_convert.hpp>
  18. #include <boost/gil/extension/io/jpeg_io.hpp>
  19. using namespace boost::gil;
  20. template <typename GrayView, typename R>
  21. void gray_image_hist(const GrayView& img_view, R& hist) {
  22. // for_each_pixel(img_view,++lambda::var(hist)[lambda::_1]);
  23. for (typename GrayView::iterator it=img_view.begin(); it!=img_view.end(); ++it)
  24. ++hist[*it];
  25. }
  26. template <typename V, typename R>
  27. void get_hist(const V& img_view, R& hist) {
  28. gray_image_hist(color_converted_view<gray8_pixel_t>(img_view), hist);
  29. }
  30. int main() {
  31. rgb8_image_t img;
  32. jpeg_read_image("test.jpg",img);
  33. int histogram[256];
  34. std::fill(histogram,histogram+256,0);
  35. get_hist(const_view(img),histogram);
  36. std::fstream histo_file("out-histogram.txt",std::ios::out);
  37. for(std::size_t ii=0;ii<256;++ii)
  38. histo_file << histogram[ii] << std::endl;
  39. histo_file.close();
  40. return 0;
  41. }