affine.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334
  1. //
  2. // Copyright 2005-2007 Adobe Systems Incorporated
  3. //
  4. // Distributed under the Boost Software License, Version 1.0
  5. // See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt
  7. //
  8. #include <boost/gil.hpp>
  9. #include <boost/gil/extension/io/jpeg.hpp>
  10. #include <boost/gil/extension/numeric/sampler.hpp>
  11. #include <boost/gil/extension/numeric/resample.hpp>
  12. // Example for resample_pixels() in the numeric extension
  13. int main()
  14. {
  15. namespace gil = boost::gil;
  16. gil::rgb8_image_t img;
  17. gil::read_image("test.jpg", img, gil::jpeg_tag());
  18. // test resample_pixels
  19. // Transform the image by an arbitrary affine transformation using nearest-neighbor resampling
  20. gil::rgb8_image_t transf(gil::rgb8_image_t::point_t(gil::view(img).dimensions() * 2));
  21. gil::fill_pixels(gil::view(transf), gil::rgb8_pixel_t(255, 0, 0)); // the background is red
  22. gil::matrix3x2<double> mat =
  23. gil::matrix3x2<double>::get_translate(-gil::point<double>(200,250)) *
  24. gil::matrix3x2<double>::get_rotate(-15*3.14/180.0);
  25. gil::resample_pixels(const_view(img), gil::view(transf), mat, gil::nearest_neighbor_sampler());
  26. gil::write_view("out-affine.jpg", gil::view(transf), gil::jpeg_tag());
  27. return 0;
  28. }