00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 #ifndef MLN_SUBSAMPLING_SUBSAMPLING_HH
00028 # define MLN_SUBSAMPLING_SUBSAMPLING_HH
00029 
00033 
00034 # include <mln/geom/ncols.hh>
00035 # include <mln/geom/nrows.hh>
00036 
00037 
00038 namespace mln
00039 {
00040 
00041   namespace subsampling
00042   {
00043 
00045     template <typename I>
00046     inline
00047     mln_concrete(I)
00048     subsampling(const Image<I>& input,
00049                 const mln_deduce(I, site, delta)& first_p,
00050                 const mln_deduce(I, site, coord)& gap);
00051 
00052 # ifndef MLN_INCLUDE_ONLY
00053 
00054     namespace impl
00055     {
00056 
00057       
00058 
00059       template <typename T>
00060       inline
00061       mln_concrete(image2d<T>)
00062       subsampling_(const image2d<T>& input,
00063                    const mln_deduce(image2d<T>, site, delta)& first_p,
00064                    const mln_deduce(image2d<T>, site, coord)& gap)
00065       {
00066         trace::entering("subsampling::impl::subsampling_");
00067         mln_concrete(image2d<T>) output(geom::nrows(input) / gap,
00068                                geom::ncols(input) / gap);
00069 
00070         for (def::coord j = geom::min_col(output);
00071              j <= geom::max_col(output); ++j)
00072           for (def::coord i = geom::min_row(output);
00073                i <= geom::max_row(output); ++i)
00074             {
00075               point2d p1(i, j);
00076               point2d p2(first_p[0] + i * gap, first_p[1] + j * gap);
00077 
00078               output(p1) = input(p2);
00079             }
00080 
00081         trace::exiting("subsampling::impl::subsampling_");
00082         return output;
00083       }
00084 
00085     } 
00086 
00087 
00088     template <typename I>
00089     inline
00090     mln_concrete(I)
00091     subsampling(const Image<I>& input,
00092                 const mln_deduce(I, site, delta)& first_p,
00093                 const mln_deduce(I, site, coord)& gap)
00094     {
00095       trace::entering("subsampling::subsampling");
00096       mln_precondition(exact(input).is_valid());
00097 
00098       mln_concrete(I) output(geom::nrows(input) / gap,
00099                              geom::ncols(input) / gap); 
00100 
00101       output = impl::subsampling_(exact(input), first_p, gap);
00102 
00103       trace::exiting("subsampling::subsampling");
00104       return output;
00105     }
00106 
00107 # endif // ! MLN_INCLUDE_ONLY
00108 
00109   } 
00110 
00111 } 
00112 
00113 
00114 #endif // ! MLN_SUBSAMPLING_SUBSAMPLING_HH