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