TuttleOFX  1
canny.hpp
Go to the documentation of this file.
00001 #ifndef _TERRY_FILTER_CANNY_HPP_
00002 #define _TERRY_FILTER_CANNY_HPP_
00003 
00004 #include "sobel.hpp"
00005 #include "localMaxima.hpp"
00006 #include "floodFill.hpp"
00007 #include "thinning.hpp"
00008 
00009 #include <terry/algorithm/transform_pixels.hpp>
00010 #include <terry/algorithm/pixel_by_channel.hpp>
00011 #include <terry/color/norm.hpp>
00012 #include <terry/draw/fill.hpp>
00013 #include <terry/numeric/operations.hpp>
00014 #include <terry/algorithm/pixel_by_channel.hpp>
00015 
00016 #include <boost/gil/algorithm.hpp>
00017 
00018 
00019 namespace terry {
00020 namespace filter {
00021 
00022 /**
00023  * @brief Canny filtering.
00024  */
00025 template<template<typename> class Alloc, class SView, class TRGBView, class TGrayView, class DView>
00026 void canny(
00027         const SView& srcView,
00028         const TRGBView& tmpSobelView,
00029         const TGrayView& tmpGrayView,
00030         const DView& cannyView,
00031         const point2<double>& sobelSize,
00032         const convolve_boundary_option sobelBoundaryOption,
00033         const double cannyThresLow, const double cannyThresUpper
00034         )
00035 {
00036         typedef typename DView::value_type DPixel;
00037         typedef typename SView::value_type SPixel;
00038 
00039         typedef typename SView::point_t Point;
00040         typedef typename channel_mapping_type<DView>::type DChannel;
00041         typedef typename floating_channel_type_t<DChannel>::type DChannelFloat;
00042         typedef pixel<DChannelFloat, gray_layout_t> DPixelGray;
00043 
00044         const Point proc_tl( 0, 0 );
00045 
00046         //boost::gil::png_write_view( "data/terry/output_in_terry.png", color_converted_view<rgb8_pixel_t>( srcView ) );
00047         
00048         //boost::timer t;
00049         sobel<Alloc>(
00050                 srcView,
00051                 kth_channel_view<0>(tmpSobelView), // sobel X
00052                 kth_channel_view<1>(tmpSobelView), // sobel Y
00053                 sobelSize,
00054                 sobelBoundaryOption );
00055         //std::cout << "sobel time: " << t.elapsed() << std::endl;
00056         
00057         //t.restart();
00058         boost::gil::transform_pixels(
00059                 kth_channel_view<0>(tmpSobelView), // srcX
00060                 kth_channel_view<1>(tmpSobelView), // srcY
00061                 kth_channel_view<2>(tmpSobelView), // dst: gradient direction
00062                 algorithm::transform_pixel_by_channel_t<terry::color::channel_norm_t>()
00063                 );
00064         //std::cout << "norm time: " << t.elapsed() << std::endl;
00065         
00066         //boost::gil::png_write_view( "data/terry/output_sobel_terry.png", color_converted_view<rgb8_pixel_t>( tmpSobelView ) );
00067 
00068         //t.restart();
00069         applyLocalMaxima( tmpSobelView, tmpGrayView );
00070         //std::cout << "localMaxima time: " << t.elapsed() << std::endl;
00071 
00072         //boost::gil::png_write_view( "data/terry/output_localMaxima_terry.png", color_converted_view<rgb8_pixel_t>( tmpGrayView ) );
00073         
00074         //t.restart();
00075         applyFloodFill<Alloc>( tmpGrayView, cannyView, cannyThresLow, cannyThresUpper );
00076         //std::cout << "floodFill time: " << t.elapsed() << std::endl;
00077 
00078         //boost::gil::png_write_view( "data/terry/output_floodFill_terry.png", color_converted_view<rgb8_pixel_t>( cannyView ) );
00079 
00080         //t.restart();
00081         applyThinning( cannyView, tmpGrayView, cannyView );
00082         //std::cout << "thinning time: " << t.elapsed() << std::endl;
00083 }
00084 
00085 
00086 
00087 }
00088 }
00089 
00090 #endif
00091