2 // Copyright 2005-2007 Adobe Systems Incorporated
4 // Distributed under the Boost Software License, Version 1.0
5 // See accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt
8 #include <boost/gil.hpp>
9 #include <boost/gil/extension/io/jpeg.hpp>
14 // Example file to demonstrate a way to compute histogram
16 using namespace boost::gil;
18 template <typename GrayView, typename R>
19 void gray_image_hist(GrayView const& img_view, R& hist)
21 for (auto it = img_view.begin(); it != img_view.end(); ++it)
24 // Alternatively, prefer the algorithm with lambda
25 // for_each_pixel(img_view, [&hist](gray8_pixel_t const& pixel) {
30 template <typename V, typename R>
31 void get_hist(const V& img_view, R& hist) {
32 gray_image_hist(color_converted_view<gray8_pixel_t>(img_view), hist);
37 read_image("test.jpg", img, jpeg_tag());
40 std::fill(histogram,histogram + 256, 0);
41 get_hist(const_view(img), histogram);
43 std::fstream histo_file("out-histogram.txt", std::ios::out);
44 for(std::size_t ii = 0; ii < 256; ++ii)
45 histo_file << histogram[ii] << std::endl;