Commit ce79c1f9 authored by Edwin Carlinet's avatar Edwin Carlinet
Browse files

Inim fix bugs related to word croping.

	* edwin/inim/inim.cc: Add height closing to avoid word to be cropped.
	* edwin/mln/morpho/tree/filter.hh: Add generic filter to
	  replace filtered components by a user value instead of
	  predefined values.
	* edwin/rush/exo2/test.cc: Minor fixes.
	* edwin/rush/exo2/wst_from_tree.cc: Test corrected sharpness
	  with wst.
	* inim/2011/fredwin: New.

git-svn-id: https://svn.lrde.epita.fr/svn/oln/trunk@3799 4aad255d-cdde-0310-9447-f3009e2ae8c0
parent 7349c5ba
2009-05-15 Edwin Carlinet <carlinet@lrde.epita.fr>
Inim fix bugs related to word croping.
* edwin/inim/inim.cc: Add height closing to avoid word to be cropped.
* edwin/mln/morpho/tree/filter.hh: Add generic filter to
replace filtered components by a user value instead of
predefined values.
* edwin/rush/exo2/test.cc: Minor fixes.
* edwin/rush/exo2/wst_from_tree.cc: Test corrected sharpness
with wst.
* inim/2011/fredwin: New.
2009-05-15 Thierry Geraud <thierry.geraud@lrde.epita.fr>
Update Laurent's stuff and new code for Fabien.
......
......@@ -20,12 +20,13 @@
#include <mln/morpho/tree/compute_attribute_image.hh>
#include <mln/morpho/tree/propagate.hh>
#include <mln/morpho/tree/components.hh>
#include <mln/morpho/tree/filter.hh>
/* Attributes */
#include <mln/transform/distance_front.hh>
#include <mln/morpho/attribute/bbox.hh>
#include <mln/morpho/attribute/card.hh>
#include <mln/morpho/attribute/volume.hh>
#include <mln/morpho/attribute/height.hh>
#include <mln/make/w_window2d_int.hh>
/* io */
......@@ -60,7 +61,7 @@ bool mydebug = false;
void usage(char** argv)
{
std::cerr << "usage: " << argv[0] << " input [--debug] [-n nbr_components | -t treshold] [-c card]" << std::endl;
std::cerr << "usage: " << argv[0] << " input [--debug] [-n nbr_components | -t treshold] [-h height]" << std::endl;
abort();
}
......@@ -112,7 +113,7 @@ int main(int argc, char* argv[])
std::string arg;
unsigned nb_components = 0;
unsigned card = 0;
unsigned height = 15;
double treshold = 0;
if (argc < 2)
......@@ -127,8 +128,8 @@ int main(int argc, char* argv[])
nb_components = atoi(argv[++i]);
else if (arg == "-t" && i != argc)
treshold = atof(argv[++i]);
else if (arg == "-c" && i != argc)
card = atoi(argv[++i]);
else if (arg == "-h" && i != argc)
height = atoi(argv[++i]);
else if (arg == "--trace")
trace::quiet = false;
else
......@@ -142,6 +143,10 @@ int main(int argc, char* argv[])
image2d<bool> input_;
io::pbm::load(input_, argv[1]);
if (mydebug) {
dsp("Distance geodesic");
}
/* Work on geodesic distance image */
I input;
{
......@@ -156,8 +161,7 @@ int main(int argc, char* argv[])
}
if (mydebug) {
dsp("Distance geodesic");
dsp("Component tree computation");
}
/* Component tree creation */
......@@ -167,36 +171,32 @@ int main(int argc, char* argv[])
S sorted_sites = level::sort_psites_decreasing(input);
tree_t tree(input, sorted_sites, c4());
if (mydebug) {
dsp("Attribute image computation");
}
/* Compute Attribute On Image */
typedef morpho::attribute::bbox<I> bbox_t;
typedef morpho::attribute::volume<I> card_t;
typedef morpho::attribute::card<I> card_t;
typedef morpho::attribute::height<I> height_t;
typedef mln_ch_value_(I, double) A;
mln_VAR(attr_image, morpho::tree::compute_attribute_image(bbox_t (), tree));
mln_VAR(card_image, morpho::tree::compute_attribute_image(card_t (), tree));
A a = duplicate(ratio(pw::value(attr_image), pw::value(card_image)) | attr_image.domain());
if (card)
{
if (mydebug)
dsp("Image card attribute");
a = duplicate((fun::p2v::ternary(pw::value(card_image) > pw::cst(card),
pw::value(a),
pw::cst(0.0))) | a.domain());
}
if (mydebug) {
dsp("Image sharp attribute");
}
mln_VAR(height_image, morpho::tree::compute_attribute_image(height_t (), tree));
A a = duplicate(ratio(pw::value(attr_image), pw::value(card_image)) | attr_image.domain());
if (height)
morpho::tree::filter::filter(tree, a, pw::value(height_image) > pw::cst(height), 0.0);
/* Run max accumulator */
p_array< mln_psite_(A) > obj_array; // Array of object components.
if (mydebug) {
std::stringstream s("Run max accumulator, look for ", std::stringstream::out|std::stringstream::in|
std::stringstream s("Run max accumulator, look for ",
std::stringstream::out|std::stringstream::in|
std::stringstream::ate);
if (nb_components)
s << nb_components << " components.";
......@@ -224,20 +224,16 @@ int main(int argc, char* argv[])
std::cout << c;
}
/* Now Back Propagate to component */
typedef mln_ch_value_(I, bool) M;
M mask = morpho::tree::set_value_to_components(tree, obj_array, true, false);
// mask now contains all nodes related to objects
if (mydebug) {
dsp("Create mask and propagate");
}
a = morpho::tree::propagate_components(a, tree, obj_array, 0);
mln_VAR(output_, level::stretch(int_u8(), a)); //adapt to 0-255
io::pgm::save(output_, "components.pgm");
/* Now Back Propagate to component */
typedef mln_ch_value_(I, bool) M;
M mask = morpho::tree::set_value_to_components(tree, obj_array, true, false);
a = morpho::tree::propagate_components(a, tree, obj_array, 0);
/* Labeling */
typedef mln_ch_value_(I, value::label<8>) L;
......@@ -245,7 +241,8 @@ int main(int argc, char* argv[])
value::label_8 nlabel;
L label = labeling::blobs(mask, c4(), nlabel);
O output = labeling::colorize(value::rgb8(), label, nlabel);
io::ppm::save(output, "label.pgm");
if (mydebug)
io::ppm::save(output, "label.pgm");
/* Now store output image image */
O out, distance;
......@@ -259,6 +256,7 @@ int main(int argc, char* argv[])
for_all(it)
{
std::cout << it << " :: " << attr_image(it).pmin() << " -> " << a(it)
<< " (h: " << height_image(it) << ")"
<< std::endl;
draw::box(out, attr_image(it), literal::red_t ());
......
......@@ -37,7 +37,7 @@
** predicate as well. In this case, all strategies have the same
** result but min filter or direct filter should be used in term
** of performance. If a predicate test is not enough fast, then
** prefer the min filter that minimizes call to predicate.
** prefer the min filter that minimizes calls to predicate.
*/
# include <mln/core/concept/function.hh>
......@@ -49,11 +49,19 @@ namespace mln {
namespace tree {
namespace filter {
template <typename T, typename F, typename P2B>
inline
void
filter(const T& tree, Image<F>& f_, const Function_p2b<P2B>& pred_, const mln_value(F)& v);
template <typename T, typename F, typename P2B>
inline
void
min(const T& tree, Image<F>& f_, const Function_p2b<P2B>& pred_);
template <typename T, typename F, typename P2B>
inline
void
......@@ -102,6 +110,29 @@ namespace mln {
}
template <typename T, typename F, typename P2B>
inline
void
filter(const T& tree, Image<F>& f_, const Function_p2b<P2B>& pred_, const mln_value(F)& v)
{
F& f = exact(f_);
const P2B& pred = exact(pred_);
//FIXME precondition
mln_ch_value(F, bool) mark;
initialize(mark, f);
mln::data::fill(mark, false);
mln_dn_node_piter(T) n(tree);
for_all(n)
if (mark(tree.parent(n)) || !pred(n))
{
f(n) = v;
mark(n) = true;
}
//FIXME postcondition
}
template <typename T, typename F, typename P2B>
inline
......
include makefile.rules
OLENADIR=$(MLN_DIR)/..
MILENADIR=$(MLN_DIR)
CXXFLAGS = -I$(MILENADIR) -I./ -W -Wall
CXXFLAGS += $(if $(DEBUG), -g -ggdb, -DNDEBUG\
$(if $(RELEASE), -O3, -O1))
CXX=g++
LD=g++
LDFLAGS=
SRC=
OUT_IMG=superpose.pgm mean.pgm gradient.pgm closing.pgm
BIN=wst_from_closing wst_from_tree test
all: $(BIN)
%: %.cc
$(CXX) $(CXXFLAGS) $< -o $@
clean:
rm -f $(OUT_IMG)
rm -f $(BIN)
%.o: %.cc
$(CXX) $(CXXFLAGS) -c $<
\ No newline at end of file
#include <mln/morpho/attribute/volume.hh>
#include <mln/morpho/attribute/height.hh>
#include <mln/morpho/attribute/sharpness.hh>
#include <mln/morpho/attribute/mysharpness.hh>
#include <mln/morpho/tree/data.hh>
#include <mln/morpho/tree/compute_attribute_image.hh>
#include <mln/level/sort_psites.hh>
......@@ -12,8 +13,8 @@
#include <mln/core/alias/neighb1d.hh>
#include <mln/value/int_u8.hh>
#include "../../tree/components.hh"
#include "../../tree/propagate.hh"
#include <mln/morpho/tree/components.hh>
#include <mln/morpho/tree/propagate.hh>
#include <mln/fun/p2v/ternary.hh>
#include <mln/pw/all.hh>
......@@ -104,28 +105,28 @@ int main()
{
typedef mln_ch_value_(I, double) A;
typedef morpho::attribute::sharpness<I> attribute_t;
A a, component_img;
// Attribute Pruning
a = morpho::tree::compute_attribute_image(attribute_t (), t);
a = morpho::attribute::mysharpness(t);
morpho::tree::propagate_representative(t, a);
debug::println("sharpness", a);
// Component filtering
a = duplicate((fun::p2v::ternary(pw::value(height) > pw::cst(2),
pw::value(a),
pw::cst(0.0))) | a.domain());
// a = duplicate((fun::p2v::ternary(pw::value(height) > pw::cst(2),
// pw::value(a),
// pw::cst(0.0))) | a.domain());
debug::println("sharpness", a);
//debug::println("sharpness", a);
p_array< mln_psite_(A) > obj_array;
obj_array = morpho::tree::get_components(t, a);
std::cout << obj_array.nsites() << std::endl;
// p_array< mln_psite_(A) > obj_array;
// obj_array = morpho::tree::get_components(t, a);
// std::cout << obj_array.nsites() << std::endl;
component_img = morpho::tree::propagate_components(a, t, obj_array, 0);
// component_img = morpho::tree::propagate_components(a, t, obj_array, 0);
debug::println("sharpness", component_img);
// debug::println("sharpness", component_img);
}
......
......@@ -53,11 +53,12 @@
/* Tree computation */
#include <mln/level/sort_psites.hh>
#include <mln/morpho/tree/data.hh>
#include "../../tree/propagate.hh"
#include "../../tree/components.hh"
#include <mln/morpho/tree/propagate.hh>
#include <mln/morpho/tree/propagate_if.hh>
#include <mln/morpho/tree/components.hh>
#include <mln/morpho/tree/compute_attribute_image.hh>
#include <mln/morpho/attribute/sharpness.hh>
#include <mln/morpho/attribute/mysharpness.hh>
/* pw */
#include <mln/core/concept/function.hh>
......@@ -103,6 +104,27 @@ namespace mln
{
return height_wrapper_<P2V>(f);
}
template <typename T, typename F, typename P2B>
inline
void
mymin(const T& tree, Image<F>& f_, const Function_p2b<P2B>& pred_)
{
F& f = exact(f_);
const P2B& pred = exact(pred_);
mln_ch_value(F, bool) mark;
initialize(mark, f);
mln::data::fill(mark, false);
mln_dn_node_piter(T) n(tree);
for_all(n)
if (mark(tree.parent(n)) || !pred(tree.parent(n)))
{
f(n) = 0.0;
mark(n) = true;
}
}
}
......@@ -176,17 +198,17 @@ int main(int argc, char** argv)
typedef mln_ch_value_(I, double) A;
A a;
{
typedef morpho::attribute::sharpness<I> sharp_t;
typedef mln_ch_value_(I, sharp_t) B;
typedef mln_ch_value_(I, unsigned) H;
// Attribute Pruning
B a_img;
a = morpho::tree::compute_attribute_image(sharp_t (), t, &a_img);
H h_img;
a = morpho::attribute::mysharpness(t, &h_img);
// Component filtering
a = duplicate((fun::p2v::ternary(height_wrapper(pw::value(a_img)) > pw::cst(lambda_h),
pw::value(a),
pw::cst(0.0))) | a.domain());
// this should use a filter from morpho/tree/filter with the predicate on the height of the parent
// so use function composition but ...
mymin(t, a, pw::value(h_img) > pw::cst(lambda_h));
}
/************************************************/
......
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