2
0
mirror of https://github.com/boostorg/gil.git synced 2026-01-19 16:22:14 +00:00
Files
gil/example/histogram.cpp
Mateusz Łoskot 32fec9f05b Refactor library includes to #include <boost/gil/...>
Group include directives, sort within group:
* In headers of GIL core and extensions:
  1. boost/gil/extension/*
  2. boost/gil/*
  3. boost/*
  4. C++ standard library headers
* In programs:
  1. boost/gil/*
  2. boost/*
  3. C++ standard library headers
  4. "xxx.hpp" for local headers
Add basic guidelines to CONTRIBUTING.md.
Add/Remove #include <boost/config.hpp> or std headers un/necessary.
Rename gil_concept.hpp to concepts.hpp.
Remove gil_all.hpp - we already have all-in-one boost/gil.hpp.
Tidy up and unify copyright and license header.
Tidy up formatting and excessive whitespaces in some comments.
Remove Doxygen block with file description, author, date, etc.
Remove dead or commented pragmas and directives.
Trim trailing whitespaces.
2018-09-28 16:26:34 +02:00

45 lines
1.2 KiB
C++

//
// Copyright 2005-2007 Adobe Systems Incorporated
//
// Distributed under the Boost Software License, Version 1.0
// See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt
//
#include <boost/gil.hpp>
#include <boost/gil/extension/io/jpeg.hpp>
#include <algorithm>
#include <fstream>
// Example file to demonstrate a way to compute histogram
using namespace boost::gil;
template <typename GrayView, typename R>
void gray_image_hist(const GrayView& img_view, R& hist) {
// for_each_pixel(img_view,++lambda::var(hist)[lambda::_1]);
for (typename GrayView::iterator it=img_view.begin(); it!=img_view.end(); ++it)
++hist[*it];
}
template <typename V, typename R>
void get_hist(const V& img_view, R& hist) {
gray_image_hist(color_converted_view<gray8_pixel_t>(img_view), hist);
}
int main() {
rgb8_image_t img;
read_image("test.jpg", img, jpeg_tag());
int histogram[256];
std::fill(histogram,histogram + 256, 0);
get_hist(const_view(img), histogram);
std::fstream histo_file("out-histogram.txt", std::ios::out);
for(std::size_t ii = 0; ii < 256; ++ii)
histo_file << histogram[ii] << std::endl;
histo_file.close();
return 0;
}