62379dd5b9
* Implement Sobel and Scharr operators This commit adds Sobel and Scharr operators with support for 0th and 1st degrees with other degrees planned for later * Migrate and fix Harris example Generate Harris entries now uses signed image view. The Harris corner detector example now uses the Scharr filter generator and convolve_2d to reduce amount of code needed. * Fix and migrate Hessian example The Hessian example now uses signed image views and uses newly added kernel generators to compute gradients * Fix Harris and Hessian tests The tests broke due to migration to signed views in algorithms, but tests were not adjusted * Fix Jamfile for example/sobel_scharr.cpp * Cosmetic changes * Commented out fail tests * Fixed pixel16 used in image16s In Harris and Hessian tests, unsigned pixel values was used to construct signed image, which was causing appveyor to error out. * Reenable failing targets * Unify kernel generator interface This commit makes all kernel generator functions to return kernel_2d and adapts dependant threshold function to use the new interface * Migrate Hessian and Harris tests Migrate Hessian and Harris tests to new interface for kernel generators * Migrate Harris and Hessian examples Harris and Hessian examples now use new interface for kernel generation * Migrate simple_kernels tests simple_kernels are now using kernel_2d interface * Add missing return Normalized mean generation had missing return at the end of the function * Adapt code to namespace move This commit reacts to kernel_2d, convolve_2d being moved to namespace detail
46 lines
1.4 KiB
C++
46 lines
1.4 KiB
C++
#include <boost/gil/typedefs.hpp>
|
|
#include <boost/gil/image_processing/numeric.hpp>
|
|
#include <boost/gil/extension/io/png.hpp>
|
|
#include <boost/gil/extension/numeric/convolve.hpp>
|
|
#include <string>
|
|
#include <iostream>
|
|
|
|
namespace gil = boost::gil;
|
|
|
|
int main(int argc, char* argv[])
|
|
{
|
|
if (argc != 5)
|
|
{
|
|
std::cerr << "usage: " << argv[0] << ": <input.png> <sobel|scharr> <output-x.png> <output-y.png>\n";
|
|
return -1;
|
|
}
|
|
|
|
gil::gray8_image_t input_image;
|
|
gil::read_image(argv[1], input_image, gil::png_tag{});
|
|
auto input = gil::view(input_image);
|
|
auto filter_type = std::string(argv[2]);
|
|
|
|
gil::gray16_image_t dx_image(input_image.dimensions());
|
|
auto dx = gil::view(dx_image);
|
|
gil::gray16_image_t dy_image(input_image.dimensions());
|
|
auto dy = gil::view(dy_image);
|
|
if (filter_type == "sobel")
|
|
{
|
|
gil::convolve_2d(input, gil::generate_dx_sobel(1), dx);
|
|
gil::convolve_2d(input, gil::generate_dy_sobel(1), dy);
|
|
}
|
|
else if (filter_type == "scharr")
|
|
{
|
|
gil::convolve_2d(input, gil::generate_dx_scharr(1), dx);
|
|
gil::convolve_2d(input, gil::generate_dy_scharr(1), dy);
|
|
}
|
|
else
|
|
{
|
|
std::cerr << "unrecognized gradient filter type. Must be either sobel or scharr\n";
|
|
return -1;
|
|
}
|
|
|
|
gil::write_view(argv[3], dx, gil::png_tag{});
|
|
gil::write_view(argv[4], dy, gil::png_tag{});
|
|
}
|