Révision 1

LICENCE.txt (revision 1)
1

  
2
CeCILL FREE SOFTWARE LICENSE AGREEMENT
3
Notice
4

  
5
This Agreement is a Free Software license agreement that is the result of discussions between its authors in order to ensure compliance with the two main principles guiding its drafting:
6

  
7
    firstly, compliance with the principles governing the distribution of Free Software: access to source code, broad rights granted to users,
8
    secondly, the election of a governing law, French law, with which it is conformant, both as regards the law of torts and intellectual property law, and the protection that it offers to both authors and holders of the economic rights over software.
9

  
10
The authors of the CeCILL1 license are:
11

  
12
Commissariat à l'Energie Atomique - CEA, a public scientific, technical and industrial research establishment, having its principal place of business at 25 rue Leblanc, immeuble Le Ponant D, 75015 Paris, France.
13

  
14
Centre National de la Recherche Scientifique - CNRS, a public scientific and technological establishment, having its principal place of business at 3 rue Michel-Ange, 75794 Paris cedex 16, France.
15

  
16
Institut National de Recherche en Informatique et en Automatique - INRIA, a public scientific and technological establishment, having its principal place of business at Domaine de Voluceau, Rocquencourt, BP 105, 78153 Le Chesnay cedex, France.
17
Preamble
18

  
19
The purpose of this Free Software license agreement is to grant users the right to modify and redistribute the software governed by this license within the framework of an open source distribution model.
20

  
21
The exercising of these rights is conditional upon certain obligations for users so as to preserve this status for all subsequent redistributions.
22

  
23
In consideration of access to the source code and the rights to copy, modify and redistribute granted by the license, users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors only have limited liability.
24

  
25
In this respect, the risks associated with loading, using, modifying and/or developing or reproducing the software by the user are brought to the user's attention, given its Free Software status, which may make it complicated to use, with the result that its use is reserved for developers and experienced professionals having in-depth computer knowledge. Users are therefore encouraged to load and test the suitability of the software as regards their requirements in conditions enabling the security of their systems and/or data to be ensured and, more generally, to use and operate it in the same conditions of security. This Agreement may be freely reproduced and published, provided it is not altered, and that no provisions are either added or removed herefrom.
26

  
27
This Agreement may apply to any or all software for which the holder of the economic rights decides to submit the use thereof to its provisions.
28
Article 1 - DEFINITIONS
29

  
30
For the purpose of this Agreement, when the following expressions commence with a capital letter, they shall have the following meaning:
31

  
32
Agreement: means this license agreement, and its possible subsequent versions and annexes.
33

  
34
Software: means the software in its Object Code and/or Source Code form and, where applicable, its documentation, "as is" when the Licensee accepts the Agreement.
35

  
36
Initial Software: means the Software in its Source Code and possibly its Object Code form and, where applicable, its documentation, "as is" when it is first distributed under the terms and conditions of the Agreement.
37

  
38
Modified Software: means the Software modified by at least one Contribution.
39

  
40
Source Code: means all the Software's instructions and program lines to which access is required so as to modify the Software.
41

  
42
Object Code: means the binary files originating from the compilation of the Source Code.
43

  
44
Holder: means the holder(s) of the economic rights over the Initial Software.
45

  
46
Licensee: means the Software user(s) having accepted the Agreement.
47

  
48
Contributor: means a Licensee having made at least one Contribution.
49

  
50
Licensor: means the Holder, or any other individual or legal entity, who distributes the Software under the Agreement.
51

  
52
Contribution: means any or all modifications, corrections, translations, adaptations and/or new functions integrated into the Software by any or all Contributors, as well as any or all Internal Modules.
53

  
54
Module: means a set of sources files including their documentation that enables supplementary functions or services in addition to those offered by the Software.
55

  
56
External Module: means any or all Modules, not derived from the Software, so that this Module and the Software run in separate address spaces, with one calling the other when they are run.
57

  
58
Internal Module: means any or all Module, connected to the Software so that they both execute in the same address space.
59

  
60
GNU GPL: means the GNU General Public License version 2 or any subsequent version, as published by the Free Software Foundation Inc.
61

  
62
Parties: mean both the Licensee and the Licensor.
63

  
64
These expressions may be used both in singular and plural form.
65
Article 2 - PURPOSE
66

  
67
The purpose of the Agreement is the grant by the Licensor to the Licensee of a non-exclusive, transferable and worldwide license for the Software as set forth in Article 5 hereinafter for the whole term of the protection granted by the rights over said Software.
68
Article 3 - ACCEPTANCE
69

  
70
3.1 The Licensee shall be deemed as having accepted the terms and conditions of this Agreement upon the occurrence of the first of the following events:
71

  
72
    (i) loading the Software by any or all means, notably, by downloading from a remote server, or by loading from a physical medium;
73
    (ii) the first time the Licensee exercises any of the rights granted hereunder.
74

  
75
3.2 One copy of the Agreement, containing a notice relating to the characteristics of the Software, to the limited warranty, and to the fact that its use is restricted to experienced users has been provided to the Licensee prior to its acceptance as set forth in Article 3.1 hereinabove, and the Licensee hereby acknowledges that it has read and understood it.
76
Article 4 - EFFECTIVE DATE AND TERM
77
4.1 EFFECTIVE DATE
78

  
79
The Agreement shall become effective on the date when it is accepted by the Licensee as set forth in Article 3.1.
80
4.2 TERM
81

  
82
The Agreement shall remain in force for the entire legal term of protection of the economic rights over the Software.
83
Article 5 - SCOPE OF RIGHTS GRANTED
84

  
85
The Licensor hereby grants to the Licensee, who accepts, the following rights over the Software for any or all use, and for the term of the Agreement, on the basis of the terms and conditions set forth hereinafter.
86

  
87
Besides, if the Licensor owns or comes to own one or more patents protecting all or part of the functions of the Software or of its components, the Licensor undertakes not to enforce the rights granted by these patents against successive Licensees using, exploiting or modifying the Software. If these patents are transferred, the Licensor undertakes to have the transferees subscribe to the obligations set forth in this paragraph.
88
5.1 RIGHT OF USE
89

  
90
The Licensee is authorized to use the Software, without any limitation as to its fields of application, with it being hereinafter specified that this comprises:
91

  
92
    permanent or temporary reproduction of all or part of the Software by any or all means and in any or all form.
93

  
94
    loading, displaying, running, or storing the Software on any or all medium.
95

  
96
    entitlement to observe, study or test its operation so as to determine the ideas and principles behind any or all constituent elements of said Software. This shall apply when the Licensee carries out any or all loading, displaying, running, transmission or storage operation as regards the Software, that it is entitled to carry out hereunder.
97

  
98
5.2 ENTITLEMENT TO MAKE CONTRIBUTIONS
99

  
100
The right to make Contributions includes the right to translate, adapt, arrange, or make any or all modifications to the Software, and the right to reproduce the resulting software.
101

  
102
The Licensee is authorized to make any or all Contributions to the Software provided that it includes an explicit notice that it is the author of said Contribution and indicates the date of the creation thereof.
103
5.3 RIGHT OF DISTRIBUTION
104

  
105
In particular, the right of distribution includes the right to publish, transmit and communicate the Software to the general public on any or all medium, and by any or all means, and the right to market, either in consideration of a fee, or free of charge, one or more copies of the Software by any means.
106

  
107
The Licensee is further authorized to distribute copies of the modified or unmodified Software to third parties according to the terms and conditions set forth hereinafter.
108
5.3.1 DISTRIBUTION OF SOFTWARE WITHOUT MODIFICATION
109

  
110
The Licensee is authorized to distribute true copies of the Software in Source Code or Object Code form, provided that said distribution complies with all the provisions of the Agreement and is accompanied by:
111

  
112
    a copy of the Agreement,
113

  
114
    a notice relating to the limitation of both the Licensor's warranty and liability as set forth in Articles 8 and 9,
115

  
116
and that, in the event that only the Object Code of the Software is redistributed, the Licensee allows future Licensees unhindered access to the full Source Code of the Software by indicating how to access it, it being understood that the additional cost of acquiring the Source Code shall not exceed the cost of transferring the data.
117
5.3.2 DISTRIBUTION OF MODIFIED SOFTWARE
118

  
119
When the Licensee makes a Contribution to the Software, the terms and conditions for the distribution of the resulting Modified Software become subject to all the provisions of this Agreement.
120

  
121
The Licensee is authorized to distribute the Modified Software, in source code or object code form, provided that said distribution complies with all the provisions of the Agreement and is accompanied by:
122

  
123
    a copy of the Agreement,
124

  
125
    a notice relating to the limitation of both the Licensor's warranty and liability as set forth in Articles 8 and 9,
126

  
127
and that, in the event that only the object code of the Modified Software is redistributed, the Licensee allows future Licensees unhindered access to the full source code of the Modified Software by indicating how to access it, it being understood that the additional cost of acquiring the source code shall not exceed the cost of transferring the data.
128
5.3.3 DISTRIBUTION OF EXTERNAL MODULES
129

  
130
When the Licensee has developed an External Module, the terms and conditions of this Agreement do not apply to said External Module, that may be distributed under a separate license agreement.
131
5.3.4 COMPATIBILITY WITH THE GNU GPL
132

  
133
The Licensee can include a code that is subject to the provisions of one of the versions of the GNU GPL in the Modified or unmodified Software, and distribute that entire code under the terms of the same version of the GNU GPL.
134

  
135
The Licensee can include the Modified or unmodified Software in a code that is subject to the provisions of one of the versions of the GNU GPL, and distribute that entire code under the terms of the same version of the GNU GPL.
136
Article 6 - INTELLECTUAL PROPERTY
137
6.1 OVER THE INITIAL SOFTWARE
138

  
139
The Holder owns the economic rights over the Initial Software. Any or all use of the Initial Software is subject to compliance with the terms and conditions under which the Holder has elected to distribute its work and no one shall be entitled to modify the terms and conditions for the distribution of said Initial Software.
140

  
141
The Holder undertakes that the Initial Software will remain ruled at least by this Agreement, for the duration set forth in Article 4.2.
142
6.2 OVER THE CONTRIBUTIONS
143

  
144
The Licensee who develops a Contribution is the owner of the intellectual property rights over this Contribution as defined by applicable law.
145
6.3 OVER THE EXTERNAL MODULES
146

  
147
The Licensee who develops an External Module is the owner of the intellectual property rights over this External Module as defined by applicable law and is free to choose the type of agreement that shall govern its distribution.
148
6.4 JOINT PROVISIONS
149

  
150
The Licensee expressly undertakes:
151

  
152
    not to remove, or modify, in any manner, the intellectual property notices attached to the Software;
153

  
154
    to reproduce said notices, in an identical manner, in the copies of the Software modified or not.
155

  
156
The Licensee undertakes not to directly or indirectly infringe the intellectual property rights of the Holder and/or Contributors on the Software and to take, where applicable, vis-à-vis its staff, any and all measures required to ensure respect of said intellectual property rights of the Holder and/or Contributors.
157
Article 7 - RELATED SERVICES
158

  
159
7.1 Under no circumstances shall the Agreement oblige the Licensor to provide technical assistance or maintenance services for the Software.
160

  
161
However, the Licensor is entitled to offer this type of services. The terms and conditions of such technical assistance, and/or such maintenance, shall be set forth in a separate instrument. Only the Licensor offering said maintenance and/or technical assistance services shall incur liability therefor.
162

  
163
7.2 Similarly, any Licensor is entitled to offer to its licensees, under its sole responsibility, a warranty, that shall only be binding upon itself, for the redistribution of the Software and/or the Modified Software, under terms and conditions that it is free to decide. Said warranty, and the financial terms and conditions of its application, shall be subject of a separate instrument executed between the Licensor and the Licensee.
164
Article 8 - LIABILITY
165

  
166
8.1 Subject to the provisions of Article 8.2, the Licensee shall be entitled to claim compensation for any direct loss it may have suffered from the Software as a result of a fault on the part of the relevant Licensor, subject to providing evidence thereof.
167

  
168
8.2 The Licensor's liability is limited to the commitments made under this Agreement and shall not be incurred as a result of in particular: (i) loss due the Licensee's total or partial failure to fulfill its obligations, (ii) direct or consequential loss that is suffered by the Licensee due to the use or performance of the Software, and (iii) more generally, any consequential loss. In particular the Parties expressly agree that any or all pecuniary or business loss (i.e. loss of data, loss of profits, operating loss, loss of customers or orders, opportunity cost, any disturbance to business activities) or any or all legal proceedings instituted against the Licensee by a third party, shall constitute consequential loss and shall not provide entitlement to any or all compensation from the Licensor.
169
Article 9 - WARRANTY
170

  
171
9.1 The Licensee acknowledges that the scientific and technical state-of-the-art when the Software was distributed did not enable all possible uses to be tested and verified, nor for the presence of possible defects to be detected. In this respect, the Licensee's attention has been drawn to the risks associated with loading, using, modifying and/or developing and reproducing the Software which are reserved for experienced users.
172

  
173
The Licensee shall be responsible for verifying, by any or all means, the suitability of the product for its requirements, its good working order, and for ensuring that it shall not cause damage to either persons or properties.
174

  
175
9.2 The Licensor hereby represents, in good faith, that it is entitled to grant all the rights over the Software (including in particular the rights set forth in Article 5).
176

  
177
9.3 The Licensee acknowledges that the Software is supplied "as is" by the Licensor without any other express or tacit warranty, other than that provided for in Article 9.2 and, in particular, without any warranty as to its commercial value, its secured, safe, innovative or relevant nature.
178

  
179
Specifically, the Licensor does not warrant that the Software is free from any error, that it will operate without interruption, that it will be compatible with the Licensee's own equipment and software configuration, nor that it will meet the Licensee's requirements.
180

  
181
9.4 The Licensor does not either expressly or tacitly warrant that the Software does not infringe any third party intellectual property right relating to a patent, software or any other property right. Therefore, the Licensor disclaims any and all liability towards the Licensee arising out of any or all proceedings for infringement that may be instituted in respect of the use, modification and redistribution of the Software. Nevertheless, should such proceedings be instituted against the Licensee, the Licensor shall provide it with technical and legal assistance for its defense. Such technical and legal assistance shall be decided on a case-by-case basis between the relevant Licensor and the Licensee pursuant to a memorandum of understanding. The Licensor disclaims any and all liability as regards the Licensee's use of the name of the Software. No warranty is given as regards the existence of prior rights over the name of the Software or as regards the existence of a trademark.
182
Article 10 - TERMINATION
183

  
184
10.1 In the event of a breach by the Licensee of its obligations hereunder, the Licensor may automatically terminate this Agreement thirty (30) days after notice has been sent to the Licensee and has remained ineffective.
185

  
186
10.2 A Licensee whose Agreement is terminated shall no longer be authorized to use, modify or distribute the Software. However, any licenses that it may have granted prior to termination of the Agreement shall remain valid subject to their having been granted in compliance with the terms and conditions hereof.
187
Article 11 - MISCELLANEOUS
188
11.1 EXCUSABLE EVENTS
189

  
190
Neither Party shall be liable for any or all delay, or failure to perform the Agreement, that may be attributable to an event of force majeure, an act of God or an outside cause, such as defective functioning or interruptions of the electricity or telecommunications networks, network paralysis following a virus attack, intervention by government authorities, natural disasters, water damage, earthquakes, fire, explosions, strikes and labor unrest, war, etc.
191

  
192
11.2 Any failure by either Party, on one or more occasions, to invoke one or more of the provisions hereof, shall under no circumstances be interpreted as being a waiver by the interested Party of its right to invoke said provision(s) subsequently.
193

  
194
11.3 The Agreement cancels and replaces any or all previous agreements, whether written or oral, between the Parties and having the same purpose, and constitutes the entirety of the agreement between said Parties concerning said purpose. No supplement or modification to the terms and conditions hereof shall be effective as between the Parties unless it is made in writing and signed by their duly authorized representatives.
195

  
196
11.4 In the event that one or more of the provisions hereof were to conflict with a current or future applicable act or legislative text, said act or legislative text shall prevail, and the Parties shall make the necessary amendments so as to comply with said act or legislative text. All other provisions shall remain effective. Similarly, invalidity of a provision of the Agreement, for any reason whatsoever, shall not cause the Agreement as a whole to be invalid.
197
11.5 LANGUAGE
198

  
199
The Agreement is drafted in both French and English and both versions are deemed authentic.
200
Article 12 - NEW VERSIONS OF THE AGREEMENT
201

  
202
12.1 Any person is authorized to duplicate and distribute copies of this Agreement.
203

  
204
12.2 So as to ensure coherence, the wording of this Agreement is protected and may only be modified by the authors of the License, who reserve the right to periodically publish updates or new versions of the Agreement, each with a separate number. These subsequent versions may address new issues encountered by Free Software.
205

  
206
12.3 Any Software distributed under a given version of the Agreement may only be subsequently distributed under the same version of the Agreement or a subsequent version, subject to the provisions of Article 5.3.4.
207
Article 13 - GOVERNING LAW AND JURISDICTION
208

  
209
13.1 The Agreement is governed by French law. The Parties agree to endeavor to seek an amicable solution to any disagreements or disputes that may arise during the performance of the Agreement.
210

  
211
13.2 Failing an amicable solution within two (2) months as from their occurrence, and unless emergency proceedings are necessary, the disagreements or disputes shall be referred to the Paris Courts having jurisdiction, by the more diligent Party.
212

  
213
1 CeCILL stands for Ce(a) C(nrs) I(nria) L(ogiciel) L(ibre)
214
Version 2.0 dated 2006-09-05.
lsm3D_compile.sh (revision 1)
1
#! /bin/bash
2

  
3
# 1. Choose an appropriate C++ compiler, that supports OpenMP.
4
# ============================================================
5

  
6
# For Linux (Default choice):
7
# --------------------------
8
CCPP='g++'
9

  
10
# For MacOS X you may want to change it:
11
# ---------------------------
12
#CCPP='g++-mp-6'
13
#CCPP='clang++'  
14
#CCPP='gcc-4.6'
15
      
16
#For Windows:
17
# -----------------
18

  
19
# 2. Compiling options, including link to X11 library
20
# ====================================================
21
compiling_options='-O2 -lm -lpthread -lX11 -I/usr/X11R6/include -L/usr/X11R6/lib -L/opt/X11/lib -I/opt/X11/include'
22

  
23
# 3. Path to binaries
24
# ====================
25
bin_directory='../bin'
26

  
27

  
28
# 4. Compile
29
# ==========
30
cd src
31
echo '------------------------------------'
32
echo 'compiling lsm_contour...'
33
$CCPP -o $bin_directory/lsm_contour lsm_contour.cpp $compiling_options
34

  
35
echo 'compiling lsm_cells...'
36
$CCPP -o $bin_directory/lsm_cells lsm_cells.cpp $compiling_options -fopenmp 
37

  
38
echo 'Done!'
39
cd ..
0 40

  
README_LSM.txt (revision 1)
1
----------------------------------------------------------------------
2
			        - lsm3d -
3
    Tools for segmenting 3D images of plant tissues 
4
     at multiple scales using the level set method¶
5
----------------------------------------------------------------------
6
Copyright 2016 ENS de Lyon, see accompanying file LICENSE.txt
7
 
8
Authors :
9
Typhaine Moreau, Annamaria Kiss <annamaria.kiss@ens-lyon.fr.fr>
10
(Laboratoire Reproduction et Développement des Plantes, Univ Lyon, ENS de Lyon, UCB Lyon 1, CNRS, INRA, F-69342, Lyon, France)
11
----------------------------------------------------------------------
12

  
13
The "lsm3d" tools
14
-----------------
15
- lsm_contour --> detects the outer surface of the tissue
16
- lsm_cells --> used to cellular segmentation or nuclei detection
17

  
18
Dependencies
19
-------------
20
The levelset tools make use of the CImg image processing C++ library, which in turn needs Xlib library.
21
Furthermore, the lsm_cells tool is parallelized using OpenMP.
22

  
23
In particular, if you do not have Xlib on your computer, you may add it:
24
- on Ubuntu:
25
    sudo apt-get install libx11-dev
26
- on MacOS X:
27
    install xQuartz from www.xquartz.org
28

  
29
Download
30
--------
31
In a terminal go to the directory where you wish to download and install the tool
32
cd Path_to_your_directory
33
svn checkout http://forge.cbp.ens-lyon.fr/svn/lsm3d
34

  
35
Compile
36
--------
37
cd lsm3D
38
./lsm3D_compile.sh
39

  
40
Troubleshooting if problems with compilation :
41
In lsm3D_compile.sh
42
- you might have to choose an appropriate compiler, which supports OpenMP.
43
- you might need to precise the location of the X11 library in the compilation options.
44

  
45

  
46
The following binaries will be generated in the bin directory :
47
--------------------------------------------------------------
48
- lsm_contour --> detects the outer surface of the tissue
49
- lsm_cells --> used to cellular segmentation or nuclei detection
50

  
51

  
52
**** lsm_contour --> detects the outer surface of the tissue
53
-------------------------------------------------------
54

  
55
Usage : lsm_contour img t_up t_down a b smooth perUp perDown
56
Examples for parameter values:
57
------------------------------
58
img : grayscale image of cells, (.inr or .inr.gz)
59
Upper threshold : t_up = 20
60
Down threshold : t_down = 5
61
Area term : a = 0 (0.5, 1)
62
Curvature term : b = 0 (1)
63
Gaussian filter : smooth = 1 (0, if image already filtered)
64
Stop criteria : the contour evolution is in [perDown,perUp] for 10 consecutive iterations
65
     perUp = 0.002, perDown = -0.002
66

  
67
Test :
68
------
69
lsm_detect_contour sample-stack.inr.gz 20 10 0 0 1 0.002 -0.002
70

  
71

  
72
**** lsm_cells --> for cellular segmentation or nuclei detection
73
-------------------------------------------------------------
74

  
75
Usage : lsm_cells img img_wat img_contour erosion [a b smooth lsm_type]
76
----------------- 
77
img : grayscale image of cells, (.inr or .inr.gz)
78
img_wat : image of seeds, (.inr or .inr.gz)
79
img_contour : mask, where cells do not evolve, (.inr or .inr.gz)
80
              if 'None', then cells can evolve on the whole image
81
erosion : amount of erosion of seeds for initialisation (uint8) --> -2, 0, 2
82
              if 0, then no erosion or dilation
83
              if negative, then a dilation is performed
84
a : area term (float) --> 0 or 0.5 or 1 (the default is 0.5)
85
              if negative, the object retracts
86
              if positive, the object inflates
87
b : curvature term (float) --> 0 or 1 (the default is 0)
88
gamma : scale parameter (float>0) --> 0.5 or 1 (the default is 1)
89
smooth : gaussian blur to apply to the image (int) --> 0 or 1 (the default is 0)
90
lsm_type : image, gradient or hessien based evolution --> 'i', 'g' or 'h' (the default is g)
91

  
92
Test :
93
------
94
lsm_cells sample-satck.inr.gz sample-satck-wat.inr.gz 'None' 2 0.3 0 0.2 1 'h'
95
or
96
lsm_cells sample-satck.inr.gz sample-satck-wat.inr.gz sample-satck_LSMcont20-10a0b0s1/sample-satck_LSMcont20-10a0b0s1.inr.gz 2 0.3 0 0.2 1 'h'
97

  
98

  
src/lsm_cells.cpp (revision 1)
1
/*
2
Level-set Method to detect cell's contours
3
- Parallel standard version -
4
       
5
       Copyright 2016 ENS de Lyon
6

  
7
       File author(s):
8
           Typhaine Moreau, Annamaria Kiss <annamaria.kiss@ens-lyon.fr.fr>
9
       See accompanying file LICENSE.txt
10

  
11
To compile :
12
 g++ -o lsm_cells lsm_cells.cpp -O2 -L/usr/X11R6/lib -lm -lpthread -lX11 -fopenmp
13
 Needs CImg.h and lsm_lib.h
14

  
15
To execute :
16
 ./lsm_cells img img_wat img_contour erosion a b gamma smooth type
17

  
18
 image in .inr or .inr.gz, save in .inr.gz
19
 img : grayscale image of cells (unsigned char)
20
 img_wat : watershed 16bits image (unsigned short) with background label 1 and cells labels >1
21
 img_contour : binary image with background=1, all cells=0 (unsigned char)
22
 erosion : amount of erosion for each cell in watershed image (int)
23
 a : area term (float) --> 0 or 0.5 or 1 (the default is 0.5)
24
             if negative, the object retracts
25
             if positive, the object inflates
26
 b : curvature term (float) --> 0 or 1 (the default is 0)
27
 gamma : scale parameter (float>0) --> 0.5 or 1 (the default is 1)
28
 smooth : gaussian blur to apply to the image (int) --> 0 or 1 (the default is 0)
29
 lsm_type : image, gradient or hessien based evolution --> 'i', 'g' or 'h' (the default is g)
30
*/
31

  
32
#include <iostream>
33
#include <math.h>
34
#include <sstream>
35
#include <vector>
36
#include <fstream>
37
#include <omp.h>
38

  
39
#include "CImg.h"
40
#include "lsm_lib.h"
41

  
42
using namespace cimg_library;
43
using namespace std;
44

  
45

  
46
//Return list of cell label
47
//---------------------------------------------------------------------
48
vector<int> index(const CImg<unsigned short> & wat, int nbcells)
49
{
50
  vector<int> list;
51
  vector<bool> test(nbcells,false);
52
  cimg_forXYZ(wat,x,y,z)
53
    {
54
      int ind=wat(x,y,z);
55
      if((test[ind]==false)and(ind!=1)and(ind!=0))
56
	{
57
	  list.push_back(ind);
58
	  test[ind]=true;
59
	}
60
    }
61
  return list;
62
}
63

  
64
//Return crop psi image and it's min coordinates for one cell 
65
//--------------------------------------------------------------------
66
CImg<float> box_cell(const CImg<unsigned short> & wat, int marge,int erosion, int c0,int indice, int &xmin, int &ymin, int &zmin)
67
{
68
  //search box (min and max coordinates with a marge)
69
  xmin=wat._width;
70
  ymin=wat._height;
71
  zmin=wat._depth;
72
  int xmax=0;
73
  int ymax=0;
74
  int zmax=0;
75
  cimg_forXYZ(wat,x,y,z)
76
    {
77
      if(wat(x,y,z)==indice)
78
	{
79
	  if(x>xmax){xmax=x;}else if(x<xmin){xmin=x;}
80
	  if(y>ymax){ymax=y;}else if(y<ymin){ymin=y;}
81
	  if(z>zmax){zmax=z;}else if(z<zmin){zmin=z;}
82
	}
83
    }
84
  //marge and border conditions
85
  xmin=xmin-marge;
86
  if(xmin<0){xmin=0;}
87
  ymin=ymin-marge;
88
  if(ymin<0){ymin=0;}
89
  zmin=zmin-marge;
90
  if(zmin<0){zmin=0;}
91
  xmax=xmax+marge;
92
  if(xmax>=wat._width){xmax=wat._width-1;}
93
  ymax=ymax+marge;
94
  if(ymax>=wat._height){ymax=wat._height-1;}
95
  zmax=zmax+marge;
96
  if(zmax>=wat._depth){zmax=wat._depth-1;}
97

  
98
  //crop wat image to the size of box, make binary
99
  CImg<unsigned short>binary=wat.get_crop(xmin,ymin,zmin,0,xmax,ymax,zmax,0);
100
  cimg_forXYZ(binary,x,y,z)
101
    {
102
      if(binary(x,y,z)==indice){binary(x,y,z)=1;}
103
      else {binary(x,y,z)=0;}
104
    }
105

  
106
  //erode binary but not completely (vol stay >0)
107
  int vol=binary.sum();
108
  int nb_ero=0;
109
  while((vol>0)and(nb_ero<abs(erosion)))
110
  {
111
    CImg<unsigned char> binary_erode=binary.get_erode(3,3,3); 
112
	if (erosion<0) 
113
	{
114
		for(int i=0;i<3;i++)
115
		{
116
		binary=binary.get_dilate(2,2,2);
117
		}
118
		binary_erode=binary;
119
	}
120
      vol=binary_erode.sum();
121
      if(vol>0)
122
	{
123
	  binary=binary_erode;
124
	  nb_ero+=1;
125
	}
126
    }
127

  
128
  //initalize psi
129
  CImg<float>psi=binary;
130
  cimg_forXYZ(psi,x,y,z)
131
    {
132
      if(binary(x,y,z)==0){psi(x,y,z)=c0;}
133
      else {psi(x,y,z)=-c0;}
134
    }
135
  return psi;
136
}
137

  
138

  
139
//LSM segment : edge detection
140
//---------------------------------------------------------------------
141
CImg<float> lsm_segment2(CImg<float> psi,CImg<float> const & g,CImgList<float> const & gg,CImg<float> const & h, int lam, float mu,float alf, float beta, float epsilon, int dt, vector<int> min_list)
142
{
143
  int timestep_max=2000;
144
  int evolution_min=1;
145
  //int evolution_max=-1;
146
  int it=0;
147
  int it_stop=0;
148
  bool contour_evolve=true;
149
  int backsegm=0;
150
  CImg<float> psi_old=psi;
151
  cimg_forXYZ(psi,x,y,z)
152
    {
153
      if(psi(x,y,z)>=0){backsegm+=1;}
154
    }
155

  
156
  while((it<timestep_max)and(contour_evolve==true)and(backsegm>30))
157
    {
158
      psi_old=psi;
159
      //evolution
160
      psi=evolution_AK2_contour_cells(psi,g,gg,h,lam,mu,alf,beta,epsilon,dt,min_list);
161
      //new segmentation
162
      int new_backsegm=0;
163
      cimg_forXYZ(psi,x,y,z)
164
	{
165
	  if(psi(x,y,z)>=0){new_backsegm+=1;}
166
	}
167
	  
168
      //Stop criteria
169
      // * if the cell would disappear, we stop
170
      if(new_backsegm==0)
171
			{psi=psi_old;
172
		     contour_evolve=false;}
173
      
174
      int bg_evolution=abs(new_backsegm-backsegm);
175
	
176
      // * if the evolution is less then evolution_min 3 consecutive times
177
      if((it>10) and (bg_evolution<=evolution_min) )
178
	{
179
	  it_stop+=1;
180
	  if(it_stop>3)
181
	    {contour_evolve=false;}
182
	}
183
      else
184
	{
185
	  it_stop=0;
186
	}
187

  
188

  
189
      it+=1;
190
      backsegm=new_backsegm;
191
    }
192
  return psi;
193
}
194

  
195

  
196
//Reconstruct full segmented image from cell's images
197
//---------------------------------------------------------------
198
CImg<unsigned short> reconstruct(const CImg<unsigned char> & background,const vector<CImg<float> > & psi_list, const vector< vector<int> > & min_list, int nbcells,const vector<int> & list)
199
{
200
  CImg<unsigned short> res=background;
201
  for(int i=0;i<nbcells;i++)
202
    {
203
      cimg_forXYZ(psi_list[i],xb,yb,zb)
204
	{
205
	  int x=xb+min_list[i][0];
206
	  int y=yb+min_list[i][1];
207
	  int z=zb+min_list[i][2];
208
	  if(psi_list[i](xb,yb,zb)>=0)
209
	    {res(x,y,z)=list[i];}
210
	}
211
    }
212
  return res;
213
}
214

  
215
//Reconstruct segmented image from cell's images and treat overlap
216
//---------------------------------------------------------------
217
CImg<unsigned short> reconstruct_overlap(CImg<unsigned char> const &  background,const vector<CImg<float> > & psi_list, const vector< vector<int> > & min_list, int nbcells, CImg<unsigned char> &free, const vector<int> & list)
218
{
219
  CImg<unsigned short> res=background;
220
  free=background;
221
  for(int i=0;i<nbcells;i++)
222
    {
223
      cimg_forXYZ(psi_list[i],xb,yb,zb)
224
	{
225
	  int x=xb+min_list[i][0];
226
	  int y=yb+min_list[i][1];
227
	  int z=zb+min_list[i][2];
228
	  if(psi_list[i](xb,yb,zb)>=0)
229
	    {
230
	      res(x,y,z)=list[i];
231
	      free(x,y,z)+=1;
232
	    }
233
	}
234
    }
235
  cimg_forXYZ(free,x,y,z)
236
    {
237
      if(free(x,y,z)>1)
238
	{
239
	  if(background(x,y,z)==1)
240
	    {
241
	      free(x,y,z)=1;
242
	      res(x,y,z)=1;
243
	    }
244
	  else
245
	    {
246
	      free(x,y,z)=0;
247
	      res(x,y,z)=0;
248
	    }
249
	}
250
    }
251
  return res;
252
}
253

  
254

  
255
//-----------------------------------------------------------------------------------------------
256
//******************************************  MAIN **********************************************
257
//-----------------------------------------------------------------------------------------------
258

  
259
int main (int argc, char* argv[])
260
{
261
  double begin=omp_get_wtime();
262

  
263
  if(argc<5)
264
    {
265
    cout<<"!! wrong number of arguments ("<<argc<<")"<<endl;
266
    cout<<"Usage : lsm_cells img img_wat img_contour erosion [a b smooth lsm_type]"<<endl;
267
    cout<<"----------------- "<<endl;  
268
	cout<<"img : grayscale image of cells, (.inr or .inr.gz)"<<endl;
269
	cout<<"img_wat : image of seeds, (.inr or .inr.gz)"<<endl;
270
	cout<<"img_contour : mask, where cells do not evolve, (.inr or .inr.gz)"<<endl;
271
	cout<<"              if 'None', then cells can evolve on the whole image"<<endl;
272
	cout<<"erosion : amount of erosion of seeds for initialisation (uint8) --> -2, 0, 2"<<endl;
273
	cout<<"              if 0, then no erosion or dilation"<<endl;
274
	cout<<"              if negative, then a dilation is performed"<<endl;
275
	cout<<"a : area term (float) --> 0 or 0.5 or 1 (the default is 0.5)"<<endl;
276
	cout<<"              if negative, the object retracts"<<endl;
277
	cout<<"              if positive, the object inflates"<<endl;
278
	cout<<"b : curvature term (float) --> 0 or 1 (the default is 0)"<<endl;
279
	cout<<"gamma : scale parameter (float>0) --> 0.5 or 1 (the default is 1)"<<endl;
280
	cout<<"smooth : gaussian blur to apply to the image (int) --> 0 or 1 (the default is 0)"<<endl;
281
    cout<<"lsm_type : image, gradient or hessien based evolution --> 'i', 'g' or 'h' (the default is g)"<<endl;  
282
      return 0;
283
    }
284

  
285
  //----------------------------------------------read images and check the names
286
  //Original image
287
  CImg<char> description;
288
  float tailleVoxel[3] = {0}; // resolution initialisation
289
  
290
  bool gzipped=false;
291
  
292
  string filename_img=argv[1];
293
  CImg<unsigned char> img_prev;
294
  if(filename_img.compare(filename_img.size()-4,4,".inr")==0)
295
    {
296
      img_prev.load(filename_img.c_str());
297
      img_prev.get_load_inr(filename_img.c_str(),tailleVoxel); // reads resolution
298
    }
299
  else if(filename_img.compare(filename_img.size()-7,7,".inr.gz")==0)
300
    {
301
	  gzipped = true;
302
      string oldname = filename_img;
303
      filename_img.erase(filename_img.size()-3);
304
      string zip="gunzip -c "+oldname+" > "+filename_img;
305
      if(system(zip.c_str())); // decompress image file
306
      img_prev.load(filename_img.c_str());
307
      img_prev.get_load_inr(filename_img.c_str(),tailleVoxel); // reads resolution
308
      zip="rm "+filename_img;
309
      if(system(zip.c_str())); //removes decompressed image  
310
    }
311
  else
312
    {cout<<"!! wrong file extension : "<<filename_img<<endl;
313
      return 0;}
314
  CImg<float> img=img_prev;
315
  img_prev.assign();
316
  cout<<"original image : "<<filename_img<<endl;
317
  cout<<"size : "<<img.size()<<endl;
318
  cout<<"size of original image : "<< img._width<<' '<< img._height <<' '<< img._depth<<' '<< endl;
319
  
320
  //Watershed
321
  string filename=argv[2];
322
  CImg<unsigned short> wat;
323
  if(filename.compare(filename.size()-4,4,".inr")==0)
324
    {
325
      wat.load(filename.c_str());
326
    }
327
  else if(filename.compare(filename.size()-7,7,".inr.gz")==0)
328
    {
329
      wat.load_gzip_external(filename.c_str());
330
      filename.erase(filename.size()-3);
331
    }
332
  else
333
    {cout<<"!! wrong file extension : "<<filename<<endl;
334
      return 0;}
335
  cout<<"watershed image : "<<filename<<endl;
336
cout<<"size : "<<wat.size()<<endl;
337
  cout<<"size of original image : "<< wat._width<<' '<< wat._height <<' '<< wat._depth<<' '<< endl;
338
  
339
  //Background
340
  string filename_bg=argv[3];
341
  CImg<unsigned char> background(img._width, img._height, img._depth,1,0);
342
   if(filename_bg.compare("None")==0)
343
    {
344
       cout<<"!! no background entered !!"<<endl;
345
    }
346
    else if(filename_bg.compare(filename_bg.size()-4,4,".inr")==0)
347
    {
348
      background.load(filename_bg.c_str());
349
    }
350
  else if(filename_bg.compare(filename_bg.size()-7,7,".inr.gz")==0)
351
    {
352
      background.load_gzip_external(filename_bg.c_str());
353
      filename_bg.erase(filename_bg.size()-3);
354
    }
355
  else
356
    {cout<<"!! wrong file extension : "<<filename_bg<<endl;
357
      return 0;}
358
  cout<<"background image : "<<filename_bg<<endl;
359
  
360
  if((wat.size()!=img.size())or(background.size()!=img.size()))
361
    {
362
      cout<<"!! images are not the same size"<<endl;
363
      return 0;
364
    }
365
  else cout<<"size : "<<img.size()<<endl;
366

  
367

  
368
  //---------------------------------------------------------------Parameters
369
  //model parameters
370
  
371
  int c0=-4;
372
  int erosion=atoi(argv[4]);
373
  int marge=10; 
374
  
375
  int lam=10;
376
  float alf=0.5;
377
  float beta=0;
378
  float gamma=1;
379
  float smooth=0;
380
  string lsm_type="g";
381
  
382
  string ar=argv[4];
383
  string insert="_cellLSM-d"+ar;
384
  if(argc>5)
385
    {
386
    alf=atof(argv[5]);
387
    ar=argv[5];
388
    insert=insert+"-a"+ar;
389
    }
390
  if(argc>6)
391
    {
392
    beta=atof(argv[6]);
393
    ar=argv[6];
394
    insert+="-b"+ar;
395
    }
396
  if(argc>7)
397
    {
398
    gamma=atof(argv[7]);
399
    ar=argv[7];
400
    insert+="-g"+ar;
401
	}
402
  if(argc>8)
403
    {
404
    smooth=atof(argv[8]);
405
    ar=argv[8];
406
    insert+="-s"+ar;
407
	}
408
  if(argc>9)
409
    {
410
	lsm_type=argv[9];
411
	ar=argv[9];
412
	insert+="-"+ar;
413
	}
414
	
415
  
416

  
417
  //numerical parameters
418
  float epsilon=0.5;
419
  int dt=1;   //it was 50, changed into 1 the 2015/10/16
420
  float mu=0.1/dt;
421
  int timestep_max=10000; // it was 1000, changed into 10000 the 2015/10/16
422

  
423

  
424
  //------------------------------------Names and directories
425
  //new name with arguments
426
  filename.insert(filename.size()-4,insert);
427

  
428
  //create directories and update names
429
  size_t test=filename.rfind("/");
430
  if(test!=filename.npos)
431
    {filename.erase(0,test+1);}
432
  string outputdir=filename;
433
  outputdir.erase(filename.size()-4);
434
  string mkdir="mkdir -p "+outputdir;
435
  if(system(mkdir.c_str())); 
436

  
437
  string filename_txt=outputdir+"/"+filename;
438
  filename_txt.erase(filename_txt.size()-4);
439
  filename=outputdir+"/"+filename;
440
  string wat_eroded_name=filename;
441
  wat_eroded_name.insert(filename.size()-4,"_eroded");
442
  string edge_detection_name=filename;
443
  edge_detection_name.insert(filename.size()-4,"_evoEdge");
444
  string edge_evolve_name=filename;
445
  edge_evolve_name.insert(filename.size()-4,"_final");
446

  
447
  //txt files 
448
  ofstream file;
449
  string txt_name=filename_txt+".txt";
450
  file.open(txt_name.c_str());
451
  file<<argv[0]<<endl;
452
  time_t t;
453
  struct tm * timeinfo;
454
  time(&t);
455
  timeinfo=localtime(&t);
456
  file<<asctime(timeinfo);
457
  file<<"image : "<<argv[1]<<endl;
458
  file<<"watershed : "<<argv[2]<<endl;
459
  file<<"background : "<<argv[3]<<endl;
460
  file<<"_________________________________"<<endl;
461
  file<<"Parameters"<<endl;
462
  file<<"lsm_type : "<<lsm_type<<endl;
463
  file<<"lambda : "<<lam<<endl;
464
  file<<"alpha : "<<alf<<endl;
465
  file<<"beta : "<<beta<<endl;
466
  file<<"gamma :"<<gamma<<endl;
467
  //file<<"alphabis : "<<alfabis<<endl;
468
  //file<<"betabis : "<<betabis<<endl;
469
  file<<"erosion : "<<erosion<<endl;
470
  file<<"marge : "<<marge<<endl;
471
  file<<"epsilon : "<<epsilon <<endl;
472
  file<<"mu : "<<mu <<endl;
473
  file<<"dt : "<<dt <<endl;
474
  file<<"timestep_max : "<<timestep_max <<endl;
475

  
476
  //-----------------------------------------Image Pre-processing
477

  
478
  //smooth image
479
  file<<"smooth : "<<smooth<<endl;
480
  if (smooth>0)
481
  {
482
  img.blur(smooth);
483
  }
484

  
485
  //-------------------------------------Initialization with erosion
486
  //compute fixed terms
487
  CImg<float> g;
488
  if(lsm_type.compare("g")==0)
489
    {
490
  g=edge_indicator1(img, gamma);
491
    }
492
  else if (lsm_type.compare("h")==0)
493
   {
494
  g=edge_indicator2s(img, gamma);
495
   }
496
  else if (lsm_type.compare("i")==0)
497
   {
498
  g=edge_indicator3(img, gamma);
499
   }
500
  else
501
  cout<<"Wrong lsm type given :'"<<lsm_type<<"'('g' for gradient-based, 'h' for Hessien-based) "<<endl;
502
 
503
  CImgList<float> gg=gradient(g);
504
  CImg<float> h=g;
505
  img.assign();
506
  
507
  //initialize psi for every cell
508
  int maxcells=wat.max()+1; //indice maximum  
509
  vector<int> list=index(wat,maxcells);
510
  int nbcells=list.size();
511
  cout<<"number of cells : "<<nbcells<<endl;
512
  file<<"number of cells : "<<nbcells<<endl;
513
  vector<CImg<float> > psi_list(nbcells);
514
  vector<vector<int> > min_list(nbcells,vector<int>(3,0));
515
  vector<vector<int> > max_list(nbcells,vector<int>(3,0));
516

  
517
#pragma omp parallel shared(wat,marge,erosion,c0,psi_list,min_list,list)
518
  {
519
  int xmin=0;
520
  int ymin=0;
521
  int zmin=0;
522
#pragma omp for schedule(dynamic)
523
  for(int i=0;i<nbcells;i++) 
524
    {
525
      int ind=list[i];
526
      psi_list[i]=box_cell(wat,marge,erosion,c0,ind,xmin,ymin,zmin);
527
      min_list[i][0]=xmin;
528
      min_list[i][1]=ymin;
529
      min_list[i][2]=zmin;
530
      cout <<"cell "<<ind<<" initialised."<<endl;
531
    }
532
  }
533
  wat.assign();
534

  
535
  //reconstruct image of eroded cells
536
  CImg<unsigned short> wat_eroded=reconstruct(background,psi_list,min_list,nbcells,list);
537
  cout <<"saving file "<<wat_eroded_name<<"..."<<endl;
538
  wat_eroded.save_inr(wat_eroded_name.c_str(),tailleVoxel);
539
  string zip="gzip -f "+wat_eroded_name;
540
  if(system(zip.c_str()));
541
  cout <<"Eroded watershed segmentation saved in file:"<<wat_eroded_name<<endl;
542

  
543
  //Segmented inital = background segmentation
544
  CImg<unsigned char> segmented=background;
545

  
546
  double end1=omp_get_wtime();
547
  double time1=double(end1-begin);
548
  cout<<"Evolving cells..... "<<endl;
549
  
550
  //---------------------------------------------------------Edge detection
551
  //evolve each cell one by one, attract to maximal gradient
552
#pragma omp parallel shared(psi_list,min_list,g,gg,h,lam,mu,alf,beta,epsilon,dt,list)
553
  {
554
#pragma omp for schedule(dynamic)
555
  for(int i=0;i<nbcells;i++) 
556
    {
557
      psi_list[i]=lsm_segment2(psi_list[i],g,gg,h,lam,mu,alf,beta,epsilon,dt,min_list[i]);
558
      cout <<"cell "<<list[i]<<" evolved."<<endl;
559
    }
560
  }
561

  
562
  //reconstruct image of edge detection, overlap=not segmented
563
  CImg<unsigned char>free=background;
564
  CImg<unsigned short> edge=reconstruct_overlap(background,psi_list,min_list,nbcells,free,list);
565
  edge.save_inr(edge_detection_name.c_str(),tailleVoxel);
566
  zip="gzip -f "+edge_detection_name;
567
  if(system(zip.c_str()));
568

  
569
// time measurements
570
  double end2=omp_get_wtime();
571
  double time2=double(end2-begin);
572
  
573
  double end=omp_get_wtime();
574
  double time=double(end-begin);
575
  cout<<"total time : "<<time<<"s"<<" (~"<<time/60<<" mn  ~"<<time/60/60<<" h)"<<endl;
576
  cout<<"-initialization with erosion : "<<time1<<"s"<<endl;
577
  cout<<"-edge detection : "<<time2<<"s"<<endl;
578
  file<<"total time : "<<time<<"s"<<" (~"<<time/60<<" mn  ~"<<time/60/60<<" h)"<<endl;
579
  file<<"-initialization with erosion : "<<time1<<"s"<<endl;
580
  file<<"-edge detection : "<<time2<<"s"<<endl;
581
  file.close();
582

  
583
  return 0;
584
}
src/CImg.h (revision 1)
1
/*
2
 #
3
 #  File            : CImg.h
4
 #                    ( C++ header file )
5
 #
6
 #  Description     : The C++ Template Image Processing Toolkit.
7
 #                    This file is the main component of the CImg Library project.
8
 #                    ( http://cimg.sourceforge.net )
9
 #
10
 #  Project manager : David Tschumperle.
11
 #                    ( http://tschumperle.users.greyc.fr/ )
12
 #
13
 #                    A complete list of contributors is available in file 'README.txt'
14
 #                    distributed within the CImg package.
15
 #
16
 #  Licenses        : This file is 'dual-licensed', you have to choose one
17
 #                    of the two licenses below to apply.
18
 #
19
 #                    CeCILL-C
20
 #                    The CeCILL-C license is close to the GNU LGPL.
21
 #                    ( http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.html )
22
 #
23
 #                or  CeCILL v2.0
24
 #                    The CeCILL license is compatible with the GNU GPL.
25
 #                    ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html )
26
 #
27
 #  This software is governed either by the CeCILL or the CeCILL-C license
28
 #  under French law and abiding by the rules of distribution of free software.
29
 #  You can  use, modify and or redistribute the software under the terms of
30
 #  the CeCILL or CeCILL-C licenses as circulated by CEA, CNRS and INRIA
31
 #  at the following URL: "http://www.cecill.info".
32
 #
33
 #  As a counterpart to the access to the source code and  rights to copy,
34
 #  modify and redistribute granted by the license, users are provided only
35
 #  with a limited warranty  and the software's author,  the holder of the
36
 #  economic rights,  and the successive licensors  have only  limited
37
 #  liability.
38
 #
39
 #  In this respect, the user's attention is drawn to the risks associated
40
 #  with loading,  using,  modifying and/or developing or reproducing the
41
 #  software by the user in light of its specific status of free software,
42
 #  that may mean  that it is complicated to manipulate,  and  that  also
43
 #  therefore means  that it is reserved for developers  and  experienced
44
 #  professionals having in-depth computer knowledge. Users are therefore
45
 #  encouraged to load and test the software's suitability as regards their
46
 #  requirements in conditions enabling the security of their systems and/or
47
 #  data to be ensured and,  more generally, to use and operate it in the
48
 #  same conditions as regards security.
49
 #
50
 #  The fact that you are presently reading this means that you have had
51
 #  knowledge of the CeCILL and CeCILL-C licenses and that you accept its terms.
52
 #
53
*/
54

  
55
// Set version number of the library.
56
#ifndef cimg_version
57
#define cimg_version 160
58

  
59
/*-----------------------------------------------------------
60
 #
61
 # Test and possibly auto-set CImg configuration variables
62
 # and include required headers.
63
 #
64
 # If you find that the default configuration variables are
65
 # not adapted to your system, you can override their values
66
 # before including the header file "CImg.h"
67
 # (use the #define directive).
68
 #
69
 ------------------------------------------------------------*/
70

  
71
// Include standard C++ headers.
72
// This is the minimal set of required headers to make CImg-based codes compile.
73
#include <cstdio>
74
#include <cstdlib>
75
#include <cstdarg>
76
#include <cstring>
77
#include <cmath>
78
#include <ctime>
79
#include <exception>
80

  
81
// Detect/configure OS variables.
82
//
83
// Define 'cimg_OS' to: '0' for an unknown OS (will try to minize library dependencies).
84
//                      '1' for a Unix-like OS (Linux, Solaris, BSD, MacOSX, Irix, ...).
85
//                      '2' for Microsoft Windows.
86
//                      (auto-detection is performed if 'cimg_OS' is not set by the user).
87
#ifndef cimg_OS
88
#if defined(unix)        || defined(__unix)      || defined(__unix__) \
89
 || defined(linux)       || defined(__linux)     || defined(__linux__) \
90
 || defined(sun)         || defined(__sun) \
91
 || defined(BSD)         || defined(__OpenBSD__) || defined(__NetBSD__) \
92
 || defined(__FreeBSD__) || defined (__DragonFly__) \
93
 || defined(sgi)         || defined(__sgi) \
94
 || defined(__MACOSX__)  || defined(__APPLE__) \
95
 || defined(__CYGWIN__)
96
#define cimg_OS 1
97
#elif defined(_MSC_VER) || defined(WIN32)  || defined(_WIN32) || defined(__WIN32__) \
98
   || defined(WIN64)    || defined(_WIN64) || defined(__WIN64__)
99
#define cimg_OS 2
100
#else
101
#define cimg_OS 0
102
#endif
103
#elif !(cimg_OS==0 || cimg_OS==1 || cimg_OS==2)
104
#error CImg Library: Invalid configuration variable 'cimg_OS'.
105
#error (correct values are '0 = unknown OS', '1 = Unix-like OS', '2 = Microsoft Windows').
106
#endif
107

  
108
// Disable silly warnings on some Microsoft VC++ compilers.
109
#ifdef _MSC_VER
110
#pragma warning(push)
111
#pragma warning(disable:4311)
112
#pragma warning(disable:4312)
113
#pragma warning(disable:4800)
114
#pragma warning(disable:4804)
115
#pragma warning(disable:4996)
116
#define _CRT_SECURE_NO_DEPRECATE 1
117
#define _CRT_NONSTDC_NO_DEPRECATE 1
118
#endif
119

  
120
// Include OS-specific headers.
121
#if cimg_OS==1
122
#include <sys/types.h>
123
#include <sys/time.h>
124
#include <sys/stat.h>
125
#include <unistd.h>
126
#elif cimg_OS==2
127
#ifndef NOMINMAX
128
#define NOMINMAX
129
#endif
130
#include <windows.h>
131
#ifndef _WIN32_IE
132
#define _WIN32_IE 0x0400
133
#endif
134
#include <shlobj.h>
135
#include <process.h>
136
#include <io.h>
137
#define cimg_snprintf _snprintf
138
#define cimg_vsnprintf _vsnprintf
139
#endif
140
#ifndef cimg_snprintf
141
#include <stdio.h>
142
#define cimg_snprintf snprintf
143
#define cimg_vsnprintf vsnprintf
144
#endif
145

  
146
// Look for C++11 features
147
#if !defined(cimg_use_cpp11) && __cplusplus>201100
148
#define cimg_use_cpp11
149
#endif
150
#ifdef cimg_use_cpp11
151
#include <initializer_list>
152
#include <utility>
153
#endif
154

  
155
// Configure filename separator.
156
//
157
// Filename separator is set by default to '/', except for Windows where it is '\'.
158
#ifndef cimg_file_separator
159
#if cimg_OS==2
160
#define cimg_file_separator '\\'
161
#else
162
#define cimg_file_separator '/'
163
#endif
164
#endif
165

  
166
// Configure verbosity of output messages.
167
//
168
// Define 'cimg_verbosity' to: '0' to hide library messages (quiet mode).
169
//                             '1' to output library messages on the console.
170
//                             '2' to output library messages on a basic dialog window (default behavior).
171
//                             '3' to do as '1' + add extra warnings (may slow down the code!).
172
//                             '4' to do as '2' + add extra warnings (may slow down the code!).
173
//
174
// Define 'cimg_strict_warnings' to replace warning messages by exception throwns.
175
//
176
// Define 'cimg_use_vt100' to allow output of color messages on VT100-compatible terminals.
177
#ifndef cimg_verbosity
178
#define cimg_verbosity 2
179
#elif !(cimg_verbosity==0 || cimg_verbosity==1 || cimg_verbosity==2 || cimg_verbosity==3 || cimg_verbosity==4)
180
#error CImg Library: Configuration variable 'cimg_verbosity' is badly defined.
181
#error (should be { 0=quiet | 1=console | 2=dialog | 3=console+warnings | 4=dialog+warnings }).
182
#endif
183

  
184
// Configure display framework.
185
//
186
// Define 'cimg_display' to: '0' to disable display capabilities.
187
//                           '1' to use the X-Window framework (X11).
188
//                           '2' to use the Microsoft GDI32 framework.
189
#ifndef cimg_display
190
#if cimg_OS==0
191
#define cimg_display 0
192
#elif cimg_OS==1
193
#if defined(__MACOSX__) || defined(__APPLE__)
194
#define cimg_display 1
195
#else
196
#define cimg_display 1
197
#endif
198
#elif cimg_OS==2
199
#define cimg_display 2
200
#endif
201
#elif !(cimg_display==0 || cimg_display==1 || cimg_display==2)
202
#error CImg Library: Configuration variable 'cimg_display' is badly defined.
203
#error (should be { 0=none | 1=X-Window (X11) | 2=Microsoft GDI32 }).
204
#endif
205

  
206
// Include display-specific headers.
207
#if cimg_display==1
208
#include <X11/Xlib.h>
209
#include <X11/Xutil.h>
210
#include <X11/keysym.h>
211
#include <pthread.h>
212
#ifdef cimg_use_xshm
213
#include <sys/ipc.h>
214
#include <sys/shm.h>
215
#include <X11/extensions/XShm.h>
216
#endif
217
#ifdef cimg_use_xrandr
218
#include <X11/extensions/Xrandr.h>
219
#endif
220
#endif
221
#ifndef cimg_appname
222
#define cimg_appname "CImg"
223
#endif
224

  
225
// Configure OpenMP support.
226
// (http://www.openmp.org)
227
//
228
// Define 'cimg_use_openmp' to enable OpenMP support.
229
//
230
// OpenMP directives may be used in a (very) few CImg functions to get
231
// advantages of multi-core CPUs.
232
#ifdef cimg_use_openmp
233
#include <omp.h>
234
#endif
235

  
236
// Configure OpenCV support.
237
// (http://opencv.willowgarage.com/wiki/)
238
//
239
// Define 'cimg_use_opencv' to enable OpenCV support.
240
//
241
// OpenCV library may be used to access images from cameras
242
// (see method 'CImg<T>::load_camera()').
243
#ifdef cimg_use_opencv
244
#ifdef True
245
#undef True
246
#define _cimg_redefine_True
247
#endif
248
#ifdef False
249
#undef False
250
#define _cimg_redefine_False
251
#endif
252
#include <cstddef>
253
#include "cv.h"
254
#include "highgui.h"
255
#endif
256

  
257
// Configure LibPNG support.
258
// (http://www.libpng.org)
259
//
260
// Define 'cimg_use_png' to enable LibPNG support.
261
//
262
// PNG library may be used to get a native support of '.png' files.
263
// (see methods 'CImg<T>::{load,save}_png()'.
264
#ifdef cimg_use_png
265
extern "C" {
266
#include "png.h"
267
}
268
#endif
269

  
270
// Configure LibJPEG support.
271
// (http://en.wikipedia.org/wiki/Libjpeg)
272
//
273
// Define 'cimg_use_jpeg' to enable LibJPEG support.
274
//
275
// JPEG library may be used to get a native support of '.jpg' files.
276
// (see methods 'CImg<T>::{load,save}_jpeg()').
277
#ifdef cimg_use_jpeg
278
extern "C" {
279
#include "jpeglib.h"
280
#include "setjmp.h"
281
}
282
#endif
283

  
284
// Configure LibTIFF support.
285
// (http://www.libtiff.org)
286
//
287
// Define 'cimg_use_tiff' to enable LibTIFF support.
288
//
289
// TIFF library may be used to get a native support of '.tif' files.
290
// (see methods 'CImg[List]<T>::{load,save}_tiff()').
291
#ifdef cimg_use_tiff
292
extern "C" {
293
#define uint64 uint64_hack_
294
#define int64 int64_hack_
295
#include "tiffio.h"
296
#undef uint64
297
#undef int64
298
}
299
#endif
300

  
301
// Configure LibMINC2 support.
302
// (http://en.wikibooks.org/wiki/MINC/Reference/MINC2.0_File_Format_Reference)
303
//
304
// Define 'cimg_use_minc2' to enable LibMINC2 support.
305
//
306
// MINC2 library may be used to get a native support of '.mnc' files.
307
// (see methods 'CImg<T>::{load,save}_minc2()').
308
#ifdef cimg_use_minc2
309
#include "minc_io_simple_volume.h"
310
#include "minc_1_simple.h"
311
#include "minc_1_simple_rw.h"
312
#endif
313

  
314
// Configure FFMPEG support.
315
// (http://www.ffmpeg.org)
316
//
317
// Define 'cimg_use_ffmpeg' to enable FFMPEG lib support.
318
//
319
// Avcodec and Avformat libraries from FFMPEG may be used
320
// to get a native support of various video file formats.
321
// (see methods 'CImg[List]<T>::load_ffmpeg()').
322
#ifdef cimg_use_ffmpeg
323
#if (defined(_STDINT_H) || defined(_STDINT_H_)) && !defined(UINT64_C)
324
#warning "__STDC_CONSTANT_MACROS has to be defined before including <stdint.h>, this file will probably not compile."
325
#endif
326
#ifndef __STDC_CONSTANT_MACROS
327
#define __STDC_CONSTANT_MACROS // ...or stdint.h wont' define UINT64_C, needed by libavutil
328
#endif
329
extern "C" {
330
#include <libavformat/avformat.h>
331
#include <libavcodec/avcodec.h>
332
#include <libswscale/swscale.h>
333
}
334
#endif
335

  
336
// Configure Zlib support.
337
// (http://www.zlib.net)
338
//
339
// Define 'cimg_use_zlib' to enable Zlib support.
340
//
341
// Zlib library may be used to allow compressed data in '.cimgz' files
342
// (see methods 'CImg[List]<T>::{load,save}_cimg()').
343
#ifdef cimg_use_zlib
344
extern "C" {
345
#include "zlib.h"
346
}
347
#endif
348

  
349
// Configure Magick++ support.
350
// (http://www.imagemagick.org/Magick++)
351
//
352
// Define 'cimg_use_magick' to enable Magick++ support.
353
//
354
// Magick++ library may be used to get a native support of various image file formats.
355
// (see methods 'CImg<T>::{load,save}()').
356
#ifdef cimg_use_magick
357
#include "Magick++.h"
358
#endif
359

  
360
// Configure FFTW3 support.
361
// (http://www.fftw.org)
362
//
363
// Define 'cimg_use_fftw3' to enable libFFTW3 support.
364
//
365
// FFTW3 library may be used to efficiently compute the Fast Fourier Transform
366
// of image data, without restriction on the image size.
367
// (see method 'CImg[List]<T>::FFT()').
368
#ifdef cimg_use_fftw3
369
extern "C" {
370
#include "fftw3.h"
371
}
372
#endif
373

  
374
// Configure LibBoard support.
375
// (http://libboard.sourceforge.net/)
376
//
377
// Define 'cimg_use_board' to enable Board support.
378
//
379
// Board library may be used to draw 3d objects in vector-graphics canvas
380
// that can be saved as '.ps' or '.svg' files afterwards.
381
// (see method 'CImg<T>::draw_object3d()').
382
#ifdef cimg_use_board
383
#ifdef None
384
#undef None
385
#define _cimg_redefine_None
386
#endif
387
#include "Board.h"
388
#endif
389

  
390
// Configure OpenEXR support.
391
// (http://www.openexr.com/)
392
//
393
// Define 'cimg_use_openexr' to enable OpenEXR support.
394
//
395
// OpenEXR library may be used to get a native support of '.exr' files.
396
// (see methods 'CImg<T>::{load,save}_exr()').
397
#ifdef cimg_use_openexr
398
#include "ImfRgbaFile.h"
399
#include "ImfInputFile.h"
400
#include "ImfChannelList.h"
401
#include "ImfMatrixAttribute.h"
402
#include "ImfArray.h"
403
#endif
404

  
405
// Lapack configuration.
406
// (http://www.netlib.org/lapack)
407
//
408
// Define 'cimg_use_lapack' to enable LAPACK support.
409
//
410
// Lapack library may be used in several CImg methods to speed up
411
// matrix computations (eigenvalues, inverse, ...).
412
#ifdef cimg_use_lapack
413
extern "C" {
414
  extern void sgetrf_(int*, int*, float*, int*, int*, int*);
415
  extern void sgetri_(int*, float*, int*, int*, float*, int*, int*);
416
  extern void sgetrs_(char*, int*, int*, float*, int*, int*, float*, int*, int*);
417
  extern void sgesvd_(char*, char*, int*, int*, float*, int*, float*, float*, int*, float*, int*, float*, int*, int*);
418
  extern void ssyev_(char*, char*, int*, float*, int*, float*, float*, int*, int*);
419
  extern void dgetrf_(int*, int*, double*, int*, int*, int*);
420
  extern void dgetri_(int*, double*, int*, int*, double*, int*, int*);
421
  extern void dgetrs_(char*, int*, int*, double*, int*, int*, double*, int*, int*);
422
  extern void dgesvd_(char*, char*, int*, int*, double*, int*, double*, double*,
423
                      int*, double*, int*, double*, int*, int*);
424
  extern void dsyev_(char*, char*, int*, double*, int*, double*, double*, int*, int*);
425
  extern void dgels_(char*, int*,int*,int*,double*,int*,double*,int*,double*,int*,int*);
426
  extern void sgels_(char*, int*,int*,int*,float*,int*,float*,int*,float*,int*,int*);
427
}
428
#endif
429

  
430
// Check if min/max/PI macros are defined.
431
//
432
// CImg does not compile if macros 'min', 'max' or 'PI' are defined,
433
// because it redefines functions min(), max() and const variable PI in the cimg:: namespace.
434
// so it '#undef' these macros if necessary, and restore them to reasonable
435
// values at the end of this file.
436
#ifdef min
437
#undef min
438
#define _cimg_redefine_min
439
#endif
440
#ifdef max
441
#undef max
442
#define _cimg_redefine_max
443
#endif
444
#ifdef PI
445
#undef PI
446
#define _cimg_redefine_PI
447
#endif
448

  
449
// Define 'cimg_library' namespace suffix.
450
//
451
// You may want to add a suffix to the 'cimg_library' namespace, for instance if you need to work
452
// with several versions of the library at the same time.
453
#ifdef cimg_namespace_suffix
454
#define __cimg_library_suffixed(s) cimg_library_##s
455
#define _cimg_library_suffixed(s) __cimg_library_suffixed(s)
456
#define cimg_library_suffixed _cimg_library_suffixed(cimg_namespace_suffix)
457
#else
458
#define cimg_library_suffixed cimg_library
459
#endif
460

  
461
/*------------------------------------------------------------------------------
462
  #
463
  # Define user-friendly macros.
464
  #
465
  # These CImg macros are prefixed by 'cimg_' and can be used safely in your own
466
  # code. They are useful to parse command line options, or to write image loops.
467
  #
468
  ------------------------------------------------------------------------------*/
469

  
470
// Macros to define program usage, and retrieve command line arguments.
471
#define cimg_usage(usage) cimg_library_suffixed::cimg::option((char*)0,argc,argv,(char*)0,usage,false)
472
#define cimg_help(str) cimg_library_suffixed::cimg::option((char*)0,argc,argv,str,(char*)0)
473
#define cimg_option(name,defaut,usage) cimg_library_suffixed::cimg::option(name,argc,argv,defaut,usage)
474
#define cimg_argument(pos) \
475
  cimg_library_suffixed::cimg::argument(pos,argc,argv)
476
#define cimg_argument1(pos,s0) \
477
  cimg_library_suffixed::cimg::argument(pos,argc,argv,1,s0)
478
#define cimg_argument2(pos,s0,s1) \
479
  cimg_library_suffixed::cimg::argument(pos,argc,argv,2,s0,s1)
480
#define cimg_argument3(pos,s0,s1,s2) \
481
  cimg_library_suffixed::cimg::argument(pos,argc,argv,3,s0,s1,s2)
482
#define cimg_argument4(pos,s0,s1,s2,s3) \
483
  cimg_library_suffixed::cimg::argument(pos,argc,argv,4,s0,s1,s2,s3)
484
#define cimg_argument5(pos,s0,s1,s2,s3,s4) \
485
  cimg_library_suffixed::cimg::argument(pos,argc,argv,5,s0,s1,s2,s3,s4)
486
#define cimg_argument6(pos,s0,s1,s2,s3,s4,s5) \
487
  cimg_library_suffixed::cimg::argument(pos,argc,argv,6,s0,s1,s2,s3,s4,s5)
488
#define cimg_argument7(pos,s0,s1,s2,s3,s4,s5,s6) \
489
  cimg_library_suffixed::cimg::argument(pos,argc,argv,7,s0,s1,s2,s3,s4,s5,s6)
490
#define cimg_argument8(pos,s0,s1,s2,s3,s4,s5,s6,s7) \
491
  cimg_library_suffixed::cimg::argument(pos,argc,argv,8,s0,s1,s2,s3,s4,s5,s6,s7)
492
#define cimg_argument9(pos,s0,s1,s2,s3,s4,s5,s6,s7,s8) \
493
  cimg_library_suffixed::cimg::argument(pos,argc,argv,9,s0,s1,s2,s3,s4,s5,s6,s7,s8)
494

  
495
// Macros to define and manipulate local neighborhoods.
496
#define CImg_2x2(I,T) T I[4]; \
497
                      T& I##cc = I[0]; T& I##nc = I[1]; \
498
                      T& I##cn = I[2]; T& I##nn = I[3]; \
499
                      I##cc = I##nc = \
500
                      I##cn = I##nn = 0
501

  
502
#define CImg_3x3(I,T) T I[9]; \
503
                      T& I##pp = I[0]; T& I##cp = I[1]; T& I##np = I[2]; \
504
                      T& I##pc = I[3]; T& I##cc = I[4]; T& I##nc = I[5]; \
505
                      T& I##pn = I[6]; T& I##cn = I[7]; T& I##nn = I[8]; \
506
                      I##pp = I##cp = I##np = \
507
                      I##pc = I##cc = I##nc = \
508
                      I##pn = I##cn = I##nn = 0
509

  
510
#define CImg_4x4(I,T) T I[16]; \
511
                      T& I##pp = I[0]; T& I##cp = I[1]; T& I##np = I[2]; T& I##ap = I[3]; \
512
                      T& I##pc = I[4]; T& I##cc = I[5]; T& I##nc = I[6]; T& I##ac = I[7]; \
513
                      T& I##pn = I[8]; T& I##cn = I[9]; T& I##nn = I[10]; T& I##an = I[11]; \
514
                      T& I##pa = I[12]; T& I##ca = I[13]; T& I##na = I[14]; T& I##aa = I[15]; \
515
                      I##pp = I##cp = I##np = I##ap = \
516
                      I##pc = I##cc = I##nc = I##ac = \
517
                      I##pn = I##cn = I##nn = I##an = \
518
                      I##pa = I##ca = I##na = I##aa = 0
519

  
520
#define CImg_5x5(I,T) T I[25]; \
521
                      T& I##bb = I[0]; T& I##pb = I[1]; T& I##cb = I[2]; T& I##nb = I[3]; T& I##ab = I[4]; \
522
                      T& I##bp = I[5]; T& I##pp = I[6]; T& I##cp = I[7]; T& I##np = I[8]; T& I##ap = I[9]; \
523
                      T& I##bc = I[10]; T& I##pc = I[11]; T& I##cc = I[12]; T& I##nc = I[13]; T& I##ac = I[14]; \
524
                      T& I##bn = I[15]; T& I##pn = I[16]; T& I##cn = I[17]; T& I##nn = I[18]; T& I##an = I[19]; \
525
                      T& I##ba = I[20]; T& I##pa = I[21]; T& I##ca = I[22]; T& I##na = I[23]; T& I##aa = I[24]; \
526
                      I##bb = I##pb = I##cb = I##nb = I##ab = \
527
                      I##bp = I##pp = I##cp = I##np = I##ap = \
528
                      I##bc = I##pc = I##cc = I##nc = I##ac = \
529
                      I##bn = I##pn = I##cn = I##nn = I##an = \
530
                      I##ba = I##pa = I##ca = I##na = I##aa = 0
531

  
532
#define CImg_2x2x2(I,T) T I[8]; \
533
                      T& I##ccc = I[0]; T& I##ncc = I[1]; \
534
                      T& I##cnc = I[2]; T& I##nnc = I[3]; \
535
                      T& I##ccn = I[4]; T& I##ncn = I[5]; \
... Ce différentiel a été tronqué car il excède la taille maximale pouvant être affichée.

Formats disponibles : Unified diff