SlideShare uma empresa Scribd logo
1 de 20
Baixar para ler offline
Component Trees and Chaining Operators in Climb

                                      Christopher Chedeau


                                 Technical Report no 1108, June 2011
                                           revision 2295



Climb is a generic image processing library designed to be used for rapid prototyping. The implemen-
tation of two component trees algorithms impacts Climb in several ways: the definition of values is ex-
tended, new site sets are added and debugging utilities are improved.
   A detour is taken to understand the Chaining design pattern popularized by the Javascript jQuery
library. The pattern is adapted to both the image processing domain and Common Lisp and is extended
to introduce a parallel notation as well as better control flows.
Climb est une bibliothèque de traitement d’image générique ayant pour objectif le prototypage rapide.
L’implémentation de deux algorithmes d’arbre de composantes impacte Climb de plusieurs façons : la
définition des valeurs est étendue, de nouveaux ensembles de sites sont ajoutés et les outils de développe-
ment sont améliorés.
   Un détour est pris afin de comprendre le patron de conception de chaînage popularisé par la biblio-
thèque jQuery. La méthode est modifiée afin de s’adapter au traitement d’image ainsi qu’à Common
Lisp. Elle est également étendue via une notation parallèle ainsi qu’avec une meilleure gestion du fil
d’exécution.

Keywords
climb, image processing, dynamic language, chaining, component tree




                       Laboratoire de Recherche et Développement de l’Epita
                   14-16, rue Voltaire – F-94276 Le Kremlin-Bicêtre cedex – France
                            Tél. +33 1 53 14 59 47 – Fax. +33 1 53 14 59 22
               christopher.chedeau@lrde.epita.fr – http://www.lrde.epita.fr/
2


Copying this document
Copyright c 2011 LRDE.
  Permission is granted to copy, distribute and/or modify this document under the terms of
the GNU Free Documentation License, Version 1.2 or any later version published by the Free
Software Foundation; with the Invariant Sections being just “Copying this document”, no Front-
Cover Texts, and no Back-Cover Texts.
  A copy of the license is provided in the file COPYING.DOC.
Contents

1 Introduction                                                                                                                                                                        4

2   Component Tree                                                                                                                                                                    5
    2.1 Component Tree . . . . . .                   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .    5
        2.1.1 Definition . . . . .                    .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .    5
        2.1.2 Najman . . . . . .                     .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .    6
        2.1.3 Berger . . . . . . .                   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .    7
    2.2 Impact on Climb . . . . . .                  .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .    7
        2.2.1 Values . . . . . . .                   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .    8
        2.2.2 Developer Utilities                    .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .    9
        2.2.3 More Site Sets . . .                   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   11

3   Chaining Operators                                                                                                                                                               12
    3.1 Chaining . . . .     .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   12
    3.2 Serial . . . . . .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   13
    3.3 Paralell . . . . .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   15
    3.4 Flow Control . .     .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   16

4   Conclusion                                                                                                                                                                       19

5   Bibliography                                                                                                                                                                     20
Chapter 1

Introduction

The image processing domain requires high performance as the inputs are big: most images
nowadays are composed of millions of pixels. As a consequence, most libraries are written in C
or C++ with a high focus on speed. It is often done at the expense of ease of use. Climb has been
designed from the ground up to be a developer friendly library. Using Common Lisp, Climb
benefits from the dynamic aspect and functional abilities of the language.
  Climb is in its infancy. The core aspects of the library such as sites, site sets and morphers
and the implementation of most mathematical morphology operators have been established in
previous work (Denuzière (2009), Chedeau (2010)). The next step is to introduce many new
algorithms from various areas of image processing and see if the framework supports them.
  In this article, we concentrate on two different algorithms that produce the component tree
of an image. The purpose of this article is not about comparing performance nor studying use
cases of the two algorithms but more about showing how their implementations impacts the
design of Climb.
  Eventually, we take a detour to the Javascript world and specifically the jQuery1 library to
discover a design pattern to chain operations. We adapt it to the image processing world and
improve it thanks to Common Lisp expressive power in order to "Write less and do more"2 .


Acknoledgements
Thanks to Didier Verna for being both a great teacher and project manager, Laurent Senta and
Simon Guillot for helping out on the Climb development, Lorene Poinsot and Alex Hamelin for
the help during the preparation of this report.




  1 http://jquery.com/
  2 jQuery:   The Write Less, Do More, JavaScript Library
Chapter 2

Component Tree

2.1 Component Tree
2.1.1   Definition
A component tree is the organization in a tree structure, thanks to the inclusion relation, of the
level set connected components of an image. In other words, if we see our image in 3D where
the z-coordinate is the pixel intensity. A slice of a mountain is called a connected component
and two slices are connected if they are on top of each other. A visual example is available in
Figure 2.1.




             Figure 2.1: Component tree 3D representation Gonzalez et al. (2004)

  We implement two algorithms to compute the component tree: Najman and Couprie (2004)
and Berger et al. (2007). They are similar algorithms as they are both based on Tarjan’s union-
find disjoint set forest computation (Géraud (2005)). They have been chosen because the com-
ponent tree they produce is stored in two different ways.
2.1 Component Tree                                                                                6


  Let us take a simple example. In input, Figure 2.2, we have a 3x5 image in gray level. In
Figure 2.3, we label each node (or pixel) with a capital letter.


                 80      60      70                                A      B      C

                 30      30      30                                D      E      F

                 20      10      30                                G      H       I

                 30      30      30                                 J     K      L

                 90      40      50                                M      N      O


            Figure 2.2: Node Values                           Figure 2.3: Node Names

2.1.2 Najman
The node H has the lowest value, and is therefore part of the root component of the tree. In
order to climb the tree, we go to G and then there’s a floor composed of D, E, F, I, L, K, J. At this
step, the tree is split in two on the nodes N and B. Each of them can join two other components
O, M and C, A. The first algorithm, Najman and Couprie (2004), computes the component tree
in Figure 2.4. It also provides for each node, the canonical element of its component: Figure
2.5.


                                                                   A      B      C
                         H
                                                                   E      E      E

                         G                                         G      H      E

                                                                   E      E      E
                 D, E, F, I, L, K, J

                                                                   M      N      O

             N                         B
                                                              Figure 2.5: Components

        O          M           C           A


         Figure 2.4: Component Tree
7                                                                                   Component Tree


2.1.3   Berger
The second algorithm, Berger et al. (2007), gives another representation of the component tree.
Instead of building the tree, it provides a parent relation seen in Figure 2.6. If the node is canon-
ical, the parent points to the canonical element of the parent component, else to the canonical
element of its own component. In order to use the parent relation, the nodes have to be iterated
in increasing order of values. Therefore, a structure containing the nodes in sorted order is also
returned (Figure 2.7).


                B      L      B                                      H      G       D

                L      L      L                                      E      F       I

                H      H      L                                      J      K       L

                L      L      G                                      N      O       B

                N      L      N                                      C      A      M


           Figure 2.6: Node Parents                            Figure 2.7: Sorted Nodes


   Climb has been designed to provide an interface that matches operations used in literature.
Therefore, the implementation of the algorithms is straightforward. Figure 2.8 shows that the
lisp code is the exact translation of the pseudo-code found in Berger et al. (2007) paper.

CANONICALIZE - TREE (parent, f )             0 (defun canonicalize−tree (parent sorted−sites image)
1 for each p ∈ R in reverse order do         1 (do−sites (p sorted−sites :backward)
2   q ← parent(p)                            2     (let ((q (iref parent p)))
3   if f (parent(q)) = f (q) then            3     (when (value−equal (iref image (iref parent q)) (iref image q))
4      parent(p) ← parent(q)                 4        (setf (iref parent p) (iref parent q)))))
                                             5 parent)
5 return parent



                     Figure 2.8: Translation of the pseudo-code to real code



2.2 Impact on Climb
Climb has first been developed around mathematical morphology operators such as erosion,
dilation or top-hat (Chedeau (2010)). Those simple operators were a good opportunity to focus
on making a stable and powerful internal architecture. The implementation of those two algo-
rithms demonstrates that overall the design was good enough to support them. The changes
required are explained in this section.
2.2 Impact on Climb                                                                              8


2.2.1 Values
Berger algorithm requires to have a data structure that associates sites with sites while Najman
algorithm requires to associate a site with a list of sites. The nearest concept available in Climb
is the Image. It associates a site with a value, where the value is an array of elements that
represents grayscale or RGB intensities. The natural evolution is to extend the notion of value.
   An image value can be any common lisp value: numbers, lists, strings, objects and even
images. Contrary to Olena1 (in C++) and our old design, the image container is no longer
required to know the type of its content. Instead, each element knows its own type. As a side-
effect, it makes possible to create heterogeneous images.
   The writing of morphers (Chedeau (2010)) is easier as we no longer have to manually enter
the output type, which can be complicated. As we make use of classes for values, the code in
Figure 2.9 is also more meaningful for the reader.

 1    ; Legacy v e r s i o n
 2    ( image−direct−value−morpher
 3       image : gray
 4       ( lambda ( gray ) ( v e c t o r gray gray gray ) ) ; Reader
 5       ( lambda ( rgb ) (/ ( reduce # ’+ rgb ) 3 ) ) )    ; Writer
 6
 7    ; Version with new Value r e p r e s e n t a t i o n
 8    ( image−direct−value−morpher
 9       image
10       ( lambda ( gray ) ( make−rgb : r gray : g gray : b gray ) ) ; Reader
11       ( lambda ( rgb ) ( make−gray : i (/ (+ ( value−r rgb )             ; Writer
12                                                    ( value−g rgb )
13                                                    ( value−b rgb ) ) 3 ) ) ) )

                      Figure 2.9: Implementation of a RGB to Gray morpher

  In order for algorithms to be written once and work for all types of values, we use duck typing
(Martelli (2000)). All images with values that implements the generic functions equal and < can
be used to make a component tree. It makes the addition of new value types straightforward.
  The Image definition in Climb is now more in line with the image processing literature. It is
nothing more than a function associates a value to a site. Each algorithm can use the best fitting
implementation of the image and interpret the value as it needs to.




     1 http://olena.lrde.epita.fr/
9                                                                                     Component Tree


2.2.2        Developer Utilities
make-image-[bool, gray]
Basic values such as grayscale or RGB are no longer primitive types but classes. As a conse-
quence, we have to call a constructor function if we want to use them from primitive types. It
makes the creation of small test images harder. We introduce two functions make-image-bool
and make-image-gray to help the developer.
 1 ( make−image−bool ( dimensions v a l u e s ) )
 2 ( make−image−gray ( dimensions v a l u e s ) )
  In order to represent boolean values, common lisp uses nil and t. As they do not have
the same number of characters, it makes displaying them in a textual grid a tedious process.
Looking for an alternative, we thought about 0 and 1. However, the two symbols are hard to
distinguish one from the other. We finally chose to use . and #.
  Figure 2.10 and Figure 2.11 demonstrate how easy it is to use them.

 1   ( print−image−2d                                1   ( print−image−2d
 2   ( make−image−bool ’ ( 4 4 )                     2   ( make−image−gray ’ ( 4 4 )
 3   "# . # .                                        3   ’ ( 0 10 20 30
 4     . # . #                                       4     100 255   0    0
 5     . . # .                                       5      10 12 18 14
 6     . . . #" ))                                   6       0    0  0    1)))
 7                                                   7
 8   ;   #   .   #   .                               8   ;   0 10        20     30
 9   ;   .   #   .   #                               9   ; 100 255        0      0
10   ;   .   .   #   .                              10   ; 10 12         18     14
11   ;   .   .   .   #                              11   ;   0   0        0      1

             Figure 2.10: Boolean Utilities                   Figure 2.11: Grayscale Utilities




print-image-2d
We also add a print-image-2d function that prints an image to the console. The goal of the
function is to provide a practical way to visualize a small image. To make it developer-friendly,
the output of boolean and grayscale images uses the same format as make-image-*.
 1 ( p r i n t −image−2d ( image &o p t i o n a l ( r e p r   ’ value−r e p r ) ) )
  It is possible to provide a custom function to display the value. For example, it is useful
to print the parent representation of the component tree. Figure 2.12 shows how to combine
make-image-gray, component-tree and print-image-2d.
  As it is hard to get a generic library right, we first start by writing non-generic functions. Only
once there are multiple functions with the same goal and different types of arguments, we can
merge them. In this case, we first wrote print-image-bool-2d and extended it. However,
we did not yet have the need to print other images than 2d ones. It would be premature to write
down print-image without real use cases.
  We may also merge make-image-bool and make-image-gray with make-image in the
future. We will consider doing this when we will discover more use cases.
2.2 Impact on Climb                                                                       10




 1   ; Transforms S i t e ( 0 , 0 ) i n t o ’A’ , S i t e ( 0 , 1 ) i n t o ’ B ’   ...
 2   ( defun r e p r − l a b e l ( s i t e )
 3      ( code−char
 4        (+ 65
 5           ( ∗ 3 (1− ( p o i n t − c o o r d i n a t e s i t e 1 ) ) )
 6           (1− ( p o i n t − c o o r d i n a t e s i t e 0 ) ) ) ) )
 7
 8   ( destructuring−bind
 9       ( ( t r e e components )
10         ( component−tree
11             ( make−image−gray
12                ’(3 5)
13                ’ ( 8 0 60 70
14                  30 30 30
15                  20 10 30
16                  30 30 30
17                  90 40 5 0 ) )
18             (4− c o n n e c t i v i t y ) )
19     ( print−image−2d t r e e # ’ r e p r − l a b e l ) )
20
21   ;   B L B
22   ;   L L L
23   ;   H H L
24   ;   L L G
25   ;   N L N

                   Figure 2.12: Use of component-tree and print-image-2d
11                                                                                    Component Tree


 2.2.3   More Site Sets
 Figure 2.8 introduces the notion of iteration on sorted site sets. Climb does not have any built-
 in mechanism to achieve this. However, it allows to add new types of site sets. We introduce
 site-set-array. It implements generic functions required by do-sites to iterate over it:
 reset and next. And implements two additional: push and sort.
   Duck typing is not only used on values but also on site sets. If an object implements both
 next and reset, it can be used anywhere an iterable site set is required. In order to iterate over
 the site-set in reverse order, we add a :backward optional argument to the reset function.
   Climb features many types of site sets:

  Box : reset (ø, :backward), next
Array : reset (ø, :backward), next, push, sort
 Stack : reset, next, push
Queue : reset, next, push

 Heap : reset, next, push
Graph : reset (ø, :bfs, :dfs), next, push

    Figure 2.13 is an example of an image traversal as it if was a graph. We start to create a
 boolean image seen with the same dimensions as the source image using make-image. Then
 we insert the start element into our structure and set it as seen. In line 5, we iterate over each
 site of the structure. After the line 7, we add all the unseen neighbors of the current site to the
 structure if they haven’t been seen yet.
    The struct variable can be either a stack, queue or heap. The choice of this structure
 allows to traverse the image in various ways such as Breadth-first search, Depth-first search,
 "Shortest-path" or even from the lowest values to the highest.

  1 ( defun t r a v e r s e ( img s t r u c t window s t a r t )
  2    ( l e t ( ( seen ( make−image img : i n i t i a l − e l e m e n t n i l ) ) )
  3        ( site−set−push s t r u c t s t a r t )
  4        ( s e t f ( i r e f seen ) t )
  5        ( do−sites ( s i t e s t r u c t )
  6            ; Do something with s i t e
  7
  8            ( d o − s i t e s ( neighb window s i t e )
  9                ( u n l e s s ( i r e f seen neighb )
 10                   ( s e t f ( i r e f seen neighb ) t )
 11                   ( site−set−push s t r u c t neighb ) ) ) ) ) )

                             Figure 2.13: Use of all the site-set operations
Chapter 3

Chaining Operators

jQuery is a Javascript library designed to provide unified utilities to manipulate HTML docu-
ments across all the browsers and their respective quirks. It quickly grew in popularity as it
introduced a new design pattern that solves well the problems the library tries to solve. jQuery
is based on the chaining ability of Javascript Harmes and Diaz (2007).
   We are going to explain what this technique is, its use in jQuery in order to translate it for the
image processing domain. Common Lisp expressiveness even allows to extend the pattern.


3.1        Chaining
The idea behind chaining is execute more than one action at a time on the same object. It is
trivial to implement in an Object Oriented language, the functions that can be chained should
return this. Figure 3.1 is an example in Javascript.

 1   function Object ( ) { }
 2
 3   Object . prototype = {
 4    methodA : f u n c t i o n ( ) {
 5        // do something
 6        return this ;
 7     },
 8
 9        methodB : f u n c t i o n ( ) {
10          // do something
11          return this ;
12        }
13   };
14
15   var o b j = new O b j e c t ( ) ;
16   o b j . methodA ( ) . methodB ( ) ;

                           Figure 3.1: Javascript implementation of chaining
13                                                                                            Chaining Operators


  Method chaining removes the need to declare temporary variables, and therefore makes the
code much more readable and easier to write. Figure 3.2 is a real world example of chaining
with jQuery. We want to process all the links of a page. We give them the external CSS class,
make them open in a new tab when clicked and plug in an analytic tracking code.

 1 $ ( ’ a [ @href ^=" h t t p : / / " ] ’ )
 2     . addClass ( " e x t e r n a l " )
 3     . a t t r ( " t a r g e t " , " _blank " )
 4     . c l i c k ( f u n c t i o n ( ) { /∗ a n a l y t i c s   c a l l ∗/ } )

                             Figure 3.2: Multiple actions on the same object

  Once we understand the power of this construction, we can lift the limit of returning only
this. Figure 3.3 is a jQuery example where chaining is used to traverse a HTML document: it
finds the parent of the first list element that contains a sublist. Figure 3.4 is a sample code from
the v8cgi SQL Query module1 . The last example in Figure 3.5 implements the basic concept of
method chaining but in an asynchronous way (Diaz (2010)).

 1 $(" li ")                             1 SQL ( " s e l e c t " )                 1 $ (" < div / >")
 2   . has ( " u l " )                   2   . field ("∗")                         2     . f e t c h ( " n a v i g a t i o n . html " )
 3   . eq ( 1 )                          3   . table ( " users " )                 3     . addClass ( " column " )
 4   . parent ( )                        4   . limit (10)                          4     . appendTo ( " # s i d e " )


Figure 3.3: Traversing a                                                       Figure 3.5: Asynchronous Ma-
HTML Document                                Figure 3.4: SQL Query             nipulation




3.2 Serial
In order to extract information from an image, many small algorithms are combined together
into a processing chain. The chaining technique is therefore adapted for this domain. Figure
3.6 shows a sample processing chain we would like to write.

 1 Image ( " l e n a . j p g " )
 2   . togray ( )
 3   . otsu ( )
 4   . opening ( 8 _ c o n n e c t i v i t y )
 5   . save ( " lena_opening . png " )

                                    Figure 3.6: Sample processing chain

  Common Lisp does not have the concept of object methods with the dot notation, instead it
has generic functions. If we were to write the example it would resemble to Figure 3.7. The
order of writing is reversed: the last actions are written in first. Also, the arguments of the
functions are far away from the function call.
     1 http://code.google.com/p/v8cgi/wiki/API_Query
3.2 Serial                                                                                     14



 1 ( save
 2    ( opening
 3       ( otsu
 4          ( togray
 5             ( load " l e n a . j p g " )
 6          )
 7       )
 8    (8− c o n n e c t i v i t y ) )
 9 " lena_opening . png " )


                               Figure 3.7: Direct Common Lisp implementation


  Instead, we can write it the traditional way using a temporary variable as seen in Figure 3.8.
The code is written in the expected order but it too verbose. In this small example there are
eight occurrences of img along with three setf.

 1 ( l e t ( ( img ( load " l e n a . j p g " ) ) )
 2     ( s e t f img ( t o g r a y img ) )
 3     ( s e t f img ( o t s u img ) )
 4     ( s e t f img ( opening img (8− c o n n e c t i v i t y ) ) )
 5     ( save img " lena_opening . png " ) )

                             Figure 3.8: Processing chain using temporary variable

   We introduce in Climb a $ macro (in reference to jQuery). It takes a sequence of actions and
combine them such as the first argument is the result of the previous action. Figure 3.9 code can
either be rewritten into Figure 3.7 and Figure 3.8. The $ allows to write a code equivalent to the
method chaining in Javascript: the opening parenthesis is just moved before the method name.
Clojure2 , a lisp implementation on-top of the JVM3 , implements a similar operator named ->4 .

 1 ($      ( load " l e n a . j p g " )
 2         ( togray )
 3         ( otsu )
 4         ( opening (8− c o n n e c t i v i t y ) )
 5         ( save " lena_opening . png " ) )

                                          Figure 3.9: Climb $ macro




  2 http://clojure.org/
  3 Java   Virtual Machine
  4 http://clojuredocs.org/clojure_core/clojure.core/-%3E
15                                                                                   Chaining Operators


3.3 Paralell
Method chaining and consequently the $ operator are limited to linear processes. jQuery has an
end method5 in order to simulate branching. Every time a method returns an element different
than this, it is being pushed to a stack. The end method pops the latest element from the stack
and returns the new top. Figure 3.10 shows how to use it to set the color of foo into red and
bar into green.

 1 $ ( " # id " )
 2
 3     . f i n d ( " . foo " )
 4          . c s s ( " c o l o r " , " red " )
 5     . end ( )
 6
 7     . f i n d ( " . bar " )
 8          . c s s ( " c o l o r " , " green " )
 9     . end ( )

                                       Figure 3.10: jQuery end example

   The solution adopted by jQuery is the best possible option with traditional method chaining.
Since we are building our operator through macros, we can bypass this limitation. This is why
we introduce the // operator seen in Figure 3.11. In essence, it spawns a new $ operation for
each group of action. It allows to use one variable multiple times. The same version without //
is available in Figure 3.12.

 1 ( $ " # id "                                         1 ( l e t ( ( tmp ( $ " # id " ) ) )
 2                                                      2
 3    (//                                               3     ( $ tmp
 4       ( ( f i n d " . foo " )                        4        ( f i n d " . foo " )
 5         ( c s s " c o l o r " " red " ) )            5        ( c s s " c o l o r " " red " ) )
 6                                                      6
 7       ( ( f i n d " . bar " )                        7     ( $ tmp
 8         ( c s s " c o l o r " " green " ) ) ) )      8        ( f i n d " . bar " )
                                                        9        ( c s s " c o l o r " " green " ) ) )

      Figure 3.11: Climb equivalent with //              Figure 3.12: Climb equivalent without //


   In the jQuery version, it is not possible to use the last value returned by the branches as they
it be ignored by the end method. On the other hand, the // operator returns all the final values.
They will be passed as arguments of the next action. Figure 3.13 is an example that shows how
to compare the result of two binarization algorithms: Sauvola and Otsu. The diff function will
be called with two arguments, the first one being the image through Sauvola, while the second
the image after Otsu.
     5 http://api.jquery.com/end/
3.4 Flow Control                                                                                           16



 1 ($   ( load " l e n a . png " )
 2      ( togray )
 3      (//
 4          ( ( sauvola ) ( save " sauvola . png " ) )
 5          ( ( otsu )         ( save " o t s u . png " ) ) )
 6      ( diff )
 7      ( save " d i f f e r e n c e . png " ) )

                          Figure 3.13: Combine the result of the // branches


3.4 Flow Control
It is possible with both $ and // operators to achieve complex behaviors with few lines of code.
However, it imposes a model where each returned value will be the first argument of the next
action. It is sometimes undesirable.
   For example, it is a common operation to time actions. Climb provides two functions timer-start
and timer-print. They are not designed to be used in a chaining context. This is why we
introduce the quote modifier: it calls the function the usual way. Figure 3.14 shows how to
time actions and Figure 3.15 is a code with similar effect without the $ operator.

 1 ( $ ( load " l e n a . png " )                       1 ( l e t ( ( tmp ( load " l e n a . png " ) ) )
 2    ’( timer−start )                                  2     ( timer−start )
 3      ( otsu )                                        3     ( s e t f tmp ( o t s u tmp ) )
 4    ’ ( t i m e r − p r i n t " Otsu " )              4     ( t i m e r − p r i n t " Otsu " )
 5      ( save " l e n a _ o t s u . png " ) )          5     ( save tmp " l e n a _ o t s u . png " ) )
 6                                                      6
 7 ; Otsu : 101ms                                       7 ; Otsu : 101ms


          Figure 3.14: Quote modifier                             Figure 3.15: Expanded code

  The quote modifier uses two distinct concepts:

   • Custom arguments: All the previous return values are not automatically inserted as firsts
     arguments. They are available through the keywords $1, $2 ...
   • Skip return values: The return values of the action are not used for chaining. Instead,
     previous return values are used.

  In order to get more flexibility, we also introduce the # modifier that only provides custom
arguments. So far, it is possible with modifiers to express three of the four combinations: Figure
3.16. We may find use cases and introduce the last combination in the future.

                                                         Custom arguments
                                                         Yes      No
                             Skip return values   Yes     ’     none yet
                                                  No      #        ø

                                     Figure 3.16: Available modifiers
17                                                                            Chaining Operators


  Figure 3.17 is a more complex example using the // operator as well as the ’ and # modifiers.
  The image is first being dispatched to the three blocks using the // operator. Each block
applies a different algorithm, saves the processed image and prints the algorithm execution
time using the ’ modifier.
  The three algorithms results are then dispatched into three blocks. Each one makes the dif-
ference between two images using the diff algorithm and the # modifier.

 1    ( $ ( load " l e n a g r a y . png " )
 2
 3        (//
 4         ( ’ ( timer−start )
 5             ( otsu )
 6           ’ ( t i m e r − p r i n t " Otsu " )
 7             ( save " o t s u . png " ) ) ; $1
 8
 9          ( ’ ( timer−start )
10              ( sauvola ( box2d 1 ) )
11            ’ ( t i m e r − p r i n t " Sauvola 1 " )
12              ( save " sauvola1 . png " ) ) ; $2
13
14          ( ’ ( timer−start )
15              ( sauvola ( box2d 5 ) )
16            ’ ( t i m e r − p r i n t " Sauvola 5 " )
17              ( save " sauvola5 . png " ) ) ) ; $3
18
19        (//
20         ( # ( d i f f $1 $2 ) ( save " diff−otsu−sauvola1 . png " ) )
21         ( # ( d i f f $1 $3 ) ( save " diff−otsu−sauvola5 . png " ) )
22         ( # ( d i f f $2 $3 ) ( save " diff−sauvola1−sauvola5 . png " ) ) ) )
23
24    ; Otsu : 101ms
25    ; Sauvola 1 : 263ms
26    ; Sauvola 5 : 3407ms

                        Figure 3.17: Comparison of three binarization techniques

     The generated images are shown in Figure 3.18.
3.4 Flow Control                                                                   18




                   Otsu - 101ms       Sauvola 1 - 263ms      Sauvola 5 - 3407ms




               Otsu - Sauvola 1        Otsu - Sauvola 5    Sauvola 1 - Sauvola 5




                    Figure 3.18: Outputs of the binarization processing chain
Chapter 4

Conclusion

We have taken two component tree algorithms from the literature and implemented them into
Climb. It enlightened the parts of the library that required to be worked on. The definition
of values is extended: instead of being a vector of numbers, it can now be of any type. The
extensibility of site sets through a duck typing interface is used to support those algorithms.
Debugging utilities are also added to improve ease of development.
  In order to enhance end user ability to use our library, we introduce a design pattern called
method chaining popularized by the Javascript jQuery library. As we adapted it to the Common
Lisp language and to the image processing context, it was clear that the current form was too
restrained. We improved it to support parallel execution as well as better flow control.
  The image processing field is deeply rooted with languages such as C and C++. Being able
to immerse it into a dynamic language such as Common Lisp gives us the ability to use a wide
range of programming patterns that were not being considered. Climb improved with the use
of lambda functions that powers morphers (Chedeau (2010)) and with the extended form of
method chaining proposed in this technical report.
  There are many other patterns that could potentially be taken from dynamic languages to
improve the library. Future work will be focused on exploring these new possibilities. New
algorithms as well as new types of images (both structures and values) will be implemented in
order to strengthen our core framework and to provide solutions to real world problems.
Chapter 5

Bibliography

Berger, Ch., Géraud, Th., Levillain, R., Widynski, N., Baillard, A., and Bertin, E. (2007). Ef-
fective component tree computation with application to pattern recognition in astronomical
imaging. In Proceedings of the IEEE International Conference on Image Processing (ICIP), volume 4,
pages IV–41–IV–44, San Antonio, TX, USA.

Chedeau, C. (2010). Functionnal approach of image processing genericity. Technical Report
1001, EPITA Research and Development Laboratory (LRDE).
Denuzière, L. (2009). CLIMB: A dynamic approach to generic image processing. Technical
Report 0906, EPITA Research and Development Laboratory (LRDE).
Diaz, D. (2010). Asynchronous method queue chaining in javascript.                http://www.
dustindiaz.com/async-method-queues/.
Géraud, Th. (2005). Ruminations on Tarjan’s Union-Find algorithm and connected operators.
volume 30 of Computational Imaging and Vision, pages 105–116, Paris, France. Springer.
Gonzalez, R., Woods, R., and Eddins, S. (2004). Digital Image Processing Using MATLAB(R).
Prentice Hall.
Harmes, R. and Diaz, D. (2007). Pro JavaScript Design Patterns (Recipes: a Problem-Solution Ap).
Apress, 1 edition.
Martelli, A. (2000). http://groups.google.com/group/comp.lang.python/msg/
e230ca916be58835.

Najman, L. and Couprie, M. (2004). Quasi-linear algorithm for the component tree.              In
IS&T/SPIE Symposium on Electronic Imaging, In Vision Geometry XII, pages 18–22.

Mais conteúdo relacionado

Mais procurados

Metatron Technology Consulting 's MySQL to PostgreSQL ...
Metatron Technology Consulting 's MySQL to PostgreSQL ...Metatron Technology Consulting 's MySQL to PostgreSQL ...
Metatron Technology Consulting 's MySQL to PostgreSQL ...webhostingguy
 
Linux mailserver-installation
Linux mailserver-installationLinux mailserver-installation
Linux mailserver-installationchetanvyas
 
D3.2. Specification of Presentation Interfaces for The Three Scenarios
D3.2. Specification of Presentation Interfaces for The Three ScenariosD3.2. Specification of Presentation Interfaces for The Three Scenarios
D3.2. Specification of Presentation Interfaces for The Three ScenariosLinkedTV
 
ENERGY EFFICIENCY OF ARM ARCHITECTURES FOR CLOUD COMPUTING APPLICATIONS
ENERGY EFFICIENCY OF ARM ARCHITECTURES FOR CLOUD COMPUTING APPLICATIONSENERGY EFFICIENCY OF ARM ARCHITECTURES FOR CLOUD COMPUTING APPLICATIONS
ENERGY EFFICIENCY OF ARM ARCHITECTURES FOR CLOUD COMPUTING APPLICATIONSStephan Cadene
 

Mais procurados (8)

Metatron Technology Consulting 's MySQL to PostgreSQL ...
Metatron Technology Consulting 's MySQL to PostgreSQL ...Metatron Technology Consulting 's MySQL to PostgreSQL ...
Metatron Technology Consulting 's MySQL to PostgreSQL ...
 
Jiu manual
Jiu   manualJiu   manual
Jiu manual
 
Linux mailserver-installation
Linux mailserver-installationLinux mailserver-installation
Linux mailserver-installation
 
mpi4py Manual!
mpi4py Manual!mpi4py Manual!
mpi4py Manual!
 
D3.2. Specification of Presentation Interfaces for The Three Scenarios
D3.2. Specification of Presentation Interfaces for The Three ScenariosD3.2. Specification of Presentation Interfaces for The Three Scenarios
D3.2. Specification of Presentation Interfaces for The Three Scenarios
 
Assembly
AssemblyAssembly
Assembly
 
Avi
AviAvi
Avi
 
ENERGY EFFICIENCY OF ARM ARCHITECTURES FOR CLOUD COMPUTING APPLICATIONS
ENERGY EFFICIENCY OF ARM ARCHITECTURES FOR CLOUD COMPUTING APPLICATIONSENERGY EFFICIENCY OF ARM ARCHITECTURES FOR CLOUD COMPUTING APPLICATIONS
ENERGY EFFICIENCY OF ARM ARCHITECTURES FOR CLOUD COMPUTING APPLICATIONS
 

Destaque

JSPP: Morphing C++ into Javascript
JSPP: Morphing C++ into JavascriptJSPP: Morphing C++ into Javascript
JSPP: Morphing C++ into JavascriptChristopher Chedeau
 
Climb - Property-based dispatch in functional languages [Report]
Climb - Property-based dispatch in functional languages [Report]Climb - Property-based dispatch in functional languages [Report]
Climb - Property-based dispatch in functional languages [Report]Christopher Chedeau
 
Climb - Property-based dispatch in functional languages [Slides]
Climb - Property-based dispatch in functional languages [Slides]Climb - Property-based dispatch in functional languages [Slides]
Climb - Property-based dispatch in functional languages [Slides]Christopher Chedeau
 
Climb - A Generic and Dynamic Approach to Image Processing
Climb - A Generic and Dynamic Approach to Image ProcessingClimb - A Generic and Dynamic Approach to Image Processing
Climb - A Generic and Dynamic Approach to Image ProcessingChristopher Chedeau
 
Climb - A Generic and Dynamic Approach to Image Processing
Climb - A Generic and Dynamic Approach to Image ProcessingClimb - A Generic and Dynamic Approach to Image Processing
Climb - A Generic and Dynamic Approach to Image ProcessingChristopher Chedeau
 
Generic Image Processing With Climb – 5th ELS
Generic Image Processing With Climb – 5th ELSGeneric Image Processing With Climb – 5th ELS
Generic Image Processing With Climb – 5th ELSChristopher Chedeau
 

Destaque (9)

JSPP: Morphing C++ into Javascript
JSPP: Morphing C++ into JavascriptJSPP: Morphing C++ into Javascript
JSPP: Morphing C++ into Javascript
 
Climb - Property-based dispatch in functional languages [Report]
Climb - Property-based dispatch in functional languages [Report]Climb - Property-based dispatch in functional languages [Report]
Climb - Property-based dispatch in functional languages [Report]
 
Climb - Property-based dispatch in functional languages [Slides]
Climb - Property-based dispatch in functional languages [Slides]Climb - Property-based dispatch in functional languages [Slides]
Climb - Property-based dispatch in functional languages [Slides]
 
Morpho math
Morpho mathMorpho math
Morpho math
 
J
JJ
J
 
Climb - A Generic and Dynamic Approach to Image Processing
Climb - A Generic and Dynamic Approach to Image ProcessingClimb - A Generic and Dynamic Approach to Image Processing
Climb - A Generic and Dynamic Approach to Image Processing
 
Climb - A Generic and Dynamic Approach to Image Processing
Climb - A Generic and Dynamic Approach to Image ProcessingClimb - A Generic and Dynamic Approach to Image Processing
Climb - A Generic and Dynamic Approach to Image Processing
 
Slides
SlidesSlides
Slides
 
Generic Image Processing With Climb – 5th ELS
Generic Image Processing With Climb – 5th ELSGeneric Image Processing With Climb – 5th ELS
Generic Image Processing With Climb – 5th ELS
 

Semelhante a Climb – Chaining Operators - Report

Managing storage management tivoli enterprise integration with tivoli storage...
Managing storage management tivoli enterprise integration with tivoli storage...Managing storage management tivoli enterprise integration with tivoli storage...
Managing storage management tivoli enterprise integration with tivoli storage...Banking at Ho Chi Minh city
 
My cool new Slideshow!
My cool new Slideshow!My cool new Slideshow!
My cool new Slideshow!Kislay Raj
 
My cool new Slideshow!
My cool new Slideshow!My cool new Slideshow!
My cool new Slideshow!Kislay Raj
 
Crando Plugins en ImageJ [de http://www.imagingbook.com/fileadmin/goodies/ijt...
Crando Plugins en ImageJ [de http://www.imagingbook.com/fileadmin/goodies/ijt...Crando Plugins en ImageJ [de http://www.imagingbook.com/fileadmin/goodies/ijt...
Crando Plugins en ImageJ [de http://www.imagingbook.com/fileadmin/goodies/ijt...drk28
 
&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />tutorialsruby
 
Deployment guide series ibm tivoli usage and accounting manager v7.1 sg247569
Deployment guide series ibm tivoli usage and accounting manager v7.1 sg247569Deployment guide series ibm tivoli usage and accounting manager v7.1 sg247569
Deployment guide series ibm tivoli usage and accounting manager v7.1 sg247569Banking at Ho Chi Minh city
 
Pragmatic Agile Web Development With Rails.3rd Edition.2009
Pragmatic   Agile Web Development With Rails.3rd Edition.2009Pragmatic   Agile Web Development With Rails.3rd Edition.2009
Pragmatic Agile Web Development With Rails.3rd Edition.2009SHC
 

Semelhante a Climb – Chaining Operators - Report (20)

test5
test5test5
test5
 
Sdd 2
Sdd 2Sdd 2
Sdd 2
 
test6
test6test6
test6
 
test4
test4test4
test4
 
test5
test5test5
test5
 
test6
test6test6
test6
 
Home automation
Home automationHome automation
Home automation
 
Managing storage management tivoli enterprise integration with tivoli storage...
Managing storage management tivoli enterprise integration with tivoli storage...Managing storage management tivoli enterprise integration with tivoli storage...
Managing storage management tivoli enterprise integration with tivoli storage...
 
My cool new Slideshow!
My cool new Slideshow!My cool new Slideshow!
My cool new Slideshow!
 
My cool new Slideshow!
My cool new Slideshow!My cool new Slideshow!
My cool new Slideshow!
 
Crando Plugins en ImageJ [de http://www.imagingbook.com/fileadmin/goodies/ijt...
Crando Plugins en ImageJ [de http://www.imagingbook.com/fileadmin/goodies/ijt...Crando Plugins en ImageJ [de http://www.imagingbook.com/fileadmin/goodies/ijt...
Crando Plugins en ImageJ [de http://www.imagingbook.com/fileadmin/goodies/ijt...
 
&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />
 
perltut
perltutperltut
perltut
 
perltut
perltutperltut
perltut
 
Perl tut
Perl tutPerl tut
Perl tut
 
Deployment guide series ibm tivoli usage and accounting manager v7.1 sg247569
Deployment guide series ibm tivoli usage and accounting manager v7.1 sg247569Deployment guide series ibm tivoli usage and accounting manager v7.1 sg247569
Deployment guide series ibm tivoli usage and accounting manager v7.1 sg247569
 
Pragmatic Agile Web Development With Rails.3rd Edition.2009
Pragmatic   Agile Web Development With Rails.3rd Edition.2009Pragmatic   Agile Web Development With Rails.3rd Edition.2009
Pragmatic Agile Web Development With Rails.3rd Edition.2009
 
Debian handbook
Debian handbookDebian handbook
Debian handbook
 
Learn c++
Learn c++Learn c++
Learn c++
 
Batch Modernization on z/OS
Batch Modernization on z/OSBatch Modernization on z/OS
Batch Modernization on z/OS
 

Último

Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfhans926745
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 

Último (20)

Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 

Climb – Chaining Operators - Report

  • 1. Component Trees and Chaining Operators in Climb Christopher Chedeau Technical Report no 1108, June 2011 revision 2295 Climb is a generic image processing library designed to be used for rapid prototyping. The implemen- tation of two component trees algorithms impacts Climb in several ways: the definition of values is ex- tended, new site sets are added and debugging utilities are improved. A detour is taken to understand the Chaining design pattern popularized by the Javascript jQuery library. The pattern is adapted to both the image processing domain and Common Lisp and is extended to introduce a parallel notation as well as better control flows. Climb est une bibliothèque de traitement d’image générique ayant pour objectif le prototypage rapide. L’implémentation de deux algorithmes d’arbre de composantes impacte Climb de plusieurs façons : la définition des valeurs est étendue, de nouveaux ensembles de sites sont ajoutés et les outils de développe- ment sont améliorés. Un détour est pris afin de comprendre le patron de conception de chaînage popularisé par la biblio- thèque jQuery. La méthode est modifiée afin de s’adapter au traitement d’image ainsi qu’à Common Lisp. Elle est également étendue via une notation parallèle ainsi qu’avec une meilleure gestion du fil d’exécution. Keywords climb, image processing, dynamic language, chaining, component tree Laboratoire de Recherche et Développement de l’Epita 14-16, rue Voltaire – F-94276 Le Kremlin-Bicêtre cedex – France Tél. +33 1 53 14 59 47 – Fax. +33 1 53 14 59 22 christopher.chedeau@lrde.epita.fr – http://www.lrde.epita.fr/
  • 2. 2 Copying this document Copyright c 2011 LRDE. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation; with the Invariant Sections being just “Copying this document”, no Front- Cover Texts, and no Back-Cover Texts. A copy of the license is provided in the file COPYING.DOC.
  • 3. Contents 1 Introduction 4 2 Component Tree 5 2.1 Component Tree . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 2.1.1 Definition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 2.1.2 Najman . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 2.1.3 Berger . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 2.2 Impact on Climb . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 2.2.1 Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 2.2.2 Developer Utilities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 2.2.3 More Site Sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 3 Chaining Operators 12 3.1 Chaining . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 3.2 Serial . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 3.3 Paralell . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 3.4 Flow Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 4 Conclusion 19 5 Bibliography 20
  • 4. Chapter 1 Introduction The image processing domain requires high performance as the inputs are big: most images nowadays are composed of millions of pixels. As a consequence, most libraries are written in C or C++ with a high focus on speed. It is often done at the expense of ease of use. Climb has been designed from the ground up to be a developer friendly library. Using Common Lisp, Climb benefits from the dynamic aspect and functional abilities of the language. Climb is in its infancy. The core aspects of the library such as sites, site sets and morphers and the implementation of most mathematical morphology operators have been established in previous work (Denuzière (2009), Chedeau (2010)). The next step is to introduce many new algorithms from various areas of image processing and see if the framework supports them. In this article, we concentrate on two different algorithms that produce the component tree of an image. The purpose of this article is not about comparing performance nor studying use cases of the two algorithms but more about showing how their implementations impacts the design of Climb. Eventually, we take a detour to the Javascript world and specifically the jQuery1 library to discover a design pattern to chain operations. We adapt it to the image processing world and improve it thanks to Common Lisp expressive power in order to "Write less and do more"2 . Acknoledgements Thanks to Didier Verna for being both a great teacher and project manager, Laurent Senta and Simon Guillot for helping out on the Climb development, Lorene Poinsot and Alex Hamelin for the help during the preparation of this report. 1 http://jquery.com/ 2 jQuery: The Write Less, Do More, JavaScript Library
  • 5. Chapter 2 Component Tree 2.1 Component Tree 2.1.1 Definition A component tree is the organization in a tree structure, thanks to the inclusion relation, of the level set connected components of an image. In other words, if we see our image in 3D where the z-coordinate is the pixel intensity. A slice of a mountain is called a connected component and two slices are connected if they are on top of each other. A visual example is available in Figure 2.1. Figure 2.1: Component tree 3D representation Gonzalez et al. (2004) We implement two algorithms to compute the component tree: Najman and Couprie (2004) and Berger et al. (2007). They are similar algorithms as they are both based on Tarjan’s union- find disjoint set forest computation (Géraud (2005)). They have been chosen because the com- ponent tree they produce is stored in two different ways.
  • 6. 2.1 Component Tree 6 Let us take a simple example. In input, Figure 2.2, we have a 3x5 image in gray level. In Figure 2.3, we label each node (or pixel) with a capital letter. 80 60 70 A B C 30 30 30 D E F 20 10 30 G H I 30 30 30 J K L 90 40 50 M N O Figure 2.2: Node Values Figure 2.3: Node Names 2.1.2 Najman The node H has the lowest value, and is therefore part of the root component of the tree. In order to climb the tree, we go to G and then there’s a floor composed of D, E, F, I, L, K, J. At this step, the tree is split in two on the nodes N and B. Each of them can join two other components O, M and C, A. The first algorithm, Najman and Couprie (2004), computes the component tree in Figure 2.4. It also provides for each node, the canonical element of its component: Figure 2.5. A B C H E E E G G H E E E E D, E, F, I, L, K, J M N O N B Figure 2.5: Components O M C A Figure 2.4: Component Tree
  • 7. 7 Component Tree 2.1.3 Berger The second algorithm, Berger et al. (2007), gives another representation of the component tree. Instead of building the tree, it provides a parent relation seen in Figure 2.6. If the node is canon- ical, the parent points to the canonical element of the parent component, else to the canonical element of its own component. In order to use the parent relation, the nodes have to be iterated in increasing order of values. Therefore, a structure containing the nodes in sorted order is also returned (Figure 2.7). B L B H G D L L L E F I H H L J K L L L G N O B N L N C A M Figure 2.6: Node Parents Figure 2.7: Sorted Nodes Climb has been designed to provide an interface that matches operations used in literature. Therefore, the implementation of the algorithms is straightforward. Figure 2.8 shows that the lisp code is the exact translation of the pseudo-code found in Berger et al. (2007) paper. CANONICALIZE - TREE (parent, f ) 0 (defun canonicalize−tree (parent sorted−sites image) 1 for each p ∈ R in reverse order do 1 (do−sites (p sorted−sites :backward) 2 q ← parent(p) 2 (let ((q (iref parent p))) 3 if f (parent(q)) = f (q) then 3 (when (value−equal (iref image (iref parent q)) (iref image q)) 4 parent(p) ← parent(q) 4 (setf (iref parent p) (iref parent q))))) 5 parent) 5 return parent Figure 2.8: Translation of the pseudo-code to real code 2.2 Impact on Climb Climb has first been developed around mathematical morphology operators such as erosion, dilation or top-hat (Chedeau (2010)). Those simple operators were a good opportunity to focus on making a stable and powerful internal architecture. The implementation of those two algo- rithms demonstrates that overall the design was good enough to support them. The changes required are explained in this section.
  • 8. 2.2 Impact on Climb 8 2.2.1 Values Berger algorithm requires to have a data structure that associates sites with sites while Najman algorithm requires to associate a site with a list of sites. The nearest concept available in Climb is the Image. It associates a site with a value, where the value is an array of elements that represents grayscale or RGB intensities. The natural evolution is to extend the notion of value. An image value can be any common lisp value: numbers, lists, strings, objects and even images. Contrary to Olena1 (in C++) and our old design, the image container is no longer required to know the type of its content. Instead, each element knows its own type. As a side- effect, it makes possible to create heterogeneous images. The writing of morphers (Chedeau (2010)) is easier as we no longer have to manually enter the output type, which can be complicated. As we make use of classes for values, the code in Figure 2.9 is also more meaningful for the reader. 1 ; Legacy v e r s i o n 2 ( image−direct−value−morpher 3 image : gray 4 ( lambda ( gray ) ( v e c t o r gray gray gray ) ) ; Reader 5 ( lambda ( rgb ) (/ ( reduce # ’+ rgb ) 3 ) ) ) ; Writer 6 7 ; Version with new Value r e p r e s e n t a t i o n 8 ( image−direct−value−morpher 9 image 10 ( lambda ( gray ) ( make−rgb : r gray : g gray : b gray ) ) ; Reader 11 ( lambda ( rgb ) ( make−gray : i (/ (+ ( value−r rgb ) ; Writer 12 ( value−g rgb ) 13 ( value−b rgb ) ) 3 ) ) ) ) Figure 2.9: Implementation of a RGB to Gray morpher In order for algorithms to be written once and work for all types of values, we use duck typing (Martelli (2000)). All images with values that implements the generic functions equal and < can be used to make a component tree. It makes the addition of new value types straightforward. The Image definition in Climb is now more in line with the image processing literature. It is nothing more than a function associates a value to a site. Each algorithm can use the best fitting implementation of the image and interpret the value as it needs to. 1 http://olena.lrde.epita.fr/
  • 9. 9 Component Tree 2.2.2 Developer Utilities make-image-[bool, gray] Basic values such as grayscale or RGB are no longer primitive types but classes. As a conse- quence, we have to call a constructor function if we want to use them from primitive types. It makes the creation of small test images harder. We introduce two functions make-image-bool and make-image-gray to help the developer. 1 ( make−image−bool ( dimensions v a l u e s ) ) 2 ( make−image−gray ( dimensions v a l u e s ) ) In order to represent boolean values, common lisp uses nil and t. As they do not have the same number of characters, it makes displaying them in a textual grid a tedious process. Looking for an alternative, we thought about 0 and 1. However, the two symbols are hard to distinguish one from the other. We finally chose to use . and #. Figure 2.10 and Figure 2.11 demonstrate how easy it is to use them. 1 ( print−image−2d 1 ( print−image−2d 2 ( make−image−bool ’ ( 4 4 ) 2 ( make−image−gray ’ ( 4 4 ) 3 "# . # . 3 ’ ( 0 10 20 30 4 . # . # 4 100 255 0 0 5 . . # . 5 10 12 18 14 6 . . . #" )) 6 0 0 0 1))) 7 7 8 ; # . # . 8 ; 0 10 20 30 9 ; . # . # 9 ; 100 255 0 0 10 ; . . # . 10 ; 10 12 18 14 11 ; . . . # 11 ; 0 0 0 1 Figure 2.10: Boolean Utilities Figure 2.11: Grayscale Utilities print-image-2d We also add a print-image-2d function that prints an image to the console. The goal of the function is to provide a practical way to visualize a small image. To make it developer-friendly, the output of boolean and grayscale images uses the same format as make-image-*. 1 ( p r i n t −image−2d ( image &o p t i o n a l ( r e p r ’ value−r e p r ) ) ) It is possible to provide a custom function to display the value. For example, it is useful to print the parent representation of the component tree. Figure 2.12 shows how to combine make-image-gray, component-tree and print-image-2d. As it is hard to get a generic library right, we first start by writing non-generic functions. Only once there are multiple functions with the same goal and different types of arguments, we can merge them. In this case, we first wrote print-image-bool-2d and extended it. However, we did not yet have the need to print other images than 2d ones. It would be premature to write down print-image without real use cases. We may also merge make-image-bool and make-image-gray with make-image in the future. We will consider doing this when we will discover more use cases.
  • 10. 2.2 Impact on Climb 10 1 ; Transforms S i t e ( 0 , 0 ) i n t o ’A’ , S i t e ( 0 , 1 ) i n t o ’ B ’ ... 2 ( defun r e p r − l a b e l ( s i t e ) 3 ( code−char 4 (+ 65 5 ( ∗ 3 (1− ( p o i n t − c o o r d i n a t e s i t e 1 ) ) ) 6 (1− ( p o i n t − c o o r d i n a t e s i t e 0 ) ) ) ) ) 7 8 ( destructuring−bind 9 ( ( t r e e components ) 10 ( component−tree 11 ( make−image−gray 12 ’(3 5) 13 ’ ( 8 0 60 70 14 30 30 30 15 20 10 30 16 30 30 30 17 90 40 5 0 ) ) 18 (4− c o n n e c t i v i t y ) ) 19 ( print−image−2d t r e e # ’ r e p r − l a b e l ) ) 20 21 ; B L B 22 ; L L L 23 ; H H L 24 ; L L G 25 ; N L N Figure 2.12: Use of component-tree and print-image-2d
  • 11. 11 Component Tree 2.2.3 More Site Sets Figure 2.8 introduces the notion of iteration on sorted site sets. Climb does not have any built- in mechanism to achieve this. However, it allows to add new types of site sets. We introduce site-set-array. It implements generic functions required by do-sites to iterate over it: reset and next. And implements two additional: push and sort. Duck typing is not only used on values but also on site sets. If an object implements both next and reset, it can be used anywhere an iterable site set is required. In order to iterate over the site-set in reverse order, we add a :backward optional argument to the reset function. Climb features many types of site sets: Box : reset (ø, :backward), next Array : reset (ø, :backward), next, push, sort Stack : reset, next, push Queue : reset, next, push Heap : reset, next, push Graph : reset (ø, :bfs, :dfs), next, push Figure 2.13 is an example of an image traversal as it if was a graph. We start to create a boolean image seen with the same dimensions as the source image using make-image. Then we insert the start element into our structure and set it as seen. In line 5, we iterate over each site of the structure. After the line 7, we add all the unseen neighbors of the current site to the structure if they haven’t been seen yet. The struct variable can be either a stack, queue or heap. The choice of this structure allows to traverse the image in various ways such as Breadth-first search, Depth-first search, "Shortest-path" or even from the lowest values to the highest. 1 ( defun t r a v e r s e ( img s t r u c t window s t a r t ) 2 ( l e t ( ( seen ( make−image img : i n i t i a l − e l e m e n t n i l ) ) ) 3 ( site−set−push s t r u c t s t a r t ) 4 ( s e t f ( i r e f seen ) t ) 5 ( do−sites ( s i t e s t r u c t ) 6 ; Do something with s i t e 7 8 ( d o − s i t e s ( neighb window s i t e ) 9 ( u n l e s s ( i r e f seen neighb ) 10 ( s e t f ( i r e f seen neighb ) t ) 11 ( site−set−push s t r u c t neighb ) ) ) ) ) ) Figure 2.13: Use of all the site-set operations
  • 12. Chapter 3 Chaining Operators jQuery is a Javascript library designed to provide unified utilities to manipulate HTML docu- ments across all the browsers and their respective quirks. It quickly grew in popularity as it introduced a new design pattern that solves well the problems the library tries to solve. jQuery is based on the chaining ability of Javascript Harmes and Diaz (2007). We are going to explain what this technique is, its use in jQuery in order to translate it for the image processing domain. Common Lisp expressiveness even allows to extend the pattern. 3.1 Chaining The idea behind chaining is execute more than one action at a time on the same object. It is trivial to implement in an Object Oriented language, the functions that can be chained should return this. Figure 3.1 is an example in Javascript. 1 function Object ( ) { } 2 3 Object . prototype = { 4 methodA : f u n c t i o n ( ) { 5 // do something 6 return this ; 7 }, 8 9 methodB : f u n c t i o n ( ) { 10 // do something 11 return this ; 12 } 13 }; 14 15 var o b j = new O b j e c t ( ) ; 16 o b j . methodA ( ) . methodB ( ) ; Figure 3.1: Javascript implementation of chaining
  • 13. 13 Chaining Operators Method chaining removes the need to declare temporary variables, and therefore makes the code much more readable and easier to write. Figure 3.2 is a real world example of chaining with jQuery. We want to process all the links of a page. We give them the external CSS class, make them open in a new tab when clicked and plug in an analytic tracking code. 1 $ ( ’ a [ @href ^=" h t t p : / / " ] ’ ) 2 . addClass ( " e x t e r n a l " ) 3 . a t t r ( " t a r g e t " , " _blank " ) 4 . c l i c k ( f u n c t i o n ( ) { /∗ a n a l y t i c s c a l l ∗/ } ) Figure 3.2: Multiple actions on the same object Once we understand the power of this construction, we can lift the limit of returning only this. Figure 3.3 is a jQuery example where chaining is used to traverse a HTML document: it finds the parent of the first list element that contains a sublist. Figure 3.4 is a sample code from the v8cgi SQL Query module1 . The last example in Figure 3.5 implements the basic concept of method chaining but in an asynchronous way (Diaz (2010)). 1 $(" li ") 1 SQL ( " s e l e c t " ) 1 $ (" < div / >") 2 . has ( " u l " ) 2 . field ("∗") 2 . f e t c h ( " n a v i g a t i o n . html " ) 3 . eq ( 1 ) 3 . table ( " users " ) 3 . addClass ( " column " ) 4 . parent ( ) 4 . limit (10) 4 . appendTo ( " # s i d e " ) Figure 3.3: Traversing a Figure 3.5: Asynchronous Ma- HTML Document Figure 3.4: SQL Query nipulation 3.2 Serial In order to extract information from an image, many small algorithms are combined together into a processing chain. The chaining technique is therefore adapted for this domain. Figure 3.6 shows a sample processing chain we would like to write. 1 Image ( " l e n a . j p g " ) 2 . togray ( ) 3 . otsu ( ) 4 . opening ( 8 _ c o n n e c t i v i t y ) 5 . save ( " lena_opening . png " ) Figure 3.6: Sample processing chain Common Lisp does not have the concept of object methods with the dot notation, instead it has generic functions. If we were to write the example it would resemble to Figure 3.7. The order of writing is reversed: the last actions are written in first. Also, the arguments of the functions are far away from the function call. 1 http://code.google.com/p/v8cgi/wiki/API_Query
  • 14. 3.2 Serial 14 1 ( save 2 ( opening 3 ( otsu 4 ( togray 5 ( load " l e n a . j p g " ) 6 ) 7 ) 8 (8− c o n n e c t i v i t y ) ) 9 " lena_opening . png " ) Figure 3.7: Direct Common Lisp implementation Instead, we can write it the traditional way using a temporary variable as seen in Figure 3.8. The code is written in the expected order but it too verbose. In this small example there are eight occurrences of img along with three setf. 1 ( l e t ( ( img ( load " l e n a . j p g " ) ) ) 2 ( s e t f img ( t o g r a y img ) ) 3 ( s e t f img ( o t s u img ) ) 4 ( s e t f img ( opening img (8− c o n n e c t i v i t y ) ) ) 5 ( save img " lena_opening . png " ) ) Figure 3.8: Processing chain using temporary variable We introduce in Climb a $ macro (in reference to jQuery). It takes a sequence of actions and combine them such as the first argument is the result of the previous action. Figure 3.9 code can either be rewritten into Figure 3.7 and Figure 3.8. The $ allows to write a code equivalent to the method chaining in Javascript: the opening parenthesis is just moved before the method name. Clojure2 , a lisp implementation on-top of the JVM3 , implements a similar operator named ->4 . 1 ($ ( load " l e n a . j p g " ) 2 ( togray ) 3 ( otsu ) 4 ( opening (8− c o n n e c t i v i t y ) ) 5 ( save " lena_opening . png " ) ) Figure 3.9: Climb $ macro 2 http://clojure.org/ 3 Java Virtual Machine 4 http://clojuredocs.org/clojure_core/clojure.core/-%3E
  • 15. 15 Chaining Operators 3.3 Paralell Method chaining and consequently the $ operator are limited to linear processes. jQuery has an end method5 in order to simulate branching. Every time a method returns an element different than this, it is being pushed to a stack. The end method pops the latest element from the stack and returns the new top. Figure 3.10 shows how to use it to set the color of foo into red and bar into green. 1 $ ( " # id " ) 2 3 . f i n d ( " . foo " ) 4 . c s s ( " c o l o r " , " red " ) 5 . end ( ) 6 7 . f i n d ( " . bar " ) 8 . c s s ( " c o l o r " , " green " ) 9 . end ( ) Figure 3.10: jQuery end example The solution adopted by jQuery is the best possible option with traditional method chaining. Since we are building our operator through macros, we can bypass this limitation. This is why we introduce the // operator seen in Figure 3.11. In essence, it spawns a new $ operation for each group of action. It allows to use one variable multiple times. The same version without // is available in Figure 3.12. 1 ( $ " # id " 1 ( l e t ( ( tmp ( $ " # id " ) ) ) 2 2 3 (// 3 ( $ tmp 4 ( ( f i n d " . foo " ) 4 ( f i n d " . foo " ) 5 ( c s s " c o l o r " " red " ) ) 5 ( c s s " c o l o r " " red " ) ) 6 6 7 ( ( f i n d " . bar " ) 7 ( $ tmp 8 ( c s s " c o l o r " " green " ) ) ) ) 8 ( f i n d " . bar " ) 9 ( c s s " c o l o r " " green " ) ) ) Figure 3.11: Climb equivalent with // Figure 3.12: Climb equivalent without // In the jQuery version, it is not possible to use the last value returned by the branches as they it be ignored by the end method. On the other hand, the // operator returns all the final values. They will be passed as arguments of the next action. Figure 3.13 is an example that shows how to compare the result of two binarization algorithms: Sauvola and Otsu. The diff function will be called with two arguments, the first one being the image through Sauvola, while the second the image after Otsu. 5 http://api.jquery.com/end/
  • 16. 3.4 Flow Control 16 1 ($ ( load " l e n a . png " ) 2 ( togray ) 3 (// 4 ( ( sauvola ) ( save " sauvola . png " ) ) 5 ( ( otsu ) ( save " o t s u . png " ) ) ) 6 ( diff ) 7 ( save " d i f f e r e n c e . png " ) ) Figure 3.13: Combine the result of the // branches 3.4 Flow Control It is possible with both $ and // operators to achieve complex behaviors with few lines of code. However, it imposes a model where each returned value will be the first argument of the next action. It is sometimes undesirable. For example, it is a common operation to time actions. Climb provides two functions timer-start and timer-print. They are not designed to be used in a chaining context. This is why we introduce the quote modifier: it calls the function the usual way. Figure 3.14 shows how to time actions and Figure 3.15 is a code with similar effect without the $ operator. 1 ( $ ( load " l e n a . png " ) 1 ( l e t ( ( tmp ( load " l e n a . png " ) ) ) 2 ’( timer−start ) 2 ( timer−start ) 3 ( otsu ) 3 ( s e t f tmp ( o t s u tmp ) ) 4 ’ ( t i m e r − p r i n t " Otsu " ) 4 ( t i m e r − p r i n t " Otsu " ) 5 ( save " l e n a _ o t s u . png " ) ) 5 ( save tmp " l e n a _ o t s u . png " ) ) 6 6 7 ; Otsu : 101ms 7 ; Otsu : 101ms Figure 3.14: Quote modifier Figure 3.15: Expanded code The quote modifier uses two distinct concepts: • Custom arguments: All the previous return values are not automatically inserted as firsts arguments. They are available through the keywords $1, $2 ... • Skip return values: The return values of the action are not used for chaining. Instead, previous return values are used. In order to get more flexibility, we also introduce the # modifier that only provides custom arguments. So far, it is possible with modifiers to express three of the four combinations: Figure 3.16. We may find use cases and introduce the last combination in the future. Custom arguments Yes No Skip return values Yes ’ none yet No # ø Figure 3.16: Available modifiers
  • 17. 17 Chaining Operators Figure 3.17 is a more complex example using the // operator as well as the ’ and # modifiers. The image is first being dispatched to the three blocks using the // operator. Each block applies a different algorithm, saves the processed image and prints the algorithm execution time using the ’ modifier. The three algorithms results are then dispatched into three blocks. Each one makes the dif- ference between two images using the diff algorithm and the # modifier. 1 ( $ ( load " l e n a g r a y . png " ) 2 3 (// 4 ( ’ ( timer−start ) 5 ( otsu ) 6 ’ ( t i m e r − p r i n t " Otsu " ) 7 ( save " o t s u . png " ) ) ; $1 8 9 ( ’ ( timer−start ) 10 ( sauvola ( box2d 1 ) ) 11 ’ ( t i m e r − p r i n t " Sauvola 1 " ) 12 ( save " sauvola1 . png " ) ) ; $2 13 14 ( ’ ( timer−start ) 15 ( sauvola ( box2d 5 ) ) 16 ’ ( t i m e r − p r i n t " Sauvola 5 " ) 17 ( save " sauvola5 . png " ) ) ) ; $3 18 19 (// 20 ( # ( d i f f $1 $2 ) ( save " diff−otsu−sauvola1 . png " ) ) 21 ( # ( d i f f $1 $3 ) ( save " diff−otsu−sauvola5 . png " ) ) 22 ( # ( d i f f $2 $3 ) ( save " diff−sauvola1−sauvola5 . png " ) ) ) ) 23 24 ; Otsu : 101ms 25 ; Sauvola 1 : 263ms 26 ; Sauvola 5 : 3407ms Figure 3.17: Comparison of three binarization techniques The generated images are shown in Figure 3.18.
  • 18. 3.4 Flow Control 18 Otsu - 101ms Sauvola 1 - 263ms Sauvola 5 - 3407ms Otsu - Sauvola 1 Otsu - Sauvola 5 Sauvola 1 - Sauvola 5 Figure 3.18: Outputs of the binarization processing chain
  • 19. Chapter 4 Conclusion We have taken two component tree algorithms from the literature and implemented them into Climb. It enlightened the parts of the library that required to be worked on. The definition of values is extended: instead of being a vector of numbers, it can now be of any type. The extensibility of site sets through a duck typing interface is used to support those algorithms. Debugging utilities are also added to improve ease of development. In order to enhance end user ability to use our library, we introduce a design pattern called method chaining popularized by the Javascript jQuery library. As we adapted it to the Common Lisp language and to the image processing context, it was clear that the current form was too restrained. We improved it to support parallel execution as well as better flow control. The image processing field is deeply rooted with languages such as C and C++. Being able to immerse it into a dynamic language such as Common Lisp gives us the ability to use a wide range of programming patterns that were not being considered. Climb improved with the use of lambda functions that powers morphers (Chedeau (2010)) and with the extended form of method chaining proposed in this technical report. There are many other patterns that could potentially be taken from dynamic languages to improve the library. Future work will be focused on exploring these new possibilities. New algorithms as well as new types of images (both structures and values) will be implemented in order to strengthen our core framework and to provide solutions to real world problems.
  • 20. Chapter 5 Bibliography Berger, Ch., Géraud, Th., Levillain, R., Widynski, N., Baillard, A., and Bertin, E. (2007). Ef- fective component tree computation with application to pattern recognition in astronomical imaging. In Proceedings of the IEEE International Conference on Image Processing (ICIP), volume 4, pages IV–41–IV–44, San Antonio, TX, USA. Chedeau, C. (2010). Functionnal approach of image processing genericity. Technical Report 1001, EPITA Research and Development Laboratory (LRDE). Denuzière, L. (2009). CLIMB: A dynamic approach to generic image processing. Technical Report 0906, EPITA Research and Development Laboratory (LRDE). Diaz, D. (2010). Asynchronous method queue chaining in javascript. http://www. dustindiaz.com/async-method-queues/. Géraud, Th. (2005). Ruminations on Tarjan’s Union-Find algorithm and connected operators. volume 30 of Computational Imaging and Vision, pages 105–116, Paris, France. Springer. Gonzalez, R., Woods, R., and Eddins, S. (2004). Digital Image Processing Using MATLAB(R). Prentice Hall. Harmes, R. and Diaz, D. (2007). Pro JavaScript Design Patterns (Recipes: a Problem-Solution Ap). Apress, 1 edition. Martelli, A. (2000). http://groups.google.com/group/comp.lang.python/msg/ e230ca916be58835. Najman, L. and Couprie, M. (2004). Quasi-linear algorithm for the component tree. In IS&T/SPIE Symposium on Electronic Imaging, In Vision Geometry XII, pages 18–22.