Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure all examples build without error #628

Merged
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions example/Jamfile
Original file line number Diff line number Diff line change
@@ -11,6 +11,7 @@ import regex ;
import testing ;

using libjpeg : : : : true ; # work around bug on master
using libpng : : : : true ;

project
: # requirements
@@ -19,6 +20,7 @@ project
# TODO: Add missing examples

local sources =
adaptive_he.cpp
adaptive_threshold.cpp
affine.cpp
anisotropic_diffusion.cpp
@@ -27,12 +29,18 @@ local sources =
dynamic_image.cpp
harris.cpp
hessian.cpp
histogram_equalization.cpp
histogram_matching.cpp
histogram.cpp
hough_transform_circle.cpp
hough_transform_line.cpp
interleaved_ptr.cpp
mandelbrot.cpp
morphology.cpp
packed_pixel.cpp
rasterizer_circle.cpp
rasterizer_ellipse.cpp
rasterizer_line.cpp
resize.cpp
sobel_scharr.cpp
threshold.cpp
@@ -44,11 +52,13 @@ local targets ;

for local s in $(sources)
{
targets +=
[ compile $(s) :
[ ac.check-library /libjpeg//libjpeg : <library>/libjpeg//libjpeg : <build>no ]
]
;
targets +=
[ exe [ regex.replace $(s) ".cpp" "" ] :
$(s)
/libjpeg//libjpeg
/libpng//libpng
]
;
}

alias examples : $(targets) ;
7 changes: 7 additions & 0 deletions example/adaptive_he.cpp
Original file line number Diff line number Diff line change
@@ -13,6 +13,13 @@

using namespace boost::gil;

// Demonstrates Adaptive Histogram Equalization (AHE)

// See also:
// histogram.cpp - General use of histograms in GIL
// histogram_equalization.cpp - Regular Histogram Equalization
// histogram_matching.cpp - Reference-based histogram computation

int main()
{
gray8_image_t img;
10 changes: 10 additions & 0 deletions example/adaptive_threshold.cpp
Original file line number Diff line number Diff line change
@@ -5,12 +5,22 @@
// 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/png.hpp>
#include <iostream>

using namespace boost::gil;

// Demonstrates Adaptive Thresholding

// threshold_adaptive works following either the mean or the gaussian method, and accepts also a direction
// The direction indicates whether the pixels are assigned the max value when their values are greater
// than the threshold (regular), or when they are less than the threshold (inverse)
// threshold_adaptive is defined in include/boost/gil/image_processing/threshold.hpp
// See also:
// threshold.cpp - Simple thresholding

int main()
{
gray8_image_t img;
7 changes: 6 additions & 1 deletion example/affine.cpp
Original file line number Diff line number Diff line change
@@ -5,12 +5,17 @@
// 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 <boost/gil/extension/numeric/sampler.hpp>
#include <boost/gil/extension/numeric/resample.hpp>

// Example for resample_pixels() in the numeric extension
// Performs an arbitrary affine transformation on the image.

// This example relies on the matrices and functions available in GIL to define the operation,
// in include/boost/gil/extension/numeric/affine.hpp
// and calls resample_pixels(), avaiable in the numeric extension, to apply it

int main()
{
7 changes: 7 additions & 0 deletions example/anisotropic_diffusion.cpp
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//

#include <boost/gil/algorithm.hpp>
#include <boost/gil/extension/io/png.hpp>
#include <boost/gil/image.hpp>
@@ -20,6 +21,12 @@

namespace gil = boost::gil;

// Demonstrates Anisotropic Diffusion

// This example uses the Perona-Malik's diffusion algorithm, which is the default in GIL.
// In addition, Gaussian conductivity and two wide range conductivity functions are also available.
// see include/boost/gil/image_processing/diffusion.hpp

void gray_version(std::string const& input_path, std::string const& output_path,
unsigned int iteration_count, float kappa)
{
14 changes: 13 additions & 1 deletion example/convolution.cpp
Original file line number Diff line number Diff line change
@@ -4,12 +4,24 @@
// 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 <boost/gil/extension/numeric/kernel.hpp>
#include <boost/gil/extension/numeric/convolve.hpp>

// Example for convolve_rows() and convolve_cols() in the numeric extension
// Convolves the image with a Gaussian kernel.

// Note that the kernel can be fixed or resizable:
// kernel_1d_fixed<float, N> k(matrix, centre) produces a fixed kernel
// kernel_1d<float> k(matrix, size, centre) produces a resizable kernel

// Work can be done row by row and column by column, as in this example,
// using the functions convolve_rows and convolve_cols (or their _fixed counterpart)
// but the header boost/gil/extension/numeric/convolve.hpp also offers the function convolve_1d which combines the two.

// See also:
// convolve2d.cpp - Convolution with 2d kernels

int main() {
using namespace boost::gil;
21 changes: 21 additions & 0 deletions example/convolve2d.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,33 @@
//
// 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 <vector>
#include <iostream>
#include <boost/gil/extension/numeric/kernel.hpp>
#include <boost/gil/extension/numeric/convolve.hpp>
#include <boost/gil/extension/io/png.hpp>

#include <boost/gil/extension/io/jpeg.hpp>

using namespace boost::gil;
using namespace std;

// Convolves the image with a 2d kernel.

// Note that the kernel can be fixed or resizable:
// kernel_2d_fixed<float, N> k(elements, centre_y, centre_x) produces a fixed kernel
// kernel_2d<float> k(elements, size, centre_y, centre_x) produces a resizable kernel
// The size of the kernel matrix is deduced as the square root of the number of the elements (9 elements yield a 3x3 matrix)

// See also:
// convolution.cpp - Convolution with 2d kernels


int main()
{
//gray8_image_t img;
5 changes: 5 additions & 0 deletions example/dynamic_image.cpp
Original file line number Diff line number Diff line change
@@ -5,18 +5,23 @@
// 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/dynamic_image/any_image.hpp>
#include <boost/gil/extension/io/jpeg.hpp>
#include <boost/mp11.hpp>

// Demonstrates how to use images whose type is instantiated at run time.

int main()
{
namespace gil = boost::gil;

gil::any_image<gil::gray8_image_t, gil::rgb8_image_t, gil::gray16_image_t, gil::rgb16_image_t> dynamic_image;
gil::read_image("test.jpg", dynamic_image, gil::jpeg_tag());

// Save the image upside down, preserving its native color space and channel depth
auto view = gil::flipped_up_down_view(gil::const_view(dynamic_image));

gil::write_view("out-dynamic_image.jpg", view, gil::jpeg_tag());
}
7 changes: 5 additions & 2 deletions example/harris.cpp
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//

#include <boost/gil/extension/io/png.hpp>
#include <boost/gil/extension/numeric/convolve.hpp>
#include <boost/gil/image.hpp>
@@ -23,6 +24,8 @@

namespace gil = boost::gil;

// Demonstrates Harris corner detection

// some images might produce artifacts
// when converted to grayscale,
// which was previously observed on
@@ -157,11 +160,11 @@ int main(int argc, char* argv[])

gil::rgb8_image_t input_image;

gil::read_image(argv[1], input_image, gil::png_tag{});
gil::read_image(argv[1], input_image, gil::png_tag{});
auto original_image = input_image;
auto original_view = gil::view(original_image);
auto input_view = gil::view(input_image);
auto grayscaled = to_grayscale(input_view);
auto grayscaled = to_grayscale(input_view);
gil::gray8_image_t smoothed_image(grayscaled.dimensions());
auto smoothed = gil::view(smoothed_image);
apply_gaussian_blur(gil::view(grayscaled), smoothed);
10 changes: 10 additions & 0 deletions example/hessian.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
//
// 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/image.hpp>
#include <boost/gil/image_view.hpp>
#include <boost/gil/image_processing/numeric.hpp>
@@ -11,6 +19,8 @@

namespace gil = boost::gil;

// Demonstrates Hessian feature (blob) detection

// some images might produce artifacts
// when converted to grayscale,
// which was previously observed on
13 changes: 8 additions & 5 deletions example/histogram.cpp
Original file line number Diff line number Diff line change
@@ -14,10 +14,13 @@

using namespace boost::gil;

/*
This file explains how to use the histogram class and some of its features
that can be applied for a variety of tasks.
*/
// Explains how to use the histogram class and some of its features
// that can be applied for a variety of tasks.

// See also:
// histogram_equalization.cpp - Regular Histogram Equalization
// adaptive_he.cpp - Adaptive Histogram Equalization
// histogram_matching.cpp - Reference-based histogram computation

int main()
{
@@ -34,7 +37,7 @@ int main()
h, // Histogram to be filled
1, // Histogram bin widths
false, // Specify whether to accumulate over the values already present in h (default = false)
true, // Specify whether to have a sparse or continuous histogram (default = true)
true, // Specify whether to have a sparse (true) or continuous histogram (false) (default = true)
false, // Specify if image mask is to be specified
{{}}, // Mask as a 2D vector. Used only if prev argument specified
{0}, // Lower limit on the values in histogram (default numeric_limit::min() on axes)
15 changes: 15 additions & 0 deletions example/histogram_equalization.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,24 @@
//
// 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/png.hpp>
#include <boost/gil/image_processing/histogram_equalization.hpp>

using namespace boost::gil;

// Demonstrates Histogram Equalization

// See also:
// histogram.cpp - General use of histograms in GIL
// adaptive_he.cpp - Adaptive Histogram Equalization
// histogram_matching.cpp - Reference-based histogram computation

int main()
{
gray8_image_t img;
7 changes: 7 additions & 0 deletions example/histogram_matching.cpp
Original file line number Diff line number Diff line change
@@ -14,6 +14,13 @@

using namespace boost::gil;

// Demonstrates Histogram Matching

// See also:
// histogram_equalization.cpp - Regular Histogram Equalization
// adaptive_he.cpp - Adaptive Histogram Equalization
// histogram.cpp - General use of histograms in GIL

std::vector<std::vector<bool>> get_mask(gray8_view_t const& mask)
{
std::vector<std::vector<bool>> mask_vec(mask.height(), std::vector<bool>(mask.width(), 0));
12 changes: 11 additions & 1 deletion example/hough_transform_circle.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Boost.GIL (Generic Image Library) - tests
//
// Copyright 2020 Olzhas Zhumabek <[email protected]>
//
// Use, modification and distribution are subject to 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/png.hpp>

@@ -15,6 +15,16 @@

namespace gil = boost::gil;

// Demonstrates how to use a Hough transform to identify a circle

// Note this relies on the brute force approach, which today is the only one available in GIL
// The function hough_circle_transform_brute, defined in include/boost/gil/image_processing/hough_transform.cpp,
// accepts a greyscale edge map, the three Hough parameters allowing to do the drawing and the voting,
// an accumulator in the form of an iterator of views of the parameter space and a utility rasterizer to produce the points.
// The example outputs the voting cell of the centre of a circle drawn programatically.
// See also:
// hough_transform_line.cpp - Hough transform to detect lines

int main()
{
const std::size_t size = 128;
Loading