Commit 902b12ce authored by Guillaume Lazzara's avatar Guillaume Lazzara
Browse files

Add some code in my sandbox.

	* milena/sandbox/lazzara/scribo/binarization_naive/main.cc,
	* milena/sandbox/lazzara/scribo/binarization_naive/toto.cc,
	* milena/sandbox/lazzara/scribo/fill_holes/main.cc,
	* milena/sandbox/lazzara/scribo/separateurs_materialises/lines_pattern.cc,
	* milena/sandbox/lazzara/scribo/skeleton_crest/main.cc,
	* milena/sandbox/lazzara/skeleton_crest/main.cc: New.
parent 79ee98c0
2010-04-30 Guillaume Lazzara <z@lrde.epita.fr>
Add some code in my sandbox.
* milena/sandbox/lazzara/scribo/binarization_naive/main.cc,
* milena/sandbox/lazzara/scribo/binarization_naive/toto.cc,
* milena/sandbox/lazzara/scribo/fill_holes/main.cc,
* milena/sandbox/lazzara/scribo/separateurs_materialises/lines_pattern.cc,
* milena/sandbox/lazzara/scribo/skeleton_crest/main.cc,
* milena/sandbox/lazzara/skeleton_crest/main.cc: New.
2010-04-30 Guillaume Lazzara <z@lrde.epita.fr>
 
Add fastest implementations in labeling::compute.
#include <mln/core/image/image2d.hh>
#include <scribo/binarization/sauvola.hh>
#include <scribo/binarization/sauvola_ms.hh>
#include <scribo/preprocessing/split_bg_fg.hh>
#include <mln/io/pbm/save.hh>
int main(int argc, char *argv[])
{
using namespace mln;
if (argc < 5)
{
std::cout << "Usage: " << argv[0] << " input.ppm w n out.pbm" << std::endl;
return 1;
}
typedef image2d<value::rgb8> I;
I ima;
io::ppm::load(ima, argv[1]);
image2d<value::int_u8>
ima_r,
ima_g,
ima_b;
scribo::preprocessing::internal::split(ima, ima_r, ima_g, ima_b);
unsigned w = atoi(argv[2]);
image2d<bool>
bin_ima_r = scribo::binarization::sauvola_ms(ima_r, w, 3, 67),
bin_ima_g = scribo::binarization::sauvola_ms(ima_g, w, 3, 67),
bin_ima_b = scribo::binarization::sauvola_ms(ima_b, w, 3, 67),
output;
initialize(output, bin_ima_r);
mln_piter_(image2d<bool>) p(output.domain());
for_all(p)
{
int ntrue = 0;
if (bin_ima_r(p))
++ntrue;
if (bin_ima_g(p))
++ntrue;
if (bin_ima_b(p))
++ntrue;
output(p) = (ntrue >= atoi(argv[3]));
}
io::pbm::save(output, argv[4]);
}
#include <mln/core/image/image2d.hh>
#include <scribo/binarization/sauvola_ms.hh>
#include <scribo/preprocessing/split_bg_fg.hh>
#include <mln/io/pbm/save.hh>
int main(int argc, char *argv[])
{
using namespace mln;
if (argc < 5)
{
std::cout << "Usage: " << argv[0] << " input.ppm w n out.pbm" << std::endl;
return 1;
}
typedef image2d<value::rgb8> I;
I ima;
io::ppm::load(ima, argv[1]);
unsigned w = atoi(argv[2]);
image2d<bool> output = scribo::binarization::sauvola_ms(ima, w, 3, 67);
io::pbm::save(output, argv[4]);
}
#include <mln/core/image/image2d.hh>
#include <mln/core/image/dmorph/image_if.hh>
#include <mln/core/alias/neighb2d.hh>
#include <mln/data/transform.hh>
#include <mln/data/convert.hh>
#include <mln/data/fill.hh>
#include <mln/data/paste.hh>
#include <mln/data/wrap.hh>
#include <mln/logical/not.hh>
#include <mln/accu/math/count.hh>
#include <mln/labeling/blobs_and_compute.hh>
#include <mln/pw/all.hh>
#include <mln/io/pbm/all.hh>
#include <mln/io/ppm/save.hh>
#include <mln/io/pgm/save.hh>
#include <mln/value/int_u16.hh>
#include <mln/value/rgb8.hh>
#include <mln/literal/colors.hh>
#include <mln/transform/influence_zone_geodesic.hh>
#include <scribo/postprocessing/fill_object_holes.hh>
int main(int argc, char *argv[])
{
using namespace mln;
typedef image2d<bool> I;
I input;
io::pbm::load(input, argv[1]);
typedef value::int_u16 L;
typedef image2d<L> Li;
typedef accu::math::count<mln_site_(Li)> A;
typedef util::couple<Li, util::couple<util::array<unsigned>,
util::array<A> > > res_t;
// Holes card Image
std::cout << "> Holes card image" << std::endl;
L nlabels;
res_t res = labeling::blobs_and_compute(input, c8(), nlabels, A());
util::array<unsigned>& holes_card = res.second().first();
image2d<unsigned>
holes = data::transform(res.first(), holes_card);
// Threshold Image
std::cout << "> Threshold image" << std::endl;
I input_i = logical::not_(input);
res = labeling::blobs_and_compute(input_i, c8(), nlabels, A());
float ratio = atof(argv[2]);
util::array<unsigned>& card = res.second().first();
for (unsigned i = 1; i < card.size(); ++i)
card(i) = card(i) * ratio;
image2d<unsigned>
thres = data::transform(res.first(), card);
thres = transform::influence_zone_geodesic(thres, c8());
// Thresholding
std::cout << "> Thresholding" << std::endl;
I hole_mask;
initialize(hole_mask, holes);
data::fill(hole_mask, false);
mln_piter_(I) p(input.domain());
for_all(p)
if (holes(p))
hole_mask(p) = holes(p) < thres(p);
io::pbm::save(hole_mask, "hole_mask.pbm");
// Diff
std::cout << "> Diff" << std::endl;
image2d<value::rgb8> diff = data::convert(value::rgb8(), input);
data::fill((diff | pw::value(hole_mask)).rw(), literal::red);
io::ppm::save(diff, "diff.ppm");
// Cleanup
std::cout << "> Cleanup" << std::endl;
data::fill((input | pw::value(hole_mask)).rw(), false);
io::pbm::save(input, argv[3]);
}
// Copyright (C) 2010 EPITA Research and Development Laboratory (LRDE)
//
// This file is part of Olena.
//
// Olena is free software: you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free
// Software Foundation, version 2 of the License.
//
// Olena is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Olena. If not, see <http://www.gnu.org/licenses/>.
//
// As a special exception, you may use this file as part of a free
// software project without restriction. Specifically, if other files
// instantiate templates or use macros or inline functions from this
// file, or you compile this file and link it with other files to produce
// an executable, this file does not by itself cause the resulting
// executable to be covered by the GNU General Public License. This
// exception does not however invalidate any other reasons why the
// executable file might be covered by the GNU General Public License.
#include <mln/core/image/image2d.hh>
#include <mln/io/pbm/all.hh>
#include <mln/pw/all.hh>
#include <mln/data/fill.hh>
#include <mln/core/image/dmorph/image_if.hh>
#include <scribo/primitive/extract/lines_h_pattern.hh>
#include <scribo/debug/usage.hh>
const char *args_desc[][2] =
{
{ "input.pbm", "A binary image." },
{ "length", " Minimum line length. (Common value : 51)" },
{ "delta", " Distance between the object pixel and the background pixel (Common value : 5)" },
{0, 0}
};
int main(int argc, char *argv[])
{
using namespace mln;
if (argc != 5)
return scribo::debug::usage(argv,
"Extract horizontal lines patterns",
"input.pbm length delta output.pbm",
args_desc,
"A binary image of lines.");
trace::entering("main");
image2d<bool> input;
io::pbm::load(input, argv[1]);
image2d<bool>
h_lines = scribo::primitive::extract::lines_h_pattern(input,
atoi(argv[2]),
atoi(argv[3]));
io::pbm::save(h_lines, argv[4]);
trace::exiting("main");
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment