ivl 679
ivl/details/image/functions/image_functions_impl.hpp
00001 /* This file is part of the ivl C++ library <http://image.ntua.gr/ivl>.
00002    A C++ template library extending syntax towards mathematical notation.
00003 
00004    Copyright (C) 2012 Yannis Avrithis <iavr@image.ntua.gr>
00005    Copyright (C) 2012 Kimon Kontosis <kimonas@image.ntua.gr>
00006 
00007    ivl is free software; you can redistribute it and/or modify
00008    it under the terms of the GNU Lesser General Public License 
00009    version 3 as published by the Free Software Foundation.
00010 
00011    Alternatively, you can redistribute it and/or modify it under the terms 
00012    of the GNU General Public License version 2 as published by the Free 
00013    Software Foundation.
00014 
00015    ivl is distributed in the hope that it will be useful,
00016    but WITHOUT ANY WARRANTY; without even the implied warranty of
00017    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
00018    See the GNU General Public License for more details.
00019 
00020    You should have received a copy of the GNU General Public License 
00021    and a copy of the GNU Lesser General Public License along 
00022    with ivl. If not, see <http://www.gnu.org/licenses/>. */
00023 
00024 /*
00025 image_functions_impl
00026 
00027 This file has no include-guards and it should not be included by
00028 the user. The code in this library is compiled into the project .lib file
00029 
00030 todo: use the extern template macro, and allow the inclusion of
00031 this file for further class extension
00032 */
00033 #ifndef IMFI
00034 #define IMFI
00035 
00036 //#include "../../../image.hpp"
00037 
00038 //#ifdef min
00039 //#undef min
00040 //#endif
00041 //#ifdef max
00042 //#undef max
00043 //#endif
00044 
00045 namespace ivl {
00046 
00047 /* IMAGE PROCESSING FUNCTIONS */
00048 
00050 template <class T, class D>
00051 typename image<T, D>::create_similar flipud(const image<T, D>& a)
00052 {
00053         return flipdim(a, 0);
00054 }
00055 
00056 template <class T, class D>
00057 typename image<T, D>::create_similar fliplr(const image<T, D>& a)
00058 {
00059         return flipdim(a, 1);
00060 }
00061 
00063 template <class T, class D>
00064 typename image<T, D>::create_similar grayscale(const image<T, D>& a)
00065 {
00066         size_t ch = a.channels();
00067         CHECK(ch > 1, erange());
00068         size_t w = a.width();
00069         size_t h = a.height();
00070         typename types::promote<T>::type acc;
00071         typename image<T, D>::create_similar r(h, w, 1, 0);
00072         for(size_t i = 0; i < h; i++) {
00073                 for(size_t j = 0; j < w; j++) {
00074                         acc = a(i, j, 0);
00075                         for(size_t col = 1; col < ch; col++)
00076                                 acc += a(i, j, col);
00077                         acc /= typename types::promote<T>::type(ch);
00078                         r(i, j) = T(acc);
00079                 }
00080         }
00081         return r;
00082 }
00083 
00084 } // namespace ivl
00085 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations