libcrn  3.9.5
A document image processing library
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CRNImageGradient.h
Go to the documentation of this file.
1 /* Copyright 2006-2016 Yann LEYDIER, CoReNum, INSA-Lyon, ENS-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: CRNImageGradient.h
19  * \author Yann LEYDIER
20  */
21 
22 #ifndef CRNIMAGEGRADIENT_HEADER
23 #define CRNIMAGEGRADIENT_HEADER
24 
25 #include <CRNImage/CRNImage2D.h>
26 
27 namespace crn
28 {
29  /****************************************************************************/
39  class ImageGradient : public Image<pixel::Polar2D<unsigned int, Angle<ByteAngle>>>
40  {
41  public:
42 #ifdef _MSC_VER
43 
46  ImageGradient(size_t w, size_t h, pixel_type val = pixel_type(0)) :
49  ImageGradient(size_t w, size_t h, const pixel_type *data):
52  template<typename Y> explicit ImageGradient(const Image<Y> &img) :
55  template<typename Y> ImageGradient(const Image<Y> &img, const Rect &bbox) :
57 #else
59 #endif
60 
61  ImageGradient(const ImageGradient&) = default;
62  ImageGradient(ImageGradient&&) = default;
63 
64  ImageGradient& operator=(const ImageGradient&) = default;
66 
67  virtual ~ImageGradient() override {}
68 
70  unsigned int GetMinModule() const noexcept { return thresh; }
72  void SetMinModule(unsigned int m) { thresh = m; }
74  unsigned int AutoMinModule(const ImageGray &img);
75 
81  inline bool IsSignificant(size_t i) const { return At(i).rho >= thresh; }
88  inline bool IsSignificant(size_t x, size_t y) const { return At(x, y).rho >= thresh; }
89 
91  ImageGray MakeImageGray() const;
93  ImageRGB MakeImageRGB(bool thres = false) const;
95  ImageGray MakeCurvature() const;
97  ImageBW MakeMask() const;
98 
100  double GetHRun() const noexcept;
102  double GetVRun() const noexcept;
103 
104  private:
105  unsigned int thresh;
106  };
107 
109 }
110 #endif
Abstract class for images.
Definition: CRNImage.h:141
virtual ~ImageGradient() override
std::vector< pixel_type >::reference At(size_t x, size_t y) noexcept
Returns a reference to a pixel.
Definition: CRNImage.h:224
ImageBW MakeMask() const
Create a mask of the gradients' module.
bool IsSignificant(size_t x, size_t y) const
Tests if a pixel has a significant gradient.
ImageGradient(const ImageGradient &)=default
double GetHRun() const noexcept
Estimates the mean character width.
ImageGray MakeCurvature() const
Creates an image representing the curvature of the gradients.
ImageGray MakeImageGray() const
Converts to a gray image.
ImageRGB MakeImageRGB(bool thres=false) const
Converts to a rgb image.
void SetMinModule(unsigned int m)
Sets the module significance threshold.
Gradient image in polar form.
bool IsSignificant(size_t i) const
Tests if a pixel has a significant gradient.
ImageGradient & operator=(const ImageGradient &)=default
unsigned int GetMinModule() const noexcept
Returns the module significance threshold.
unsigned int AutoMinModule(const ImageGray &img)
Computes the module significance threshold.
CRN_ALIAS_SMART_PTR(ImageBW)
pixel::Polar2D< unsigned int, Angle< ByteAngle > > pixel_type
Definition: CRNImage.h:144
double GetVRun() const noexcept
Estimates the mean character height.
A rectangle class.
Definition: CRNRect.h:46