GithubHelp home page GithubHelp logo

arnaud-ramey / voronoi Goto Github PK

View Code? Open in Web Editor NEW
94.0 12.0 36.0 58 KB

VoronoiSkeleton is a C++ class made for the fast computing of Voronoi diagrams of monochrome images. It contains different implementations of thinning algorithms.

Home Page: https://sites.google.com/site/rameyarnaud/research/c/voronoi

License: GNU Lesser General Public License v3.0

CMake 0.59% C++ 99.41%

voronoi's Introduction

voronoi

Build Status

The morphological skeleton of an image is the set of its non-zero pixels which are equidistant to its boundaries. More info on Wikipedia.

Thinning an image consits in reducing its non-zero pixels to their morphological skeleton. More info on Wikipedia.

VoronoiSkeleton is a C++ class made for the fast computing of Voronoi diagrams of monochrome images. It contains different implementations of thinning algorithms:

  • Zhang - Suen explained in 'A fast parallel algorithm for thinning digital patterns' by T.Y. Zhang and C.Y. Suen and based on this implentation

  • Guo - Hall explained in 'Parallel thinning with two sub-iteration algorithms' by Zicheng Guo and Richard Hall and based on this implentation

  • a morphological one, based on the erode() and dilate() operators. Coming from previous work by Félix Abecassis.

A special care has been given to optimize the 2 first ones. Instead of re-examining the whole image at each iteration, only the pixels of the current contour are considered. This leads to a speedup by almost 100 times on experimental tests.

Licence

LGPL v3, check file LICENCE.

Dependencies

You need the following libraries before compiling :

  • cmake ( $ sudo apt-get install cmake ),
  • GTest ( $ sudo apt-get install gtest-dev ),
  • OpenCV ( $ sudo apt-get install libopencv-dev )

How to build the program

The project is based on a CMakeLists. It is easy to build the program on a Unix computer. Go in the source folder and type:

$ mkdir build
$ cd build
$ cmake ..
$ make

For Windows users, some instructions are available on OpenCV website: http://opencv.willowgarage.com/wiki/Getting_started .

How to use the program

To display the help, from the main folder, run the generated executable 'build/test_voronoi ' with no arguments. It will display the help of the program.

Related projects

mnist-digits-as-stroke-sequences Code project to transform the well known MNIST handwritten digit images to sequences of pen strokes, in order to obtain a data set for sequence learning.

Authors

Arnaud Ramey [email protected] -- Robotics Lab, University Carlos III of Madrid

voronoi's People

Contributors

arnaud-ramey avatar superpan2015 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

Watchers

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

voronoi's Issues

Index out of range for Zhang_suen

There is a very painful bug in this class that is coming randomly. After investigating, I think the bug is here:

https://github.com/arnaud-ramey/voronoi/blob/master/src/voronoi.h#L505

        for (int row = 0; row < rows; ++row) {
          for (int col = 0; col < cols; ++col) {
            //printf("Checking (%i, %i)...\n", col, row);
            if (*skelcontour_ptr++ == ImageContour::CONTOUR &&
                voronoi_fn(skelcontour_data, iter, col, row, cols)) {

See gdb info below for the resulting index out of range.

A potential fix could be to add:

  static bool inline need_set_zhang_suen(uchar*  skeldata, int iter, int col, int row, int cols) {
if ((row-1) * cols + col-1 < 0) return false; 

But it's not fixing at the source of the problem,

Grégoire

$ gdb ./program
GNU gdb (Ubuntu 7.7.1-0ubuntu5~14.04.2) 7.7.1
Copyright (C) 2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later http://gnu.org/licenses/gpl.html
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
http://www.gnu.org/software/gdb/bugs/.
Find the GDB manual and other documentation resources online at:
http://www.gnu.org/software/gdb/documentation/.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ./courtcalibration...done.
(gdb) run ~/v/20160804_171757/cama.png
Starting program: program a.png
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Finding corners (0)
[New Thread 0x7fffe7296700 (LWP 14123)]
[New Thread 0x7fffe6a94700 (LWP 14125)]
[New Thread 0x7fffe6e95700 (LWP 14124)]

Program received signal SIGSEGV, Segmentation fault.
0x0000000000415d3b in VoronoiThinner::need_set_zhang_suen (skeldata=0x7ffff7f79020 "", iter=0, col=3, row=0, cols=256) at voronoi.h:546
546 bool p2 = skeldata[(row-1) * cols + col];
(gdb) bt
#0 0x0000000000415d3b in VoronoiThinner::need_set_zhang_suen (skeldata=0x7ffff7f79020 "", iter=0, col=3, row=0, cols=256) at voronoi.h:546
#1 0x0000000000415a78 in VoronoiThinner::thin_fast_custom_voronoi_fn (this=0x7fffffffcbf0, img=..., voronoi_fn=0x415d0b <VoronoiThinner::need_set_zhang_suen(unsigned char*, int, int, int, int)>, crop_img_before=false, max_iters=2147483647) at voronoi.h:509
#2 0x000000000041527d in VoronoiThinner::thin_zhang_suen_fast (this=0x7fffffffcbf0, img=..., crop_img_before=false, max_iters=2147483647) at voronoi.h:396
#3 0x0000000000413ab5 in VoronoiThinner::thin (this=0x7fffffffcbf0, img=..., implementation_name="zhang_suen_fast", crop_img_before=false, max_iters=2147483647) at voronoi.h:116
#4 0x0000000000409790 in CourtCalibration::findCorners (this=0x631ea0 ) at courtCalibration.cpp:730
#5 0x000000000040e502 in courtCalibrationfromImage (imgPath=0x7fffffffdb80 "a.png", w=-1, h=-1, colorType=-1, id=0, calibPath=0x0) at courtCalibration.cpp:1347
#6 0x0000000000403f4e in main ()

fatal error when make

fatal error: gtest/gtest.h: No such file or directory
#include <gtest/gtest.h>
^~~~~~~~~~~~~~~
compilation terminated.
src/CMakeFiles/voronoi.dir/build.make:65: recipe for target 'src/CMakeFiles/voronoi.dir/test_voronoi.cpp.o' failed
make[2]: *** [src/CMakeFiles/voronoi.dir/test_voronoi.cpp.o] Error 1
make[2]: Leaving directory '/home/lidong/code/voronoi/build'
CMakeFiles/Makefile2:88: recipe for target 'src/CMakeFiles/voronoi.dir/all' failed
make[1]: *** [src/CMakeFiles/voronoi.dir/all] Error 2
make[1]: Leaving directory '/home/lidong/code/voronoi/build'
Makefile:86: recipe for target 'all' failed
make: *** [all] Error 2

Dangerous code

Here is the output of g++ when following the readme instructions:

In file included from /.../voronoi/src/test_voronoi.cpp:29:
/.../voronoi/src/timer.h:73:21: error: ‘constexpr’ needed for in-class initialization of static data member ‘const Time Timer::NOTIME’ of non-integral type [-fpermissive]
   const static Time NOTIME = -1;
                     ^~~~~~
In file included from /.../voronoi/src/test_voronoi.cpp:31:
/.../voronoi/src/voronoi.h: In static member function ‘static bool VoronoiThinner::need_set_guo_hall(uchar*, int, int, int, int)’:
/.../voronoi/src/voronoi.h:578:15: warning: suggest parentheses around operand of ‘!’ or change ‘&’ to ‘&&’ or ‘!’ to ‘~’ [-Wparentheses]
     int C  = (!p2 & (p3 | p4)) + (!p4 & (p5 | p6)) +
               ^~~
/.../voronoi/src/voronoi.h:578:35: warning: suggest parentheses around operand of ‘!’ or change ‘&’ to ‘&&’ or ‘!’ to ‘~’ [-Wparentheses]
     int C  = (!p2 & (p3 | p4)) + (!p4 & (p5 | p6)) +
                                   ^~~
/.../voronoi/src/voronoi.h:579:15: warning: suggest parentheses around operand of ‘!’ or change ‘&’ to ‘&&’ or ‘!’ to ‘~’ [-Wparentheses]
              (!p6 & (p7 | p8)) + (!p8 & (p9 | p2));
               ^~~
/.../voronoi/src/voronoi.h:579:35: warning: suggest parentheses around operand of ‘!’ or change ‘&’ to ‘&&’ or ‘!’ to ‘~’ [-Wparentheses]
              (!p6 & (p7 | p8)) + (!p8 & (p9 | p2));
                                   ^~~
/.../voronoi/src/voronoi.h: In member function ‘void VoronoiThinner::thin_guo_hall_original_iter(cv::Mat&, int)’:
/.../voronoi/src/voronoi.h:745:23: warning: comparison of integer expressions of different signedness: ‘int’ and ‘unsigned int’ [-Wsign-compare]
     for (int i = 1; i < rowmax; i++)
                     ~~^~~~~~~~
/.../voronoi/src/voronoi.h:747:25: warning: comparison of integer expressions of different signedness: ‘int’ and ‘unsigned int’ [-Wsign-compare]
       for (int j = 1; j < colmax; j++)
                       ~~^~~~~~~~
/.../voronoi/src/voronoi.h:758:19: warning: suggest parentheses around operand of ‘!’ or change ‘&’ to ‘&&’ or ‘!’ to ‘~’ [-Wparentheses]
         int C  = (!p2 & (p3 | p4)) + (!p4 & (p5 | p6)) +
                   ^~~
/.../voronoi/src/voronoi.h:758:39: warning: suggest parentheses around operand of ‘!’ or change ‘&’ to ‘&&’ or ‘!’ to ‘~’ [-Wparentheses]
         int C  = (!p2 & (p3 | p4)) + (!p4 & (p5 | p6)) +
                                       ^~~
/.../voronoi/src/voronoi.h:759:19: warning: suggest parentheses around operand of ‘!’ or change ‘&’ to ‘&&’ or ‘!’ to ‘~’ [-Wparentheses]
                  (!p6 & (p7 | p8)) + (!p8 & (p9 | p2));
                   ^~~
/.../voronoi/src/voronoi.h:759:39: warning: suggest parentheses around operand of ‘!’ or change ‘&’ to ‘&&’ or ‘!’ to ‘~’ [-Wparentheses]
                  (!p6 & (p7 | p8)) + (!p8 & (p9 | p2));
                                       ^~~
/.../voronoi/src/test_voronoi.cpp: In function ‘int CLI_help(int, char**)’:
/.../voronoi/src/test_voronoi.cpp:338:25: warning: unused parameter ‘argc’ [-Wunused-parameter]
 inline int CLI_help(int argc, char** argv) {
                     ~~~~^~~~
make[2]: *** [src/CMakeFiles/voronoi.dir/build.make:66: src/CMakeFiles/voronoi.dir/test_voronoi.cpp.o] Error 1

Please, correct that code adding the explicit casts and parentheses as needed. Don't ever trust C/C++ precedence rules; they may bite you ;)

"morph" implementation bug

HI, there seems to be a bug using morph implementation. When the third arg of function "thin" is set to false, implementation set to "morph" and given a blank white picture as input, the program would stuck and never return any result.
If there's any black point, even one pixel, or the third arg is set to true there's no problem at all.
Thank you for your work!

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.