Code Monkey home page Code Monkey logo

brandonmpetty / doxa Goto Github PK

View Code? Open in Web Editor NEW
164.0 11.0 37.0 5.52 MB

A Local Adaptive Thresholding framework for image binarization written in C++, with JS and Python bindings. Implementing: Otsu, Bernsen, Niblack, Sauvola, Wolf, Gatos, NICK, Su, T.R. Singh, WAN, ISauvola, Bataineh, Chan and Shafait.

Home Page: https://brandonmpetty.github.io/Doxa/WebAssembly

License: Creative Commons Zero v1.0 Universal

C++ 87.24% JavaScript 6.38% Python 1.85% Jupyter Notebook 3.91% CMake 0.63%
binarization

doxa's People

Contributors

brandonmpetty avatar dobatymo avatar paulbauriegel avatar stweil avatar visualfox avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

doxa's Issues

Malformed output with “zebra stripes” due to a bug in `PNM.hpp`

Hello,

I'm testing Doxa for converting color or grayscale book scans to bilevel images. I would say that 95% of time, it works, but 5% of time, Doxa produces malformed output with “zebra stripes” for lack of a better term. Here is how this output looks:

output pbm

The code I’m using is very basic:

        Doxa::Image doxaGsImage = Doxa::PNM::Read(input);
        Doxa::ISauvola::UpdateToBinary(doxaGsImage);
        Doxa::PNM::Write(doxaGsImage, output);

Thank you in advance for looking into this issue.

Please find attached, as ZIP file, a sample showing the problem. The ZIP file contains:

  • input.png — the original book scan
  • input.png.ppm — the original converted to PPM, so it can be opened using Doxa::PNM::Read
  • output.pbm — the malformed output

Sample.zip

version of c++

HI,

I try to run BinaryImageConverter.cpp on Clion but it have trouble:
Binarization/Image.hpp:127:47: error: expected ‘,’ or ‘...’ before ‘default’
inline Pixel32 Pixel(int x, int y, Pixel32 default) const { return (x < 0 || x >= width || y < 0 || y >= height) ? default: Pixel(x, y); }

Binarization/Image.hpp:127:119: error: expected ‘:’ before ‘default’
Binarization/Image.hpp:127:119: error: expected primary-expression before ‘default’
Binarization/Image.hpp:127:119: error: expected ‘;’ before ‘default’
Binarization/Image.hpp:127:119: error: case label not within a switch statement

I am using c++ 11: set(CMAKE_CXX_STANDARD 11)

Thanks

Wan algorithm is slowly if window size more than 17?

I test Doxa::Wan::UpdateToBinary(doxaGsImage, parameters); release
Wan algorithm is slowly if window size more than 17?

time , size k=0.1
0.136 , 6
0.133 , 7
0.178 , 8
0.171 , 9
0.227 , 10
0.231 , 11
0.286 , 12
0.287 , 13
0.343 , 14
0.339 , 15
0.402 , 16
0.601 , 17
0.601 , 18
0.620 , 19
0.620 , 20
0.621 , 21
0.617 , 22
0.635 , 23
0.638 , 24
0.633 , 25
0.641 , 26
0.641 , 27
0.637 , 28
0.653 , 29
0.653 , 30
0.657 , 31
0.647 , 32
0.661 , 33
0.672 , 34
0.680 , 35
0.666 , 36

Thank you

Just wanted to let you know that I really appreciate your work. I like the new additions, and the general code structure. Performance is now really good and ISauvola give me some nice results (as a low hanging fruit I tried IWolf and IWan they work great too).

I am currently testing Doxa with via a javascript frontend (Doxa is compiled into Webassembly with emscripten) and everything is running great. If you are interested I will be happy to show you more of that or setup a small demo.

Unfortunately as I cannot find a way to send you a Private Message I am abusing the Github issues system, I hope that ok.

building with Pybind11 on Windows

Hi again, @brandonmpetty!

You helped me get the 'R' version going back in August, and then recently kindly chimed in on an old issue I raised on @paulbauriegel's cython doxa (https://github.com/paulbauriegel/doxa_cython). (Ty!)

I am trying to build doxa with pybind11 per the readme in your repo.

When i get to the cmake .. step (in Windows 10, Visual Studio Code), I get
The term 'cmake' is not recognized as the name of a cmdlet, function, script file, or operable program
I tried adding the cmake extension. But no difference. (Disclaimer: any time I've tried to do anything with c-anything, I've had little success -- typically more complicated than I really know how to do, hours spent, and very little results. I'm more at the level of "pip install" and the like. :) )

Documentation - Parameter Defaults

We need to document the parameter defaults for each algorithm, and other algorithms.
Create a Wiki that describes how to use the API and its options, along with how each Algorithm works.

Algorithm Parameters

Otsu
Bataineh
	No parameters

Niblack
Sauvola
ISauvola
TRSingh
Wan
Wolf
	name: "window", default: 75
	name: "k", default: 0.2

NICK
	name: "window", default: 75
	name: "k", default: -0.2

Bernsen
	name: "window", default: 75
	name: "threshold", default: 100
	name: "contrast-limit", default: 25

Gatos
	name: "glyph", default: 60
	
Su *
	name: "window", default: 0 = Auto-Detect
	name: "minN", default: value of "window"
	
* Su - A "window" value of 0 will cause the algorithm to auto-detect based on stroke width.  This is not currently implemented so a default value of 9 is currently being used.

PNM Parameters

This is for C++ only

PNM::Read *
	name: "grayscale", default: Mean

* "grayscale" algorithm options include: Qt, Mean, BT601, BT709, BT2100, Value, Luster, Lightness

std::get on Mac OS

Hello there

I've made an R wrapper around this package as I needed it in some preprocessing for handwritten text recognition. Package was published today on CRAN at https://cran.r-project.org/web/packages/image.binarization/index.html, source code has been put at https://github.com/DIGI-VUB/image.binarization
Putting a package on CRAN also means I have to maintain it and fixing possible issues. One of the issues appearing is that CRAN tests on various platforms (windows / debian / solaris / mac) with different compiler settings.
When testing on Mac OS (version 10.13), I'm getting the following compilation issue indicating std::get is only available in Mac OS 10.14. That's unfortunate given that I have no option to update Mac OS on CRAN to something higher. Hence my question, what would be a good way to solve this, such that it works on Mac OS 10.13 which does not have std::get. See below the compilation trace.
Thanks for the help!

* installing *source* package ‘image.binarization’ ...
** package ‘image.binarization’ successfully unpacked and MD5 sums checked
** using staged installation
** libs
clang++ -mmacosx-version-min=10.13 -std=gnu++17 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG  -I'/Users/user9yOn5yDN/R/Rcpp/include' -I/usr/local/include   -fPIC  -Wall -g -O2  -c RcppExports.cpp -o RcppExports.o
clang++ -mmacosx-version-min=10.13 -std=gnu++17 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG  -I'/Users/user9yOn5yDN/R/Rcpp/include' -I/usr/local/include   -fPIC  -Wall -g -O2  -c _rcpp_doxa.cpp -o _rcpp_doxa.o
In file included from _rcpp_doxa.cpp:4:
In file included from ./Doxa/Algorithm.hpp:7:
./Doxa/Parameters.hpp:36:12: error: call to unavailable function 'get': introduced in macOS 10.14
                                return std::get<Type>(pos->second);
                                       ^~~~~~~~~~~~~~
./Doxa/Bernsen.hpp:30:38: note: in instantiation of function template specialization 'Doxa::Parameters::Get<int>' requested here
                        const int windowSize = parameters.Get("window", 75);
                                                          ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/variant:1393:22: note: candidate function [with _Tp = int, _Types = <int, double>] has been explicitly made unavailable
constexpr const _Tp& get(const variant<_Types...>& __v) {
                     ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/variant:1401:23: note: candidate function [with _Tp = int, _Types = <int, double>] not viable: no known conversion from 'const std::__1::variant<int, double>' to 'const variant<int, double> &&' for 1st argument
constexpr const _Tp&& get(const variant<_Types...>&& __v) {
                      ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/utility:780:17: note: candidate template ignored: could not match 'pair' against 'variant'
constexpr _T1 & get(pair<_T1, _T2>& __p) _NOEXCEPT
                ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/utility:787:23: note: candidate template ignored: could not match 'pair' against 'variant'
constexpr _T1 const & get(pair<_T1, _T2> const& __p) _NOEXCEPT
                      ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/utility:794:18: note: candidate template ignored: could not match 'pair' against 'variant'
constexpr _T1 && get(pair<_T1, _T2>&& __p) _NOEXCEPT
                 ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/utility:801:24: note: candidate template ignored: could not match 'pair' against 'variant'
constexpr _T1 const && get(pair<_T1, _T2> const&& __p) _NOEXCEPT
                       ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/utility:808:17: note: candidate template ignored: could not match 'pair' against 'variant'
constexpr _T1 & get(pair<_T2, _T1>& __p) _NOEXCEPT
                ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/utility:815:23: note: candidate template ignored: could not match 'pair' against 'variant'
constexpr _T1 const & get(pair<_T2, _T1> const& __p) _NOEXCEPT
                      ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/utility:822:18: note: candidate template ignored: could not match 'pair' against 'variant'
constexpr _T1 && get(pair<_T2, _T1>&& __p) _NOEXCEPT
                 ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/utility:829:24: note: candidate template ignored: could not match 'pair' against 'variant'
constexpr _T1 const && get(pair<_T2, _T1> const&& __p) _NOEXCEPT
                       ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/tuple:1035:16: note: candidate template ignored: could not match 'tuple' against 'variant'
constexpr _T1& get(tuple<_Args...>& __tup) noexcept
               ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/tuple:1042:22: note: candidate template ignored: could not match 'tuple' against 'variant'
constexpr _T1 const& get(tuple<_Args...> const& __tup) noexcept
                     ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/tuple:1049:17: note: candidate template ignored: could not match 'tuple' against 'variant'
constexpr _T1&& get(tuple<_Args...>&& __tup) noexcept
                ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/tuple:1056:23: note: candidate template ignored: could not match 'tuple' against 'variant'
constexpr _T1 const&& get(tuple<_Args...> const&& __tup) noexcept
                      ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/variant:1376:16: note: candidate template ignored: deduced type 'variant<...>' of 1st parameter does not match adjusted type 'const variant<...>' of argument [with _Tp = int, _Types = <int, double>]
constexpr _Tp& get(variant<_Types...>& __v) {
               ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/variant:1384:17: note: candidate template ignored: deduced type 'variant<...>' of 1st parameter does not match adjusted type 'const variant<...>' of argument [with _Tp = int, _Types = <int, double>]
constexpr _Tp&& get(variant<_Types...>&& __v) {
                ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/utility:746:1: note: candidate template ignored: invalid explicitly-specified argument for template parameter '_Ip'
get(pair<_T1, _T2>& __p) _NOEXCEPT
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/utility:754:1: note: candidate template ignored: invalid explicitly-specified argument for template parameter '_Ip'
get(const pair<_T1, _T2>& __p) _NOEXCEPT
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/utility:763:1: note: candidate template ignored: invalid explicitly-specified argument for template parameter '_Ip'
get(pair<_T1, _T2>&& __p) _NOEXCEPT
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/utility:771:1: note: candidate template ignored: invalid explicitly-specified argument for template parameter '_Ip'
get(const pair<_T1, _T2>&& __p) _NOEXCEPT
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/tuple:958:1: note: candidate template ignored: invalid explicitly-specified argument for template parameter '_Ip'
get(tuple<_Tp...>& __t) _NOEXCEPT
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/tuple:967:1: note: candidate template ignored: invalid explicitly-specified argument for template parameter '_Ip'
get(const tuple<_Tp...>& __t) _NOEXCEPT
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/tuple:976:1: note: candidate template ignored: invalid explicitly-specified argument for template parameter '_Ip'
get(tuple<_Tp...>&& __t) _NOEXCEPT
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/tuple:986:1: note: candidate template ignored: invalid explicitly-specified argument for template parameter '_Ip'
get(const tuple<_Tp...>&& __t) _NOEXCEPT
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/array:307:1: note: candidate template ignored: invalid explicitly-specified argument for template parameter '_Ip'
get(array<_Tp, _Size>& __a) _NOEXCEPT
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/array:316:1: note: candidate template ignored: invalid explicitly-specified argument for template parameter '_Ip'
get(const array<_Tp, _Size>& __a) _NOEXCEPT
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/array:327:1: note: candidate template ignored: invalid explicitly-specified argument for template parameter '_Ip'
get(array<_Tp, _Size>&& __a) _NOEXCEPT
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/array:336:1: note: candidate template ignored: invalid explicitly-specified argument for template parameter '_Ip'
get(const array<_Tp, _Size>&& __a) _NOEXCEPT
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/variant:1336:59: note: candidate template ignored: invalid explicitly-specified argument for template parameter '_Ip'
constexpr variant_alternative_t<_Ip, variant<_Types...>>& get(
                                                          ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/variant:1346:60: note: candidate template ignored: invalid explicitly-specified argument for template parameter '_Ip'
constexpr variant_alternative_t<_Ip, variant<_Types...>>&& get(
                                                           ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/variant:1356:65: note: candidate template ignored: invalid explicitly-specified argument for template parameter '_Ip'
constexpr const variant_alternative_t<_Ip, variant<_Types...>>& get(
                                                                ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/variant:1366:66: note: candidate template ignored: invalid explicitly-specified argument for template parameter '_Ip'
constexpr const variant_alternative_t<_Ip, variant<_Types...>>&& get(
                                                                 ^
In file included from _rcpp_doxa.cpp:4:
In file included from ./Doxa/Algorithm.hpp:7:
./Doxa/Parameters.hpp:36:12: error: call to unavailable function 'get': introduced in macOS 10.14
                                return std::get<Type>(pos->second);
                                       ^~~~~~~~~~~~~~
./Doxa/Sauvola.hpp:32:32: note: in instantiation of function template specialization 'Doxa::Parameters::Get<double>' requested here
                        const double k = parameters.Get("k", 0.2);
                                                    ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/variant:1393:22: note: candidate function [with _Tp = double, _Types = <int, double>] has been explicitly made unavailable
constexpr const _Tp& get(const variant<_Types...>& __v) {
                     ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/variant:1401:23: note: candidate function [with _Tp = double, _Types = <int, double>] not viable: no known conversion from 'const std::__1::variant<int, double>' to 'const variant<int, double> &&' for 1st argument
constexpr const _Tp&& get(const variant<_Types...>&& __v) {
                      ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/utility:780:17: note: candidate template ignored: could not match 'pair' against 'variant'
constexpr _T1 & get(pair<_T1, _T2>& __p) _NOEXCEPT
                ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/utility:787:23: note: candidate template ignored: could not match 'pair' against 'variant'
constexpr _T1 const & get(pair<_T1, _T2> const& __p) _NOEXCEPT
                      ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/utility:794:18: note: candidate template ignored: could not match 'pair' against 'variant'
constexpr _T1 && get(pair<_T1, _T2>&& __p) _NOEXCEPT
                 ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/utility:801:24: note: candidate template ignored: could not match 'pair' against 'variant'
constexpr _T1 const && get(pair<_T1, _T2> const&& __p) _NOEXCEPT
                       ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/utility:808:17: note: candidate template ignored: could not match 'pair' against 'variant'
constexpr _T1 & get(pair<_T2, _T1>& __p) _NOEXCEPT
                ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/utility:815:23: note: candidate template ignored: could not match 'pair' against 'variant'
constexpr _T1 const & get(pair<_T2, _T1> const& __p) _NOEXCEPT
                      ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/utility:822:18: note: candidate template ignored: could not match 'pair' against 'variant'
constexpr _T1 && get(pair<_T2, _T1>&& __p) _NOEXCEPT
                 ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/utility:829:24: note: candidate template ignored: could not match 'pair' against 'variant'
constexpr _T1 const && get(pair<_T2, _T1> const&& __p) _NOEXCEPT
                       ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/tuple:1035:16: note: candidate template ignored: could not match 'tuple' against 'variant'
constexpr _T1& get(tuple<_Args...>& __tup) noexcept
               ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/tuple:1042:22: note: candidate template ignored: could not match 'tuple' against 'variant'
constexpr _T1 const& get(tuple<_Args...> const& __tup) noexcept
                     ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/tuple:1049:17: note: candidate template ignored: could not match 'tuple' against 'variant'
constexpr _T1&& get(tuple<_Args...>&& __tup) noexcept
                ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/tuple:1056:23: note: candidate template ignored: could not match 'tuple' against 'variant'
constexpr _T1 const&& get(tuple<_Args...> const&& __tup) noexcept
                      ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/variant:1376:16: note: candidate template ignored: deduced type 'variant<...>' of 1st parameter does not match adjusted type 'const variant<...>' of argument [with _Tp = double, _Types = <int, double>]
constexpr _Tp& get(variant<_Types...>& __v) {
               ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/variant:1384:17: note: candidate template ignored: deduced type 'variant<...>' of 1st parameter does not match adjusted type 'const variant<...>' of argument [with _Tp = double, _Types = <int, double>]
constexpr _Tp&& get(variant<_Types...>&& __v) {
                ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/utility:746:1: note: candidate template ignored: invalid explicitly-specified argument for template parameter '_Ip'
get(pair<_T1, _T2>& __p) _NOEXCEPT
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/utility:754:1: note: candidate template ignored: invalid explicitly-specified argument for template parameter '_Ip'
get(const pair<_T1, _T2>& __p) _NOEXCEPT
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/utility:763:1: note: candidate template ignored: invalid explicitly-specified argument for template parameter '_Ip'
get(pair<_T1, _T2>&& __p) _NOEXCEPT
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/utility:771:1: note: candidate template ignored: invalid explicitly-specified argument for template parameter '_Ip'
get(const pair<_T1, _T2>&& __p) _NOEXCEPT
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/tuple:958:1: note: candidate template ignored: invalid explicitly-specified argument for template parameter '_Ip'
get(tuple<_Tp...>& __t) _NOEXCEPT
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/tuple:967:1: note: candidate template ignored: invalid explicitly-specified argument for template parameter '_Ip'
get(const tuple<_Tp...>& __t) _NOEXCEPT
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/tuple:976:1: note: candidate template ignored: invalid explicitly-specified argument for template parameter '_Ip'
get(tuple<_Tp...>&& __t) _NOEXCEPT
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/tuple:986:1: note: candidate template ignored: invalid explicitly-specified argument for template parameter '_Ip'
get(const tuple<_Tp...>&& __t) _NOEXCEPT
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/array:307:1: note: candidate template ignored: invalid explicitly-specified argument for template parameter '_Ip'
get(array<_Tp, _Size>& __a) _NOEXCEPT
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/array:316:1: note: candidate template ignored: invalid explicitly-specified argument for template parameter '_Ip'
get(const array<_Tp, _Size>& __a) _NOEXCEPT
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/array:327:1: note: candidate template ignored: invalid explicitly-specified argument for template parameter '_Ip'
get(array<_Tp, _Size>&& __a) _NOEXCEPT
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/array:336:1: note: candidate template ignored: invalid explicitly-specified argument for template parameter '_Ip'
get(const array<_Tp, _Size>&& __a) _NOEXCEPT
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/variant:1336:59: note: candidate template ignored: invalid explicitly-specified argument for template parameter '_Ip'
constexpr variant_alternative_t<_Ip, variant<_Types...>>& get(
                                                          ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/variant:1346:60: note: candidate template ignored: invalid explicitly-specified argument for template parameter '_Ip'
constexpr variant_alternative_t<_Ip, variant<_Types...>>&& get(
                                                           ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/variant:1356:65: note: candidate template ignored: invalid explicitly-specified argument for template parameter '_Ip'
constexpr const variant_alternative_t<_Ip, variant<_Types...>>& get(
                                                                ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/variant:1366:66: note: candidate template ignored: invalid explicitly-specified argument for template parameter '_Ip'
constexpr const variant_alternative_t<_Ip, variant<_Types...>>&& get(
                                                                 ^
2 errors generated.
make: *** [_rcpp_doxa.o] Error 1
ERROR: compilation failed for package ‘image.binarization’
* removing ‘/Users/user9yOn5yDN/R/image.binarization’

`#include "Morphology.hpp"` is missing from `Wan.hpp`

Hello,

The Wan algorithm won't compile, because it makes uses of a morphology function:

Morphology::Dilate(maxImage, Algorithm::grayScaleImageIn, windowSize);

and yet, #include "Morphology.hpp" is missing from Wan.hpp.

Luckily, the fix is easy. The relevant include simply has to be added.

Hope this helps!

Using on Windows

Has anyone had success using this on Windows?

If so, would you be willing to give simple instructions to a total beginner about how to get it up and running?

Any guidance would be much appreciated!

(Windows 10)

pseudo F-measure, single metrics in Doxapy, and `eps` for numerical stability?

Hi @brandonmpetty,

Thanks for the awesome package. I have been experimenting with different neural networks architectures for document image binarization (DIBCO), and after trying multiple implementations of DIBCO metrics, yours are much faster, accelerating the training loop (using Hugging Face transformers' trainer API) by a few orders of magnitude.

Below I will leave a few open points or requests, but let me know if you want me to open separate issues:

  • how does the library handle potential division by zero while computing the metrics (PSNR, F-measure, DRD)? I am used to seeing those metrics implemented with a little margin $\epsilon$ as arg to account for numerical stability.
  • personally, I am using the library just for eval with DIBCO metrics using the Python bindings. Therefore, I think it would be beneficial if the bindings exposed single DIBCO metrics other than the all-in-one calculate_performance function.
  • will you add the pseudo F-measure metric to the suite of metrics? It is quite common in DIBCO eval, and one of those metrics that can really suffer from bad implementation, as DRD does. I will attach a sample Python implementation:
import numpy as np
import numpy.typing as np_typing

import scipy


Bitmap = np_typing.NDArray[np.bool_]


G123_LUT = np.array([
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 
    0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
    0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
    1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
    1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
    0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
    1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 
    1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
    1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0
], dtype=bool)

G123P_LUT = np.array([
    0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
    0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
    0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
    0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
    0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
    1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
], dtype=bool)


def bwmorph_thin(bitmap: Bitmap, num_iters: int = -1) -> Bitmap:
    """The bwmorph thinning algorithm 
    
    For more information on the algorithm, see 
    https://it.mathworks.com/help/images/ref/bwmorph.html#bui7chk-1
    """
    if bitmap.ndim not in [2, 3]: 
        raise ValueError("The bitmap must be a 2D array or a batched 3D tensor")
        
    if not np.all(np.in1d(bitmap.flat, (0, 1))):
        raise ValueError("The bitmap contains values other than 0 and 1")

    if num_iters <= 0 and num_iters != -1:
        raise ValueError("num_iters must be > 0 or equal to -1")

    bitmap = np.array(bitmap).astype(np.uint8)
    
    batched3d = bitmap.ndim == 3
    
    if not batched3d:
        bitmap = np.expand_dims(bitmap, 0)
 
    # The neighborhood kernel
    kernel = np.array([
        [ 8,  4,   2],
        [16,  0,   1],
        [32, 64, 128]
    ], dtype=np.uint8)
    
    finished = np.zeros(bitmap.shape[0], dtype=bool)

    batch_size = bitmap.shape[0]
    num_pixels_before = np.sum(bitmap, axis=(1, 2))

    while num_iters != 0:
        # The two subiterations
        for lut in [G123_LUT, G123P_LUT]:
            for idx in range(batch_size):  # It is faster than the batched operation
                if finished[idx]:
                    continue

                N = scipy.ndimage.correlate(bitmap[idx], kernel, mode="constant")
                D = np.take(lut, N)
                
                bitmap[idx][D] = 0

        num_pixels = np.sum(bitmap, axis=(1, 2))
        
        finished = num_pixels == num_pixels_before

        if np.all(finished):
            break

        num_pixels_before = num_pixels
        
        num_iters -= 1
    
    if not batched3d:
        bitmap = np.squeeze(bitmap, axis=0)

    return bitmap.astype(bool)

def pseudo_fmeasure(references: Bitmap, preds: Bitmap, eps: float = 1e-6, **kwargs) -> np_typing.NDArray[np.float_]:
    """The pseudo F-measure metric"""
    neg_references = 1 - references
    neg_preds = 1 - preds
    
    skeletons = bwmorph_thin(neg_references, **kwargs).astype(np.uint8)
        
    tpositives = neg_preds * neg_references
    fpositives = neg_preds * references
    
    num_tpositives = np.sum(tpositives, axis=(1, 2))
    num_fpositives = np.sum(fpositives, axis=(1, 2))
    
    precision = num_tpositives / (num_fpositives + num_tpositives + eps)
    
    pseudo_tpositives = neg_preds * skeletons
    pseudo_fnegatives = preds * skeletons
    
    num_pseudo_tpositives = np.sum(pseudo_tpositives, axis=(1, 2))
    num_pseudo_fnegatives = np.sum(pseudo_fnegatives, axis=(1, 2))
    
    pseudo_recall = num_pseudo_tpositives / (num_pseudo_fnegatives + num_pseudo_tpositives + eps)
    
    pseudo_nume = 2 * (precision * pseudo_recall)
    pseudo_deno = precision + pseudo_recall + eps
    
    pseudo_score = pseudo_nume / pseudo_deno
    return pseudo_score

skewed large images

Thank you for this great library, it's very well put together and easy to use and understand. I'm doing a personal project, restarting after a very long time and this library will save me time so I can focus on what I'm doing.

When I use a large file, the binary result shows skewed lines thorough out the whole file. After I scaled the file in half it worked ok. The original file was 1800x1200 pixels.

specifying binarization method in python

Hello!

I'm trying to specify binarization methods and/or use all at once using demo.py as my starter template.

Here's the latest that I tried:

# Loop through all binarization algorithms
binarize_algos = [BERNSEN, NIBLACK, SAUVOLA, WOLF, NICK, SU, TRSINGH, BATAINEH, ISAUVOLA, WAN, GATOS]
for ba in binarize_algos:
    algo = doxapy.Binarization(doxapy.Binarization.Algorithms.ba)
    algo.initialize(grayscale_image)
    algo.to_binary(binary_image, {"window": 75, "k": 0.2}) # algorithm params are optional

    # Display our resulting image
    Image.fromarray(binary_image).show()

I also tried with the list's methods in quotes, mixed in with 3 or so variations on this line:
algo = doxapy.Binarization(doxapy.Binarization.Algorithms.ba)
(str(ba), for example, pluses (for both str(ba) and just ba like you see above)

Any idea what I'm doing wrong?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.