
https://svn.lrde.epita.fr/svn/oln/trunk/swilena Index: ChangeLog from Roland Levillain <roland@lrde.epita.fr> Wrap more morphological filters. * morpho.ixx: Wrap mln::morpho::closing, mln::morpho::opening mln::morpho::gradient_internal, mln::morpho::gradient_external, mln::morpho::opening_area. (instantiate_closing, instantiate_opening) (instantiate_gradient_internal, instantiate_gradient_external) (instantiate_opening_area): New macros. Use them... (instantiate_morpho): ...here. Deduce the previous `L' parameter from `mln_value(I)', and remove it from the list of parameters of the macro. * image2d_int_u8.i: Adjust. * image2d_int.i: Use macros instantiate_erosion and instantiate_dilation. * python/data.py: New. * python/test.py: Rename as... * python/image2d-misc.py: ...this. * python/lena.py: Rename as... * python/morpho-fun.py: ...this. Exercise more morphological filters. Move WST-based segmentation tests... * python/morpho-segm.py: ...here (new test). * python/swilena.py: Add documentation header. * python/Makefile.am (python_PYTHON): Add data.py. (TESTS): Add morpho-segm.py. s/test.py/image2d-misc.py/ s/lena.py/morpho-fun.py/ image2d_int.i | 7 +---- image2d_int_u8.i | 3 -- morpho.ixx | 67 +++++++++++++++++++++++++++++++++++++++----------- python/Makefile.am | 4 ++ python/data.py | 37 +++++++++++++++++++++++++++ python/morpho-fun.py | 50 +++++++++++++++++-------------------- python/morpho-segm.py | 60 ++++++++++++++++++++++++++++++++++++++++++++ python/swilena.py | 3 ++ 8 files changed, 183 insertions(+), 48 deletions(-) Index: python/data.py --- python/data.py (revision 0) +++ python/data.py (revision 0) @@ -0,0 +1,37 @@ +#! /usr/bin/env python + +# Copyright (C) 2008 EPITA Research and Development Laboratory (LRDE) +# +# This file is part of the Olena Library. This library is free +# software; you can redistribute it and/or modify it under the terms +# of the GNU General Public License version 2 as published by the +# Free Software Foundation. +# +# This library 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 this library; see the file COPYING. If not, write to +# the Free Software Foundation, 51 Franklin Street, Fifth Floor, +# Boston, MA 02111-1307, USA. +# +# As a special exception, you may use this file as part of a free +# software library 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. +# reasons why the executable file might be covered by the GNU General +# Public License. + +# \file python/data.py +# \brief Access to the data of the distribution (images, meshes, etc.). + +import os + +top_srcdir = os.environ["top_srcdir"] +img_dir = os.path.join(top_srcdir, "milena", "img") +lena = os.path.join (img_dir, "lena.pgm") Index: python/morpho-fun.py --- python/morpho-fun.py (revision 2138) +++ python/morpho-fun.py (working copy) @@ -27,38 +27,36 @@ # reasons why the executable file might be covered by the GNU General # Public License. -import os -from swilena import * +# \file python/morpho-fun.py +# \brief Test on mathematical morphology on functions (scalar images). -# Factor this part in a shared test Python file. -top_srcdir = os.environ["top_srcdir"] -img_dir = os.path.join(top_srcdir, "milena", "img") -lena = os.path.join (img_dir, "lena.pgm") +import data +from swilena import * # Module alias. image = image2d_int_u8 -ima = image.load(lena) +ima = image.load(data.lena) + +dilated = image.dilation(ima, win_c4p()) +image.save(dilated, "dilation.pgm") eroded = image.erosion(ima, win_c4p()) -image.save(eroded, "eroded.pgm") +image.save(eroded, "erosion.pgm") -dilated = image.dilation(ima, win_c4p()) -image.save(dilated, "dilated.pgm") +image.save(image.opening(ima, win_c4p()), "opening.pgm") +image.save(image.closing(ima, win_c4p()), "closing.pgm") -# Gradient. -gradient = image.gradient(ima, win_c4p()) -# Area closing. -closed_gradient = image.image2d_int_u8(gradient.domain()) -image.closing_area(ima, c4(), 50, closed_gradient) -# Watershed transform. -nbasins = int_u8(); -ws = image.meyer_wst (closed_gradient, c4(), nbasins) -# FIXME: Actualy print the number of basins; for the moment, this -# statement outputs something like -# -# <int_u32.int_u32; proxy of <Swig Object of type 'mln::value::int_u< 32 > *' -# at 0x816e160> > -# -print nbasins -image.save(ws, "ws.pgm") +image.save(image.gradient(ima, win_c4p()), "gradient.pgm") +image.save(image.gradient_internal(ima, win_c4p()), "gradient_internal.pgm") +image.save(image.gradient_external(ima, win_c4p()), "gradient_external.pgm") + +# FIXME: The interface of closing_area/opening_area is a pain: the +# output should be returned, not taken as argument. +closed_ima = image.image2d_int_u8(ima.domain()) +image.closing_area(ima, c4(), 50, closed_ima) +image.save(closed_ima, "closing_area.pgm") + +opened_ima = image.image2d_int_u8(ima.domain()) +image.closing_area(ima, c4(), 50, opened_ima) +image.save(opened_ima, "opening_area.pgm") Property changes on: python/morpho-fun.py ___________________________________________________________________ Added: svn:mergeinfo Index: python/morpho-segm.py --- python/morpho-segm.py (revision 0) +++ python/morpho-segm.py (revision 0) @@ -0,0 +1,60 @@ +#! /usr/bin/env python + +# Copyright (C) 2008 EPITA Research and Development Laboratory (LRDE) +# +# This file is part of the Olena Library. This library is free +# software; you can redistribute it and/or modify it under the terms +# of the GNU General Public License version 2 as published by the +# Free Software Foundation. +# +# This library 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 this library; see the file COPYING. If not, write to +# the Free Software Foundation, 51 Franklin Street, Fifth Floor, +# Boston, MA 02111-1307, USA. +# +# As a special exception, you may use this file as part of a free +# software library 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. +# reasons why the executable file might be covered by the GNU General +# Public License. + +# \file python/morpho-segm.py +# \brief Test on watershed transform-based segmentation. + +import data +from swilena import * + +# Module alias. +image = image2d_int_u8 + +ima = image.load(data.lena) + +# Gradient. +gradient = image.gradient(ima, win_c4p()) +image.save(gradient, "gradient.pgm") +# Area closing of the gradient. +closed_gradient = image.image2d_int_u8(gradient.domain()) +image.closing_area(ima, c4(), 50, closed_gradient) +# Watershed transform. +nbasins = int_u8(); +ws = image.meyer_wst (closed_gradient, c4(), nbasins) +# FIXME: Actualy print the number of basins; for the moment, this +# statement outputs something like +# +# <int_u32.int_u32; proxy of <Swig Object of type 'mln::value::int_u< 32 > *' +# at 0x816e160> > +# +print nbasins +image.save(ws, "segm.pgm") + +# FIXME: Also re-enable the naive segmentation with no gradient +# simplification, and an output on an image2d<int_u32>. Property changes on: python/image2d-misc.py ___________________________________________________________________ Added: svn:mergeinfo Index: python/Makefile.am --- python/Makefile.am (revision 2138) +++ python/Makefile.am (working copy) @@ -30,6 +30,8 @@ python_PYTHON = ltihooks.py # swilena.py: The whole Swilena suite. python_PYTHON += swilena.py +# data.py: Access to the data of the distribution (images, meshes, etc.) +python_PYTHON += data.py ## ----------------- ## @@ -170,5 +172,5 @@ $(MAKE) $(AM_MAKEFLAGS) $(RUN) @mv -f $@.tmp $@ -TESTS = test.py lena.py +TESTS = image2d-misc.py morpho-fun.py morpho-segm.py EXTRA_DIST += $(TESTS) Index: python/swilena.py --- python/swilena.py (revision 2138) +++ python/swilena.py (working copy) @@ -27,6 +27,9 @@ # reasons why the executable file might be covered by the GNU General # Public License. +# \file swilena.py +# \brief The whole Swilena suite. + import ltihooks from point2d import * Index: image2d_int_u8.i --- image2d_int_u8.i (revision 2138) +++ image2d_int_u8.i (working copy) @@ -68,8 +68,7 @@ then. */ instantiate_morpho(mln::image2d< mln::value::int_u<8> >, mln::window2d, - mln::neighb2d, - mln::value::int_u<8>) + mln::neighb2d) /*---------------------------------------. | image2d<int_u8> and image2d<int_u32>. | Index: image2d_int.i --- image2d_int.i (revision 2138) +++ image2d_int.i (working copy) @@ -54,8 +54,5 @@ %} %include "morpho.ixx" -// Explicit instantiation of this trait for the return type of -// mln::morpho::dilation and mln::morpho::erosion. -%template() mln::trait::concrete< mln::image2d< int > >; -%template(dilation) mln::morpho::dilation< mln::image2d<int>, mln::window2d >; -%template(erosion) mln::morpho::erosion< mln::image2d<int>, mln::window2d >; +instantiate_erosion(erosion, mln::image2d<int>, mln::window2d) +instantiate_dilation(dilation, mln::image2d<int>, mln::window2d) Index: morpho.ixx --- morpho.ixx (revision 2138) +++ morpho.ixx (working copy) @@ -31,12 +31,13 @@ %module morpho +%include "concrete.ixx" +%include "ch_value.ixx" + /*-----------------------------------. | Morphological dilation & erosion. | `-----------------------------------*/ -%include "concrete.ixx" - %{ #include "mln/morpho/dilation.hh" #include "mln/morpho/erosion.hh" @@ -52,22 +53,39 @@ %enddef %define instantiate_erosion(Name, I, W) + // Explicit instantiation of this trait for the return type. %template() mln::trait::concrete< I >; %template(Name) mln::morpho::erosion< I, W >; %enddef /*----------------------------------. -| Morphological opening & closing. | +| Morphological closing & opening. | `----------------------------------*/ -// FIXME: Add them. +%{ +#include "mln/morpho/closing.hh" +#include "mln/morpho/opening.hh" +%} + +%include "mln/morpho/closing.hh" +%include "mln/morpho/opening.hh" + +%define instantiate_closing(Name, I, W) + // Explicit instantiation of this trait for the return type. + %template() mln::trait::concrete< I >; + %template(Name) mln::morpho::closing< I, W >; +%enddef + +%define instantiate_opening(Name, I, W) + // Explicit instantiation of this trait for the return type. + %template() mln::trait::concrete< I >; + %template(Name) mln::morpho::opening< I, W >; +%enddef /*------------. | Gradients. | `------------*/ -// FIXME: Add other gradient. - %{ #include "mln/morpho/gradient.hh" %} @@ -80,28 +98,42 @@ %template(Name) mln::morpho::gradient< I, W >; %enddef +%define instantiate_gradient_internal(Name, I, W) + // Explicit instantiation of this trait for the return type. + %template() mln::trait::concrete< I >; + %template(Name) mln::morpho::gradient_internal< I, W >; +%enddef + +%define instantiate_gradient_external(Name, I, W) + // Explicit instantiation of this trait for the return type. + %template() mln::trait::concrete< I >; + %template(Name) mln::morpho::gradient_external< I, W >; +%enddef + /*-------------------------. | Area closing & opening. | `-------------------------*/ -// FIXME: Add area opening. - %{ #include "mln/morpho/closing_area.hh" +#include "mln/morpho/opening_area.hh" %} %include "mln/morpho/closing_area.hh" +%include "mln/morpho/opening_area.hh" %define instantiate_closing_area(Name, I, N) %template(Name) mln::morpho::closing_area< I, N, I >; %enddef +%define instantiate_opening_area(Name, I, N) + %template(Name) mln::morpho::opening_area< I, N, I >; +%enddef + /*------------------------------------. | Meyer's Watershed Transform (WST). | `------------------------------------*/ -%include "ch_value.ixx" - %{ #include "mln/morpho/meyer_wst.hh" %} @@ -118,12 +150,19 @@ | Instantiate everything. | `-------------------------*/ -%define instantiate_morpho(I, W, N, L) +%define instantiate_morpho(I, W, N) instantiate_dilation(dilation, I, W) instantiate_erosion(erosion, I, W) + + instantiate_closing(closing, I, W) + instantiate_opening(opening, I, W) + instantiate_gradient(gradient, I, W) + instantiate_gradient_internal(gradient_internal, I, W) + instantiate_gradient_external(gradient_external, I, W) + instantiate_closing_area(closing_area, I, N) - // FIXME: Could we used `typename I::value' instead of `L' here, and - // remove L from the list of arguments? - instantiate_meyer_wst(meyer_wst, L, I, N) + instantiate_opening_area(opening_area, I, N) + + instantiate_meyer_wst(meyer_wst, mln_value(I), I, N) %enddef