Read@CVL
Binarization.h
Go to the documentation of this file.
1 /*******************************************************************************************************
2  ReadFramework is the basis for modules developed at CVL/TU Wien for the EU project READ.
3 
4  Copyright (C) 2016 Markus Diem <diem@caa.tuwien.ac.at>
5  Copyright (C) 2016 Stefan Fiel <fiel@caa.tuwien.ac.at>
6  Copyright (C) 2016 Florian Kleber <kleber@caa.tuwien.ac.at>
7 
8  This file is part of ReadFramework.
9 
10  ReadFramework is free software: you can redistribute it and/or modify
11  it under the terms of the GNU General Public License as published by
12  the Free Software Foundation, either version 3 of the License, or
13  (at your option) any later version.
14 
15  ReadFramework is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  GNU General Public License for more details.
19 
20  You should have received a copy of the GNU General Public License
21  along with this program. If not, see <http://www.gnu.org/licenses/>.
22 
23  The READ project has received funding from the European Union’s Horizon 2020
24  research and innovation programme under grant agreement No 674943
25 
26  related links:
27  [1] http://www.caa.tuwien.ac.at/cvl/
28  [2] https://transkribus.eu/Transkribus/
29  [3] https://github.com/TUWien/
30  [4] http://nomacs.org
31  *******************************************************************************************************/
32 
33 #pragma once
34 
35 #include "BaseModule.h"
36 
37 #pragma warning(push, 0) // no warnings from includes
38 #include <QObject>
39 
40 #include <opencv2/core.hpp>
41 #pragma warning(pop)
42 
43 
44 #pragma warning (disable: 4251) // inlined Qt functions in dll interface
45 
46 #ifndef DllCoreExport
47 #ifdef DLL_CORE_EXPORT
48 #define DllCoreExport Q_DECL_EXPORT
49 #else
50 #define DllCoreExport Q_DECL_IMPORT
51 #endif
52 #endif
53 
54 // Qt defines
55 
56 namespace rdf {
57 
59 
60 public:
62 
63  int thresh();
64 
65  virtual QString toString() const override;
66 
67 protected:
68  // parameters
69  int mThresh = 100;
70 
71  void load(const QSettings& settings) override;
72  void save(QSettings& settings) const override;
73 };
74 
75 // read defines
81 
82 public:
83  SimpleBinarization(const cv::Mat& img);
84 
85  bool isEmpty() const override;
86  bool compute() override;
87  cv::Mat binaryImage() const;
88  QString toString() const override;
89 
90  QSharedPointer<SimpleBinarizationConfig> config() const;
91 
92 private:
93  cv::Mat mSrcImg;
94  cv::Mat mBwImg;
95 
96  bool checkInput() const override;
97 
98 };
99 
101 
102 public:
104 
105  int erodedMaskSize() const;
106  void setErodedMaskSize(int s);
107 
108  QString toString() const override;
109 
110 private:
111  void load(const QSettings& settings) override;
112  void save(QSettings& settings) const override;
113 
114  int mErodeMaskSize = 3 * 6; //size for the boundary erosion
115 };
116 
123 
124 public:
125  BaseBinarizationSu(const cv::Mat& img, const cv::Mat& mask = cv::Mat());
126 
127  bool isEmpty() const override;
128  virtual bool compute() override;
129  cv::Mat binaryImage() const;
130  virtual QString toString() const override;
131  void setPreFiltering(bool preFilter = true, int preFilterSize = 10);
132 
133  QSharedPointer<BaseBinarizationSuConfig> config() const;
134 
135 protected:
136  cv::Mat compContrastImg(const cv::Mat& srcImg, const cv::Mat& mask) const;
137  cv::Mat compBinContrastImg(const cv::Mat& contrastImg) const;
138  virtual float contrastVal(const unsigned char* maxVal, const unsigned char * minVal) const;
139  virtual void calcFilterParams(int &filterS, int &Nm);
140  virtual float strokeWidth(const cv::Mat& contrastImg) const;
141  virtual float thresholdVal(float *mean, float *std) const;
142  void computeDistHist(const cv::Mat& src, QList<int> *maxDiffList, QList<float> *localIntensity) const;
143  void computeThrImg(const cv::Mat& grayImg32F, const cv::Mat& binContrast, cv::Mat& thresholdImg, cv::Mat& thresholdContrastPxImg);
144  bool checkInput() const override;
145  //void compThrImg();
146  //void compDisHist();
147 
148  cv::Mat mSrcImg; //the input image either 3 channel or 1 channel [0 255]
149  cv::Mat mBwImg; //the binarized image [0 255]
150  cv::Mat mMask; //the mask image [0 255]
151  //cv::Mat mContrastImg;
152  //cv::Mat mBinContrastImg;
153  //cv::Mat mThrImg;
154 
155  bool mPreFilter = true;
156  int mPreFilterSize = 10;
157  float mStrokeW = 4; //estimated strokeWidth
158 
159 };
160 
168 
169 public:
170  BinarizationSuAdapted(const cv::Mat& img, const cv::Mat& mask = cv::Mat());
171 
172  virtual bool compute() override;
173  virtual QString toString() const override;
174  void setFiltering(bool medianFilter);
175 
176 protected:
177  float setStrokeWidth(float strokeW);
178  virtual float thresholdVal(float *mean, float *std) const;
179  virtual float contrastVal(const unsigned char* maxVal, const unsigned char * minVal) const override;
180  virtual void calcFilterParams(int &filterS, int &Nm) override;
181 
182  cv::Mat mContrastImg;
184  cv::Mat mThrImg;
185 private:
186  bool mMedianFilter = true;
187 };
188 
189 
197 
198 public:
199  BinarizationSuFgdWeight(const cv::Mat& img, const cv::Mat& mask = cv::Mat());
200 
201  virtual bool compute() override;
202 
203 protected:
204  cv::Mat computeFgd() const;
205  cv::Mat computeMeanFgdEst(const cv::Mat& grayImg32F, const cv::Mat& mask) const;
206  cv::Scalar computeConfidence() const;
207  //virtual void init();
208  virtual void weightFunction(cv::Mat& grayImg, cv::Mat& thrImg, const cv::Mat& mask);
209 
210  int mFgdEstFilterSize = 32; //the filter size for the foreground estimation
211  float mSigmSlope = 15.0f;
212  cv::Mat mFgdEstImg;
213  cv::Scalar mMeanContrast = cv::Scalar(-1.0f,-1.0f,-1.0f,-1.0f);
214  cv::Scalar mStdContrast = cv::Scalar(-1.0f,-1.0f,-1.0f,-1.0f);
215  float mConfidence = -1.0f;
216 
217 private:
218 };
219 
220 
221 
222 }
cv::Mat mSrcImg
Definition: Binarization.h:148
Definition: Binarization.h:58
Definition: BaseModule.h:63
#define DllCoreExport
Definition: BaseImageElement.h:43
cv::Mat mMask
Definition: Binarization.h:150
cv::Mat mBinContrastImg
Definition: Binarization.h:183
The class binarize a rgb color image. To make the algorithm robust against noise, the foreground is e...
Definition: Binarization.h:196
cv::Mat mContrastImg
Definition: Binarization.h:182
cv::Mat mBwImg
Definition: Binarization.h:149
A simple binarization module using a defined threshold.
Definition: Binarization.h:80
config
Definition: DependencyCollector.py:271
The class binarize a grayvalue image. The segmentation algorithm is based on "Binarization of Histori...
Definition: Binarization.h:167
DllCoreExport bool save(const QImage &img, const QString &savePath, int compression=-1)
Saves the specified QImage img.
Definition: Image.cpp:180
Definition: Binarization.h:100
DllCoreExport QImage load(const QString &path, bool *ok=0)
Definition: Image.cpp:152
cv::Mat mFgdEstImg
Definition: Binarization.h:212
This is the base class for all modules. It provides all functions which are implemented by the module...
Definition: BaseModule.h:126
cv::Mat mThrImg
Definition: Binarization.h:184
Definition: Algorithms.cpp:45
The class binarize a grayvalue image. The segmentation algorithm is based on "Binarization of Histori...
Definition: Binarization.h:122