PageRenderTime 6ms CodeModel.GetById 1ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/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   
 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
25using namespace boost::gil;
26
27template <typename GrayView, typename R>
28void 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
34template <typename V, typename R>
35void get_hist(const V& img_view, R& hist) {
36    gray_image_hist(color_converted_view<gray8_pixel_t>(img_view), hist);
37}
38
39int 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}