• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include <boost/gil/typedefs.hpp>
2 #include <boost/gil/image_processing/numeric.hpp>
3 #include <boost/gil/extension/io/png.hpp>
4 #include <boost/gil/extension/numeric/convolve.hpp>
5 #include <string>
6 #include <iostream>
7 
8 namespace gil = boost::gil;
9 
main(int argc,char * argv[])10 int main(int argc, char* argv[])
11 {
12     if (argc != 5)
13     {
14         std::cerr << "usage: " << argv[0] << ": <input.png> <sobel|scharr> <output-x.png> <output-y.png>\n";
15         return -1;
16     }
17 
18     gil::gray8_image_t input_image;
19     gil::read_image(argv[1], input_image, gil::png_tag{});
20     auto input = gil::view(input_image);
21     auto filter_type = std::string(argv[2]);
22 
23     gil::gray16_image_t dx_image(input_image.dimensions());
24     auto dx = gil::view(dx_image);
25     gil::gray16_image_t dy_image(input_image.dimensions());
26     auto dy = gil::view(dy_image);
27     if (filter_type == "sobel")
28     {
29         gil::detail::convolve_2d(input, gil::generate_dx_sobel(1), dx);
30         gil::detail::convolve_2d(input, gil::generate_dy_sobel(1), dy);
31     }
32     else if (filter_type == "scharr")
33     {
34         gil::detail::convolve_2d(input, gil::generate_dx_scharr(1), dx);
35         gil::detail::convolve_2d(input, gil::generate_dy_scharr(1), dy);
36     }
37     else
38     {
39         std::cerr << "unrecognized gradient filter type. Must be either sobel or scharr\n";
40         return -1;
41     }
42 
43     gil::write_view(argv[3], dx, gil::png_tag{});
44     gil::write_view(argv[4], dy, gil::png_tag{});
45 }
46