libcrn  3.9.5
A document image processing library
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CRNImage2D.h
Go to the documentation of this file.
1 /* Copyright 2007-2015 Yann LEYDIER, CoReNum, INSA-Lyon
2  *
3  * This file is part of libcrn.
4  *
5  * libcrn is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Lesser General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * libcrn is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with libcrn. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * file: CRNImage2DIntPolarVector.h
19  * \author Yann LEYDIER
20  */
21 
22 #ifndef CRNIMAGE2DINTPOLARVECTOR_HEADER
23 #define CRNIMAGE2DINTPOLARVECTOR_HEADER
24 
25 #include <CRNImage/CRNImage.h>
26 #include <CRNException.h>
27 
32 namespace crn
33 {
41  template<typename T> Image<pixel::Cart2D<T>> MakeVector(const Image<T> &x, const Image<T> &y)
42  {
43  if ((x.GetWidth() != y.GetWidth()) || (x.GetHeight() != y.GetHeight()))
44  throw ExceptionDimension("Image<pixel::Cart2D<T>> MakeVector(const Image<T> &x, const Image<T> &y): images do not have the same size.");
45  auto res = Image<pixel::Cart2D<T>>(x.GetWidth(), x.GetHeight());
46  for (auto tmp : Range(x))
47  res.At(tmp) = {x.At(tmp), y.At(tmp)};
48  return res;
49  }
50 
55  template<typename R, typename T> Image<R> RhoChannel(const Image<pixel::Polar2D<R, T>> &img)
56  {
57  auto res = Image<R>{img.GetWidth(), img.GetHeight()};
58  for (auto tmp : Range(img))
59  res.At(tmp) = img.At(tmp).rho;
60  return res;
61  }
62 
67  template<typename R, typename T> Image<typename Unit<T>::type> ThetaChannel(const Image<pixel::Polar2D<R, T>> &img)
68  {
69  auto res = Image<typename Unit<T>::type>{img.GetWidth(), img.GetHeight()};
70  for (auto tmp : Range(img))
71  res.At(tmp) = img.At(tmp).theta.value;
72  return res;
73  }
74 }
75 
76 #endif
77 
Abstract class for images.
Definition: CRNImage.h:141
ScalarRange< T > Range(T b, T e)
Creates a range [[b, e[[.
Definition: CRNType.h:257
std::vector< pixel_type >::reference At(size_t x, size_t y) noexcept
Returns a reference to a pixel.
Definition: CRNImage.h:224
size_t GetHeight() const noexcept
Definition: CRNImage.h:74
A dimension error.
Definition: CRNException.h:119
Image< pixel::Cart2D< T > > MakeVector(const Image< T > &x, const Image< T > &y)
Definition: CRNImage2D.h:41
Image< typename Unit< T >::type > ThetaChannel(const Image< pixel::Polar2D< R, T >> &img)
Definition: CRNImage2D.h:67
size_t GetWidth() const noexcept
Definition: CRNImage.h:72
Image< R > RhoChannel(const Image< pixel::Polar2D< R, T >> &img)
Definition: CRNImage2D.h:55