URL:
https://svn.lrde.epita.fr/svn/oln/trunk/milena/sandbox
ChangeLog:
2008-11-25 Matthieu Garrigues <garrigues(a)lrde.epita.fr>
Test skeletonization with pixel superiority index.
* garrigues/ocr/ocr_with_preprocess.cc: Apply the skeletonisation
using infomation of the grayscale image.
* garrigues/ocr/skeleton.hh: Use the pixel superiority index criteria
to detect crests.
---
ocr_with_preprocess.cc | 75 ++++++++++++++++++++++++-------------------------
skeleton.hh | 10 +++++-
2 files changed, 45 insertions(+), 40 deletions(-)
Index: trunk/milena/sandbox/garrigues/ocr/skeleton.hh
===================================================================
--- trunk/milena/sandbox/garrigues/ocr/skeleton.hh (revision 2950)
+++ trunk/milena/sandbox/garrigues/ocr/skeleton.hh (revision 2951)
@@ -92,6 +92,7 @@
unsigned nb_eq = 0;
unsigned nb_gt = 0;
+ unsigned nb_lt = 0;
for_all(n)
if (input.domain().has(n))
{
@@ -99,10 +100,15 @@
nb_eq++;
else if (dist_map(n) > dist_map(p))
nb_gt++;
+ else
+ nb_lt++;
}
- if ((nb_gt == 1 && nb_eq == 0) ||
- (nb_gt == 0))
+
+// if ((nb_gt == 1 && nb_eq == 0) ||
+// (nb_gt == 0))
+
+ if ((nb_lt + nb_eq) > 5) // Pixel Superiority index
is_crest(p) = true;
}
return is_crest;
Index: trunk/milena/sandbox/garrigues/ocr/ocr_with_preprocess.cc
===================================================================
--- trunk/milena/sandbox/garrigues/ocr/ocr_with_preprocess.cc (revision 2950)
+++ trunk/milena/sandbox/garrigues/ocr/ocr_with_preprocess.cc (revision 2951)
@@ -95,7 +95,6 @@
mln::border::thickness = 0;
io::pbm::load(input, argv[1]);
-// OCR_TEST(input);
// Resize
image2d<int_u8> enlarged = enlarge(logical::not_(input), 2);
@@ -105,64 +104,64 @@
// Blur.
image2d<int_u8> blur = linear::gaussian(enlarged, 2);
-
io::pgm::save(blur, std::string(argv[2]) + "_2_gaussian.pgm");
OCR_TEST(blur);
- // Threshold
- image2d<bool> binary;
- {
- initialize(binary, blur);
- mln_piter_(image2d<int_u8>) p(blur.domain());
- for_all(p)
- binary(p) = blur(p) > 100;
-
- io::pbm::save(binary, std::string(argv[2]) + "_3_threshold.pbm");
- OCR_TEST(binary);
- }
+// // Threshold
+// image2d<bool> binary;
+// {
+// initialize(binary, blur);
+// mln_piter_(image2d<int_u8>) p(blur.domain());
+// for_all(p)
+// binary(p) = blur(p) > 100;
+
+// io::pbm::save(binary, std::string(argv[2]) + "_3_threshold.pbm");
+// OCR_TEST(binary);
+// }
+
+// // Skeleton
+// image2d<bool> skel = skeleton(binary, 4);
+// io::pbm::save(skel, std::string(argv[2]) + "_4_skeleton.pbm");
+// OCR_TEST(skel);
+
+// // Dilation
+// win::octagon2d oct(5);
+// image2d<bool> dilate = morpho::dilation(skel, oct);
+// border::resize(dilate, 0);
+// io::pbm::save(dilate, std::string(argv[2]) + "_5_dilation.pbm");
+// OCR_TEST(dilate);
+
+// // Subsampling
+// image2d<bool> subsampled = subsampling::subsampling(dilate, dpoint2d(1,1),
2);
+// io::pbm::save(subsampled, std::string(argv[2]) + "_6_subsampling.pbm");
+// OCR_TEST(subsampled);
- // Skeleton
- image2d<bool> skel = skeleton(binary, 4);
- io::pbm::save(skel, std::string(argv[2]) + "_4_skeleton.pbm");
- OCR_TEST(skel);
+// io::pbm::save(subsampled, argv[2]);
- // Dilation
- win::octagon2d oct(5);
- image2d<bool> dilate = morpho::dilation(skel, oct);
- border::resize(dilate, 0);
- io::pbm::save(dilate, std::string(argv[2]) + "_5_dilation.pbm");
- OCR_TEST(dilate);
- // Subsampling
- image2d<bool> subsampled = subsampling::subsampling(dilate, dpoint2d(1,1), 2);
- io::pbm::save(subsampled, std::string(argv[2]) + "_6_subsampling.pbm");
- OCR_TEST(subsampled);
-
- io::pbm::save(subsampled, argv[2]);
-
-
- image2d<bool> K = crest(big, blur, c4());
+ image2d<bool> K = crest(big, blur, c8());
OCR_TEST(K);
- io::pbm::save(K, std::string(argv[2]) + "_7_K.pbm");
+ io::pbm::save(K, std::string(argv[2]) + "_6_K.pbm");
- image2d<bool> skel_on_gaussian = skeleton_with_constraint(big, 4, K,
arith::revert(blur));
+ image2d<bool> skel_on_gaussian = skeleton_with_constraint(big, 8, K,
arith::revert(blur));
OCR_TEST(skel_on_gaussian);
- io::pbm::save(skel_on_gaussian, std::string(argv[2]) +
"_8_skeleton_on_blur.pbm");
+ io::pbm::save(skel_on_gaussian, std::string(argv[2]) +
"_7_skeleton_on_gaussian.pbm");
// Dilation
+ win::octagon2d oct(5);
image2d<bool> dilate_on_gaussian = morpho::dilation(skel_on_gaussian, oct);
border::resize(dilate_on_gaussian, 0);
- io::pbm::save(dilate_on_gaussian, std::string(argv[2]) +
"_9_dilation_on_gaussian.pbm");
+ io::pbm::save(dilate_on_gaussian, std::string(argv[2]) +
"_8_dilation_on_gaussian.pbm");
OCR_TEST(dilate_on_gaussian);
// Subsampling
image2d<bool> subsampled_on_gaussian =
subsampling::subsampling(dilate_on_gaussian, dpoint2d(1,1), 2);
- io::pbm::save(subsampled_on_gaussian, std::string(argv[2]) +
"_91_subsampling_on_gaussian.pbm");
+ io::pbm::save(subsampled_on_gaussian, std::string(argv[2]) +
"_9_subsampling_on_gaussian.pbm");
OCR_TEST(subsampled_on_gaussian);
{
float score = 0;
- char* s = tesseract("fra", subsampled, &score);
+ char* s = tesseract("fra", subsampled_on_gaussian, &score);
std::cerr << "Tesseract result: (score " << score <<
")" << std::endl;
std::cout << s;
delete[] s;