├── PWcut ├── powerwatershed.h ├── mclistechainee.c ├── CMakeLists.txt ├── union_find.h ├── mclistechainee.h ├── union_find.cpp ├── random_walker.h ├── powerwatexample.c ├── powerwatershed.c ├── powerwatershed.cpp ├── MSF_RW.cpp ├── gageodesic.h └── cs.h ├── pink ├── mcrbt.c ├── jcimage.c ├── jcimage.h ├── lattrib.c ├── lattrib.h ├── llpeGA.c ├── lppm2GA.c ├── mcimage.c ├── jccodimage.c ├── jccomptree.h ├── jcgraphes.c ├── jcgraphes.h ├── llpemeyer.c ├── lsaliency.c ├── lwshedtopo.c ├── mccodimage.c ├── lga2khalimsky.c ├── lhierarchie.c ├── mckhalimsky2d.c ├── mcunionfind.c ├── jclabelextrema.c ├── jclabelextrema.h ├── mclistechainee.c ├── overlap.h ├── MSF_utils.h ├── CMakeLists.txt ├── lga2khalimsky.h ├── lwshedtopo.h ├── lattribheight.h ├── lsaliency.h ├── sjcomptree.h ├── mcunionfind.h ├── llabelextrema.h ├── mcsort.h ├── mclifo.h ├── mcindic.h ├── mcfifo.h ├── jclderiche.h ├── lhierarchie.h ├── mclistechainee.h ├── llpeGA.h ├── lderiche.h ├── mincover.c ├── lppm2GA.h ├── mcutil.h ├── mtrand64.h ├── mcfahsalembier.h ├── mcfah.h ├── mcrbt.h ├── mcindic.c ├── overlap.c ├── jccodimage.h ├── mcweightgraph.h ├── llpemeyer.h ├── MSF_utils.c ├── mccomptree.h ├── mcimage.h ├── mckhalimsky2d.h ├── decisionSegmentation.c ├── mclifo.c ├── mcfifo.c ├── mtrand64.c ├── prim.c ├── kruskal.c └── mccodimage.h ├── graphcuts ├── MTree_utils.h ├── CMakeLists.txt ├── maxflow.h └── README.TXT ├── test-malis.lua ├── CMakeLists.txt ├── imgraph-1.0-0.rockspec ├── init.cpp ├── set.h ├── README.md ├── mergetree.h └── MalisCriterion.lua /PWcut/powerwatershed.h: -------------------------------------------------------------------------------- 1 | 2 | extern list * Powerwatershed(MergeTree * MT); 3 | -------------------------------------------------------------------------------- /pink/mcrbt.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Atcold/lua---imgraph/master/pink/mcrbt.c -------------------------------------------------------------------------------- /pink/jcimage.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Atcold/lua---imgraph/master/pink/jcimage.c -------------------------------------------------------------------------------- /pink/jcimage.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Atcold/lua---imgraph/master/pink/jcimage.h -------------------------------------------------------------------------------- /pink/lattrib.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Atcold/lua---imgraph/master/pink/lattrib.c -------------------------------------------------------------------------------- /pink/lattrib.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Atcold/lua---imgraph/master/pink/lattrib.h -------------------------------------------------------------------------------- /pink/llpeGA.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Atcold/lua---imgraph/master/pink/llpeGA.c -------------------------------------------------------------------------------- /pink/lppm2GA.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Atcold/lua---imgraph/master/pink/lppm2GA.c -------------------------------------------------------------------------------- /pink/mcimage.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Atcold/lua---imgraph/master/pink/mcimage.c -------------------------------------------------------------------------------- /pink/jccodimage.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Atcold/lua---imgraph/master/pink/jccodimage.c -------------------------------------------------------------------------------- /pink/jccomptree.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Atcold/lua---imgraph/master/pink/jccomptree.h -------------------------------------------------------------------------------- /pink/jcgraphes.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Atcold/lua---imgraph/master/pink/jcgraphes.c -------------------------------------------------------------------------------- /pink/jcgraphes.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Atcold/lua---imgraph/master/pink/jcgraphes.h -------------------------------------------------------------------------------- /pink/llpemeyer.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Atcold/lua---imgraph/master/pink/llpemeyer.c -------------------------------------------------------------------------------- /pink/lsaliency.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Atcold/lua---imgraph/master/pink/lsaliency.c -------------------------------------------------------------------------------- /pink/lwshedtopo.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Atcold/lua---imgraph/master/pink/lwshedtopo.c -------------------------------------------------------------------------------- /pink/mccodimage.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Atcold/lua---imgraph/master/pink/mccodimage.c -------------------------------------------------------------------------------- /pink/lga2khalimsky.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Atcold/lua---imgraph/master/pink/lga2khalimsky.c -------------------------------------------------------------------------------- /pink/lhierarchie.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Atcold/lua---imgraph/master/pink/lhierarchie.c -------------------------------------------------------------------------------- /pink/mckhalimsky2d.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Atcold/lua---imgraph/master/pink/mckhalimsky2d.c -------------------------------------------------------------------------------- /pink/mcunionfind.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Atcold/lua---imgraph/master/pink/mcunionfind.c -------------------------------------------------------------------------------- /PWcut/mclistechainee.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Atcold/lua---imgraph/master/PWcut/mclistechainee.c -------------------------------------------------------------------------------- /pink/jclabelextrema.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Atcold/lua---imgraph/master/pink/jclabelextrema.c -------------------------------------------------------------------------------- /pink/jclabelextrema.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Atcold/lua---imgraph/master/pink/jclabelextrema.h -------------------------------------------------------------------------------- /pink/mclistechainee.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Atcold/lua---imgraph/master/pink/mclistechainee.c -------------------------------------------------------------------------------- /graphcuts/MTree_utils.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Atcold/lua---imgraph/master/graphcuts/MTree_utils.h -------------------------------------------------------------------------------- /graphcuts/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | include_directories (${PROJECT_SOURCE_DIR}/graphcuts) 3 | 4 | add_library(graphcuts 5 | maxflow.cpp) 6 | 7 | set (CMAKE_CXX_FLAGS "-fpic -g -DUNIXIO") 8 | target_link_libraries(graphcuts) 9 | -------------------------------------------------------------------------------- /pink/overlap.h: -------------------------------------------------------------------------------- 1 | float * Overlap(struct xvimage * segment, struct xvimage *mask, int nb_classes); 2 | float * Overlap1(struct xvimage *segment, struct xvimage *mask, int nb_classes); 3 | int * DecisionSegmentation(float * Segments, int rs, int cs, int nb_segments, float *f, int nb_classes, float t1, float t2, float t3); 4 | -------------------------------------------------------------------------------- /PWcut/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | include_directories (${PROJECT_SOURCE_DIR}/PWcut ${PROJECT_SOURCE_DIR}/pink ${PROJECT_SOURCE_DIR}/graphcuts) 3 | 4 | add_library(PWcut 5 | union_find.cpp 6 | csparse.c 7 | MSF_RW.cpp 8 | random_walker.cpp 9 | powerwatershed.cpp 10 | mclistechainee.c) 11 | 12 | set (CMAKE_C_FLAGS "-fpic -g -DUNIXIO") 13 | set (CMAKE_CXX_FLAGS "-fpic -g -DUNIXIO") 14 | target_link_libraries(PWcut) 15 | -------------------------------------------------------------------------------- /graphcuts/maxflow.h: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | #ifndef _MERGETREESTRUCT_ 5 | #define _MERGETREESTRUCT_ 6 | typedef struct { 7 | mtree *tree; 8 | RAG *rag; 9 | struct xvimage *labels; 10 | int32_t *altitudes; 11 | float *weights; 12 | int cs; 13 | int rs; 14 | } MergeTree; 15 | #endif 16 | 17 | #ifndef _LISTSTRUCT_ 18 | #define _LISTSTRUCT_ 19 | typedef struct list 20 | { 21 | int index; 22 | struct list *next; 23 | } list ; 24 | #endif 25 | 26 | extern list * Graph_Cuts(MergeTree * ); 27 | -------------------------------------------------------------------------------- /test-malis.lua: -------------------------------------------------------------------------------- 1 | 2 | require 'imgraph' 3 | 4 | m = nn.MalisCriterion('min','rand') 5 | 6 | i = torch.Tensor(8,8):fill(1) 7 | t = torch.Tensor(8,8):zero() 8 | 9 | i:narrow(1,5,4):fill(1.8) 10 | i[5][4] = 1.6 11 | 12 | print(i) 13 | 14 | ig = imgraph.graph(i) 15 | 16 | t:narrow(1,1,4):fill(1) 17 | t:narrow(1,5,4):fill(2) 18 | 19 | print(ig) 20 | print(t) 21 | 22 | loss = m:forward(ig,t) 23 | grad = m:backward(ig,t):clone() 24 | 25 | m:forward(ig,t) 26 | grad = grad + m:backward(ig,t):clone() 27 | 28 | print('rand index = ' .. loss) 29 | print(grad) 30 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | CMAKE_MINIMUM_REQUIRED(VERSION 2.6 FATAL_ERROR) 3 | CMAKE_POLICY(VERSION 2.6) 4 | IF(LUAROCKS_PREFIX) 5 | MESSAGE(STATUS "Installing Torch through Luarocks") 6 | STRING(REGEX REPLACE "(.*)lib/luarocks/rocks.*" "\\1" CMAKE_INSTALL_PREFIX "${LUAROCKS_PREFIX}") 7 | MESSAGE(STATUS "Prefix inferred from Luarocks: ${CMAKE_INSTALL_PREFIX}") 8 | ENDIF() 9 | FIND_PACKAGE(Torch REQUIRED) 10 | FIND_PACKAGE(Boost REQUIRED) 11 | 12 | add_subdirectory (pink) 13 | add_subdirectory (graphcuts) 14 | add_subdirectory (PWcut) 15 | 16 | include_directories (${PROJECT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/pink 17 | ${PROJECT_SOURCE_DIR}/graphcuts ${PROJECT_SOURCE_DIR}/PWcut ${Boost_INCLUDE_DIR}) 18 | 19 | SET(src init.cpp) 20 | SET(luasrc init.lua MalisCriterion.lua) 21 | 22 | ADD_TORCH_PACKAGE(imgraph "${src}" "${luasrc}" "Image Processing") 23 | SET (CMAKE_CXX_FLAGS "-fpic") 24 | TARGET_LINK_LIBRARIES(imgraph luaT TH graphcuts pink PWcut) 25 | -------------------------------------------------------------------------------- /imgraph-1.0-0.rockspec: -------------------------------------------------------------------------------- 1 | package = "imgraph" 2 | version = "1.0-0" 3 | 4 | source = { 5 | url = "git://github.com/clementfarabet/lua---imgraph", 6 | tag = "1.0-0" 7 | } 8 | 9 | description = { 10 | summary = "An image/graph library for Torch", 11 | detailed = [[ 12 | This package provides routines to construct graphs on images, 13 | segment them, build trees out of them, and convert them back 14 | to images. 15 | ]], 16 | homepage = "https://github.com/clementfarabet/lua---imgraph", 17 | license = "GPL" 18 | } 19 | 20 | dependencies = { 21 | "torch >= 7.0", 22 | "sys >= 1.0", 23 | "xlua >= 1.0", 24 | "image >= 1.0" 25 | } 26 | 27 | build = { 28 | type = "command", 29 | build_command = [[ 30 | cmake -E make_directory build; 31 | cd build; 32 | cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH="$(LUA_BINDIR)/.." -DCMAKE_INSTALL_PREFIX="$(PREFIX)"; 33 | $(MAKE) 34 | ]], 35 | install_command = "cd build && $(MAKE) install" 36 | } 37 | -------------------------------------------------------------------------------- /pink/MSF_utils.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _MERGETREESTRUCT_ 3 | #define _MERGETREESTRUCT_ 4 | typedef struct { 5 | mtree *tree; 6 | RAG *rag; 7 | struct xvimage *labels; 8 | int32_t *altitudes; 9 | float *weights; 10 | int cs; 11 | int rs; 12 | } MergeTree; 13 | #endif 14 | 15 | 16 | #ifndef _LISTSTRUCT_ 17 | #define _LISTSTRUCT_ 18 | typedef struct list 19 | { 20 | int index; 21 | struct list *next; 22 | } list ; 23 | #endif 24 | 25 | //#include 26 | 27 | int element_link( int x,int y, uint32_t *Rnk, uint32_t *Fth); 28 | int element_find(int x, uint32_t *Fth ); 29 | void TriRapideStochastique_dec (float * A, uint32_t *I, long p, long r); 30 | long PartitionStochastique_dec (float *A, uint32_t * I, long p, long r); 31 | int nb_neighbors(int x, JCctree *CT, int nb_leafs); 32 | int neighbor(int x, int k, JCctree *CT, int nb_leafs, int * SeededNodes); 33 | 34 | list * MSF_Kruskal(MergeTree * MT); 35 | list * MSF_Prim(MergeTree * MT); 36 | 37 | list * Min_Cover(MergeTree * MT); 38 | 39 | -------------------------------------------------------------------------------- /pink/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | include_directories (${PROJECT_SOURCE_DIR}/pink ${PROJECT_SOURCE_DIR}/graphcuts ) 3 | 4 | add_library(pink 5 | lattribheight.c 6 | llabelextrema.c 7 | lppm2GA.c 8 | lwshedtopo.c 9 | lderiche.c 10 | lhierarchie.c 11 | jccodimage.c 12 | jcimage.c 13 | jcgraphes.c 14 | jccomptree.c 15 | jclabelextrema.c 16 | llpeGA.c 17 | lga2khalimsky.c 18 | mcrbt.c 19 | mccodimage.c 20 | mccomptree.c 21 | mcfahsalembier.c 22 | mcimage.c 23 | mcindic.c 24 | mclifo.c 25 | mcfifo.c 26 | mcunionfind.c 27 | mtrand64.c 28 | kruskal.c 29 | prim.c 30 | mincover.c 31 | MSF_utils.c 32 | mcweightgraph.c 33 | sjcomptree.c 34 | mcsort.c 35 | overlap.c 36 | decisionSegmentation.c 37 | ) 38 | 39 | set (CMAKE_C_FLAGS "-fpic -g -DUNIXIO") 40 | target_link_libraries(pink) 41 | -------------------------------------------------------------------------------- /init.cpp: -------------------------------------------------------------------------------- 1 | extern "C" { 2 | #include "TH.h" 3 | #include "luaT.h" 4 | } 5 | 6 | #include "stdint.h" 7 | 8 | extern "C" { 9 | #include "mccodimage.h" 10 | #include "mcimage.h" 11 | #include "jcgraphes.h" 12 | #include "jcimage.h" 13 | #include "jccodimage.h" 14 | #include "jccomptree.h" 15 | #include "llabelextrema.h" 16 | #include "lwshedtopo.h" 17 | #include "lsaliency.h" 18 | #include "lhierarchie.h" 19 | #include "lattribheight.h" 20 | #include "MSF_utils.h" 21 | #include "llpeGA.h" 22 | #include "lga2khalimsky.h" 23 | #include "lppm2GA.h" 24 | #include "mcweightgraph.h" 25 | #include "sjcomptree.h" 26 | #include "overlap.h" 27 | } 28 | 29 | #include "powerwatershed.h" 30 | #include "set.h" 31 | #include "mergetree.h" 32 | #include "maxflow.h" 33 | 34 | #include 35 | #include 36 | #include 37 | 38 | #define torch_(NAME) TH_CONCAT_3(torch_, Real, NAME) 39 | #define torch_Tensor TH_CONCAT_STRING_3(torch., Real, Tensor) 40 | #define imgraph_(NAME) TH_CONCAT_3(imgraph_, Real, NAME) 41 | #define nn_(NAME) TH_CONCAT_3(nn_, Real, NAME) 42 | 43 | #include "generic/imgraph.c" 44 | #include "THGenerateFloatTypes.h" 45 | 46 | #include "generic/MalisCriterion.c" 47 | #include "THGenerateFloatTypes.h" 48 | 49 | extern "C" { 50 | DLL_EXPORT int luaopen_libimgraph(lua_State *L) 51 | { 52 | imgraph_FloatInit(L); 53 | imgraph_DoubleInit(L); 54 | 55 | nn_FloatMalisCriterion_init(L); 56 | nn_DoubleMalisCriterion_init(L); 57 | 58 | return 1; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /set.h: -------------------------------------------------------------------------------- 1 | #ifndef _SET_ 2 | #define _SET_ 3 | 4 | /* 5 | This file provides a very simple data structure to represent 6 | a disjoint set. This code is heavily inspired by Pedro 7 | Felzenszwalb's min-spanning tree code, released under a 8 | GNU GPL license (Copyright (C) 2006 Pedro). 9 | */ 10 | 11 | typedef struct { 12 | int pseudorank; 13 | int parent; 14 | int surface; 15 | int id; 16 | } Elt; 17 | 18 | typedef struct { 19 | Elt *elts; 20 | int nelts; 21 | } Set; 22 | 23 | Set * set_new(int nelts) { 24 | Set *set = (Set *)calloc(1, sizeof(Set)); 25 | set->elts = (Elt *)calloc(nelts, sizeof(Elt)); 26 | set->nelts = nelts; 27 | int i; 28 | for (i = 0; i < nelts; i++) { 29 | set->elts[i].pseudorank = 0; 30 | set->elts[i].surface = 1; 31 | set->elts[i].parent = i; 32 | set->elts[i].id = -1; 33 | } 34 | return set; 35 | } 36 | 37 | void set_free(Set *set) { 38 | free(set->elts); 39 | free(set); 40 | } 41 | 42 | int set_find(Set *set, int x) { 43 | int y = x; 44 | while (y != set->elts[y].parent) 45 | y = set->elts[y].parent; 46 | set->elts[x].parent = y; 47 | return y; 48 | } 49 | 50 | void set_join(Set *set, int x, int y) { 51 | if (set->elts[x].pseudorank > set->elts[y].pseudorank) { 52 | set->elts[y].parent = x; 53 | set->elts[x].surface += set->elts[y].surface; 54 | } else { 55 | set->elts[x].parent = y; 56 | set->elts[y].surface += set->elts[x].surface; 57 | if (set->elts[x].pseudorank == set->elts[y].pseudorank) 58 | set->elts[y].pseudorank++; 59 | } 60 | set->nelts--; 61 | } 62 | 63 | #endif 64 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # imgraph: a package to create/manipulate graphs on images 2 | 3 | This package provides standard functions to 4 | create and manipulate edge-weighted graphs 5 | of images: create a graph, segment it, 6 | compute its watershed, or its connected 7 | components... 8 | 9 | ## Install 10 | 11 | 1/ Torch7 is required: 12 | 13 | Dependencies, on Linux (Ubuntu > 9.04): 14 | 15 | ``` sh 16 | $ apt-get install gcc g++ git libreadline5-dev cmake wget libqt4-core libqt4-gui libqt4-dev libboost-all-dev 17 | ``` 18 | 19 | Dependencies, on Mac OS (Leopard, or more), using [Homebrew](http://mxcl.github.com/homebrew/): 20 | 21 | ``` sh 22 | $ brew install git readline cmake wget qt 23 | ``` 24 | 25 | Then on both platforms: 26 | 27 | ``` sh 28 | $ git clone https://github.com/andresy/torch 29 | $ cd torch 30 | $ mkdir build; cd build 31 | $ cmake .. 32 | $ make 33 | $ [sudo] make install 34 | ``` 35 | 36 | 2/ Once Torch7 is available, install this package: 37 | 38 | ``` sh 39 | $ [sudo] torch-rocks install imgraph 40 | ``` 41 | 42 | ## Use the library 43 | 44 | First run torch, and load imgraph: 45 | 46 | ``` sh 47 | $ torch 48 | ``` 49 | 50 | ``` lua 51 | > require 'imgraph' 52 | ``` 53 | 54 | Once loaded, tab-completion will help you navigate through the 55 | library: 56 | 57 | ``` lua 58 | > imgraph. + TAB 59 | imgraph.colorize( imgraph.connectcomponents( 60 | imgraph.graph( imgraph.histpooling( 61 | imgraph.segmentmst( imgraph.testme( 62 | imgraph.watershed( imgraph.gradient( 63 | ``` 64 | 65 | To get quickly started, run the testme() function: 66 | 67 | ``` lua 68 | > imgraph.testme() 69 | ``` 70 | 71 | which computes a few things on the famous image of Lena: 72 | 73 | ![results](http://data.neuflow.org/share/imgraph-testme.jpg) 74 | -------------------------------------------------------------------------------- /pink/lga2khalimsky.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright ESIEE (2009) 3 | 4 | m.couprie@esiee.fr 5 | 6 | This software is an image processing library whose purpose is to be 7 | used primarily for research and teaching. 8 | 9 | This software is governed by the CeCILL license under French law and 10 | abiding by the rules of distribution of free software. You can use, 11 | modify and/ or redistribute the software under the terms of the CeCILL 12 | license as circulated by CEA, CNRS and INRIA at the following URL 13 | "http://www.cecill.info". 14 | 15 | As a counterpart to the access to the source code and rights to copy, 16 | modify and redistribute granted by the license, users are provided only 17 | with a limited warranty and the software's author, the holder of the 18 | economic rights, and the successive licensors have only limited 19 | liability. 20 | 21 | In this respect, the user's attention is drawn to the risks associated 22 | with loading, using, modifying and/or developing or reproducing the 23 | software by the user in light of its specific status of free software, 24 | that may mean that it is complicated to manipulate, and that also 25 | therefore means that it is reserved for developers and experienced 26 | professionals having in-depth computer knowledge. Users are therefore 27 | encouraged to load and test the software's suitability as regards their 28 | requirements in conditions enabling the security of their systems and/or 29 | data to be ensured and, more generally, to use and operate it in the 30 | same conditions as regards security. 31 | 32 | The fact that you are presently reading this means that you have had 33 | knowledge of the CeCILL license and that you accept its terms. 34 | */ 35 | #ifdef __cplusplus 36 | extern "C" { 37 | #endif 38 | extern int32_t lga2khalimsky(struct xvimage *ga,struct xvimage *out, int32_t bar); 39 | extern int32_t lga2khalimsky3d(struct xvimage *ga, struct xvimage *out, int32_t bar); 40 | #ifdef __cplusplus 41 | } 42 | #endif 43 | -------------------------------------------------------------------------------- /pink/lwshedtopo.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright ESIEE (2009) 3 | 4 | m.couprie@esiee.fr 5 | 6 | This software is an image processing library whose purpose is to be 7 | used primarily for research and teaching. 8 | 9 | This software is governed by the CeCILL license under French law and 10 | abiding by the rules of distribution of free software. You can use, 11 | modify and/ or redistribute the software under the terms of the CeCILL 12 | license as circulated by CEA, CNRS and INRIA at the following URL 13 | "http://www.cecill.info". 14 | 15 | As a counterpart to the access to the source code and rights to copy, 16 | modify and redistribute granted by the license, users are provided only 17 | with a limited warranty and the software's author, the holder of the 18 | economic rights, and the successive licensors have only limited 19 | liability. 20 | 21 | In this respect, the user's attention is drawn to the risks associated 22 | with loading, using, modifying and/or developing or reproducing the 23 | software by the user in light of its specific status of free software, 24 | that may mean that it is complicated to manipulate, and that also 25 | therefore means that it is reserved for developers and experienced 26 | professionals having in-depth computer knowledge. Users are therefore 27 | encouraged to load and test the software's suitability as regards their 28 | requirements in conditions enabling the security of their systems and/or 29 | data to be ensured and, more generally, to use and operate it in the 30 | same conditions as regards security. 31 | 32 | The fact that you are presently reading this means that you have had 33 | knowledge of the CeCILL license and that you accept its terms. 34 | */ 35 | #ifdef __cplusplus 36 | extern "C" { 37 | #endif 38 | extern int32_t lwshedtopo_lwshedtopo(struct xvimage *image, int32_t connex); 39 | extern int32_t lreconsdilat(struct xvimage *g, struct xvimage *f, int32_t connex); 40 | extern int32_t lreconseros(struct xvimage *g, struct xvimage *f, int32_t connex); 41 | extern int32_t lwshedtopobin(struct xvimage *image, struct xvimage *marqueur, int32_t connex); 42 | #ifdef __cplusplus 43 | } 44 | #endif 45 | -------------------------------------------------------------------------------- /PWcut/union_find.h: -------------------------------------------------------------------------------- 1 | /*Copyright ESIEE (2009) 2 | 3 | Author : 4 | Camille Couprie (c.couprie@esiee.fr) 5 | 6 | Contributors : 7 | Hugues Talbot (h.talbot@esiee.fr) 8 | Leo Grady (leo.grady@siemens.com) 9 | Laurent Najman (l.najman@esiee.fr) 10 | 11 | This software contains some image processing algorithms whose purpose is to be 12 | used primarily for research. 13 | 14 | This software is governed by the CeCILL license under French law and 15 | abiding by the rules of distribution of free software. You can use, 16 | modify and/ or redistribute the software under the terms of the CeCILL 17 | license as circulated by CEA, CNRS and INRIA at the following URL 18 | "http://www.cecill.info". 19 | 20 | As a counterpart to the access to the source code and rights to copy, 21 | modify and redistribute granted by the license, users are provided only 22 | with a limited warranty and the software's author, the holder of the 23 | economic rights, and the successive licensors have only limited 24 | liability. 25 | 26 | In this respect, the user's attention is drawn to the risks associated 27 | with loading, using, modifying and/or developing or reproducing the 28 | software by the user in light of its specific status of free software, 29 | that may mean that it is complicated to manipulate, and that also 30 | therefore means that it is reserved for developers and experienced 31 | professionals having in-depth computer knowledge. Users are therefore 32 | encouraged to load and test the software's suitability as regards their 33 | requirements in conditions enabling the security of their systems and/or 34 | data to be ensured and, more generally, to use and operate it in the 35 | same conditions as regards security. 36 | 37 | The fact that you are presently reading this means that you have had 38 | knowledge of the CeCILL license and that you accept its terms. 39 | */ 40 | 41 | #ifdef __cplusplus 42 | extern "C" { 43 | #endif 44 | #include 45 | #include 46 | #include 47 | int element_link( int x,int y, uint32_t *Rnk, uint32_t *Fth); 48 | int element_find(int x, uint32_t *Fth ); 49 | uint32_t element_find_iteratif(uint32_t x, uint32_t *Fth ); 50 | 51 | #ifdef __cplusplus 52 | } 53 | #endif 54 | 55 | -------------------------------------------------------------------------------- /pink/lattribheight.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright ESIEE (2009) 3 | 4 | m.couprie@esiee.fr 5 | 6 | This software is an image processing library whose purpose is to be 7 | used primarily for research and teaching. 8 | 9 | This software is governed by the CeCILL license under French law and 10 | abiding by the rules of distribution of free software. You can use, 11 | modify and/ or redistribute the software under the terms of the CeCILL 12 | license as circulated by CEA, CNRS and INRIA at the following URL 13 | "http://www.cecill.info". 14 | 15 | As a counterpart to the access to the source code and rights to copy, 16 | modify and redistribute granted by the license, users are provided only 17 | with a limited warranty and the software's author, the holder of the 18 | economic rights, and the successive licensors have only limited 19 | liability. 20 | 21 | In this respect, the user's attention is drawn to the risks associated 22 | with loading, using, modifying and/or developing or reproducing the 23 | software by the user in light of its specific status of free software, 24 | that may mean that it is complicated to manipulate, and that also 25 | therefore means that it is reserved for developers and experienced 26 | professionals having in-depth computer knowledge. Users are therefore 27 | encouraged to load and test the software's suitability as regards their 28 | requirements in conditions enabling the security of their systems and/or 29 | data to be ensured and, more generally, to use and operate it in the 30 | same conditions as regards security. 31 | 32 | The fact that you are presently reading this means that you have had 33 | knowledge of the CeCILL license and that you accept its terms. 34 | */ 35 | #ifdef __cplusplus 36 | extern "C" { 37 | #endif 38 | extern int32_t lsegmentheight(struct xvimage *image, int32_t connex, int32_t param, int32_t max); 39 | extern int32_t lheightmaxima(struct xvimage *image, int32_t connex, int32_t param); 40 | extern int32_t lheightselnb(struct xvimage *image, int32_t connex, int32_t param, int32_t mode); 41 | extern int32_t lheightminima(struct xvimage *image, int32_t connex, int32_t param); 42 | extern void lattribheight_inverse(struct xvimage * image); 43 | #ifdef __cplusplus 44 | } 45 | #endif 46 | -------------------------------------------------------------------------------- /pink/lsaliency.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright ESIEE (2009) 3 | 4 | m.couprie@esiee.fr 5 | 6 | This software is an image processing library whose purpose is to be 7 | used primarily for research and teaching. 8 | 9 | This software is governed by the CeCILL license under French law and 10 | abiding by the rules of distribution of free software. You can use, 11 | modify and/ or redistribute the software under the terms of the CeCILL 12 | license as circulated by CEA, CNRS and INRIA at the following URL 13 | "http://www.cecill.info". 14 | 15 | As a counterpart to the access to the source code and rights to copy, 16 | modify and redistribute granted by the license, users are provided only 17 | with a limited warranty and the software's author, the holder of the 18 | economic rights, and the successive licensors have only limited 19 | liability. 20 | 21 | In this respect, the user's attention is drawn to the risks associated 22 | with loading, using, modifying and/or developing or reproducing the 23 | software by the user in light of its specific status of free software, 24 | that may mean that it is complicated to manipulate, and that also 25 | therefore means that it is reserved for developers and experienced 26 | professionals having in-depth computer knowledge. Users are therefore 27 | encouraged to load and test the software's suitability as regards their 28 | requirements in conditions enabling the security of their systems and/or 29 | data to be ensured and, more generally, to use and operate it in the 30 | same conditions as regards security. 31 | 32 | The fact that you are presently reading this means that you have had 33 | knowledge of the CeCILL license and that you accept its terms. 34 | */ 35 | #ifdef __cplusplus 36 | extern "C" { 37 | #endif 38 | int32_t lsaliency( 39 | struct xvimage *image, 40 | struct xvimage *masque, 41 | struct xvimage *saliency, 42 | int32_t connex); 43 | 44 | int32_t lsaliency6b( 45 | struct xvimage *image, 46 | struct xvimage *masque, 47 | struct xvimage *saliency, 48 | int32_t parite); 49 | 50 | /* 51 | typedef struct basinT { 52 | TypListe *neighbor; 53 | TypListe *passvalue; 54 | int32_t altitude; 55 | } basinT; 56 | */ 57 | #ifdef __cplusplus 58 | } 59 | #endif 60 | -------------------------------------------------------------------------------- /pink/sjcomptree.h: -------------------------------------------------------------------------------- 1 | #ifdef __cplusplus 2 | extern "C" { 3 | #endif 4 | 5 | 6 | #ifndef SJCOMPTREE_H 7 | #define SJCOMPTREE_H 8 | /* 9 | Copyright ESIEE (2009) 10 | 11 | m.couprie@esiee.fr 12 | 13 | This software is an image processing library whose purpose is to be 14 | used primarily for research and teaching. 15 | 16 | This software is governed by the CeCILL license under French law and 17 | abiding by the rules of distribution of free software. You can use, 18 | modify and/ or redistribute the software under the terms of the CeCILL 19 | license as circulated by CEA, CNRS and INRIA at the following URL 20 | "http://www.cecill.info". 21 | 22 | As a counterpart to the access to the source code and rights to copy, 23 | modify and redistribute granted by the license, users are provided only 24 | with a limited warranty and the software's author, the holder of the 25 | economic rights, and the successive licensors have only limited 26 | liability. 27 | 28 | In this respect, the user's attention is drawn to the risks associated 29 | with loading, using, modifying and/or developing or reproducing the 30 | software by the user in light of its specific status of free software, 31 | that may mean that it is complicated to manipulate, and that also 32 | therefore means that it is reserved for developers and experienced 33 | professionals having in-depth computer knowledge. Users are therefore 34 | encouraged to load and test the software's suitability as regards their 35 | requirements in conditions enabling the security of their systems and/or 36 | data to be ensured and, more generally, to use and operate it in the 37 | same conditions as regards security. 38 | 39 | The fact that you are presently reading this means that you have had 40 | knowledge of the CeCILL license and that you accept its terms. 41 | */ 42 | 43 | /* authors : J. Cousty - L. Najman and M. Couprie */ 44 | #include 45 | 46 | extern int32_t HierarchicalSegmentation(graphe *g, JCctree *CT, int32_t *Alt, int32_t * mergeEdge); 47 | extern int32_t sjcomponentTree(graphe *g, JCctree ** CompTree, double *CTaltitude); 48 | extern int32_t MergeTree_compatibleArbelaez(graphe *g, JCctree *CT, int32_t * results,int32_t * MergeEdges ); 49 | 50 | 51 | #endif 52 | #ifdef __cplusplus 53 | } 54 | #endif 55 | -------------------------------------------------------------------------------- /pink/mcunionfind.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright ESIEE (2009) 3 | 4 | m.couprie@esiee.fr 5 | 6 | This software is an image processing library whose purpose is to be 7 | used primarily for research and teaching. 8 | 9 | This software is governed by the CeCILL license under French law and 10 | abiding by the rules of distribution of free software. You can use, 11 | modify and/ or redistribute the software under the terms of the CeCILL 12 | license as circulated by CEA, CNRS and INRIA at the following URL 13 | "http://www.cecill.info". 14 | 15 | As a counterpart to the access to the source code and rights to copy, 16 | modify and redistribute granted by the license, users are provided only 17 | with a limited warranty and the software's author, the holder of the 18 | economic rights, and the successive licensors have only limited 19 | liability. 20 | 21 | In this respect, the user's attention is drawn to the risks associated 22 | with loading, using, modifying and/or developing or reproducing the 23 | software by the user in light of its specific status of free software, 24 | that may mean that it is complicated to manipulate, and that also 25 | therefore means that it is reserved for developers and experienced 26 | professionals having in-depth computer knowledge. Users are therefore 27 | encouraged to load and test the software's suitability as regards their 28 | requirements in conditions enabling the security of their systems and/or 29 | data to be ensured and, more generally, to use and operate it in the 30 | same conditions as regards security. 31 | 32 | The fact that you are presently reading this means that you have had 33 | knowledge of the CeCILL license and that you accept its terms. 34 | */ 35 | #ifdef __cplusplus 36 | extern "C" { 37 | #endif 38 | /* ============== */ 39 | /* types publics */ 40 | /* ============== */ 41 | 42 | typedef struct { 43 | int32_t Size; 44 | int32_t *Fth; 45 | int32_t *Rank; 46 | } Tarjan; 47 | 48 | /* ============== */ 49 | /* prototypes */ 50 | /* ============== */ 51 | 52 | extern Tarjan * CreeTarjan(int32_t taille); 53 | extern void TarjanTermine(Tarjan * T); 54 | extern void TarjanInit(Tarjan * T); 55 | extern void TarjanPrint(Tarjan * T); 56 | extern void TarjanMakeSet(Tarjan * T, int32_t x); 57 | extern int32_t TarjanFind(Tarjan * T, int32_t x); 58 | extern int32_t TarjanLink(Tarjan * T, int32_t x, int32_t y); 59 | extern int32_t TarjanLinkSafe(Tarjan * T, int32_t x, int32_t y); 60 | 61 | #ifdef __cplusplus 62 | } 63 | #endif 64 | -------------------------------------------------------------------------------- /pink/llabelextrema.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright ESIEE (2009) 3 | 4 | m.couprie@esiee.fr 5 | 6 | This software is an image processing library whose purpose is to be 7 | used primarily for research and teaching. 8 | 9 | This software is governed by the CeCILL license under French law and 10 | abiding by the rules of distribution of free software. You can use, 11 | modify and/ or redistribute the software under the terms of the CeCILL 12 | license as circulated by CEA, CNRS and INRIA at the following URL 13 | "http://www.cecill.info". 14 | 15 | As a counterpart to the access to the source code and rights to copy, 16 | modify and redistribute granted by the license, users are provided only 17 | with a limited warranty and the software's author, the holder of the 18 | economic rights, and the successive licensors have only limited 19 | liability. 20 | 21 | In this respect, the user's attention is drawn to the risks associated 22 | with loading, using, modifying and/or developing or reproducing the 23 | software by the user in light of its specific status of free software, 24 | that may mean that it is complicated to manipulate, and that also 25 | therefore means that it is reserved for developers and experienced 26 | professionals having in-depth computer knowledge. Users are therefore 27 | encouraged to load and test the software's suitability as regards their 28 | requirements in conditions enabling the security of their systems and/or 29 | data to be ensured and, more generally, to use and operate it in the 30 | same conditions as regards security. 31 | 32 | The fact that you are presently reading this means that you have had 33 | knowledge of the CeCILL license and that you accept its terms. 34 | */ 35 | #ifdef __cplusplus 36 | extern "C" { 37 | #endif 38 | #define LABMAX 0 39 | #define LABMIN 1 40 | #define LABFGD 3 41 | #define LABBGD 4 42 | 43 | /* ============== */ 44 | /* prototype for llabelextrema.c */ 45 | /* ============== */ 46 | 47 | extern int32_t llabelextrema( 48 | struct xvimage *img, 49 | int32_t connex, 50 | int32_t minimum, 51 | struct xvimage *lab, 52 | int32_t *nlabels 53 | ); 54 | 55 | extern int32_t llabeldil(struct xvimage *f, 56 | struct xvimage *m, 57 | int32_t xc, int32_t yc, 58 | struct xvimage *lab, 59 | int32_t *nlabels); 60 | 61 | extern int32_t llabelbin(struct xvimage *f, 62 | int32_t connex, 63 | struct xvimage *lab, 64 | int32_t *nlabels); 65 | 66 | #ifdef __cplusplus 67 | } 68 | #endif 69 | -------------------------------------------------------------------------------- /pink/mcsort.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | Copyright ESIEE (2009) 4 | 5 | m.couprie@esiee.fr 6 | 7 | This software is an image processing library whose purpose is to be 8 | used primarily for research and teaching. 9 | 10 | This software is governed by the CeCILL license under French law and 11 | abiding by the rules of distribution of free software. You can use, 12 | modify and/ or redistribute the software under the terms of the CeCILL 13 | license as circulated by CEA, CNRS and INRIA at the following URL 14 | "http://www.cecill.info". 15 | 16 | As a counterpart to the access to the source code and rights to copy, 17 | modify and redistribute granted by the license, users are provided only 18 | with a limited warranty and the software's author, the holder of the 19 | economic rights, and the successive licensors have only limited 20 | liability. 21 | 22 | In this respect, the user's attention is drawn to the risks associated 23 | with loading, using, modifying and/or developing or reproducing the 24 | software by the user in light of its specific status of free software, 25 | that may mean that it is complicated to manipulate, and that also 26 | therefore means that it is reserved for developers and experienced 27 | professionals having in-depth computer knowledge. Users are therefore 28 | encouraged to load and test the software's suitability as regards their 29 | requirements in conditions enabling the security of their systems and/or 30 | data to be ensured and, more generally, to use and operate it in the 31 | same conditions as regards security. 32 | 33 | The fact that you are presently reading this means that you have had 34 | knowledge of the CeCILL license and that you accept its terms. 35 | */ 36 | 37 | /* authors : J. Cousty - L. Najman and M. Couprie */ 38 | 39 | #ifdef __cplusplus 40 | extern "C" { 41 | #endif 42 | 43 | 44 | /* $Id: mcsort.h,v 1.3 2006/02/28 07:49:12 michel Exp $ */ 45 | #include 46 | 47 | extern int32_t Partitionner(int32_t *A, int32_t p, int32_t r); 48 | extern int32_t PartitionStochastique(int32_t *A, int32_t p, int32_t r); 49 | extern void TriRapide (int32_t * A, int32_t p, int32_t r); 50 | extern void TriRapideStochastique (int32_t * A, int32_t p, int32_t r); 51 | extern int32_t SelectionStochastique (int32_t * A, int32_t p, int32_t r, int32_t i); 52 | extern int32_t ElimineDupliques(int32_t *A, int32_t n); 53 | extern void d_TriRapideStochastique(int32_t * A, double *T, int32_t p, int32_t r); 54 | 55 | #ifdef __cplusplus 56 | } 57 | #endif -------------------------------------------------------------------------------- /pink/mclifo.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright ESIEE (2009) 3 | 4 | m.couprie@esiee.fr 5 | 6 | This software is an image processing library whose purpose is to be 7 | used primarily for research and teaching. 8 | 9 | This software is governed by the CeCILL license under French law and 10 | abiding by the rules of distribution of free software. You can use, 11 | modify and/ or redistribute the software under the terms of the CeCILL 12 | license as circulated by CEA, CNRS and INRIA at the following URL 13 | "http://www.cecill.info". 14 | 15 | As a counterpart to the access to the source code and rights to copy, 16 | modify and redistribute granted by the license, users are provided only 17 | with a limited warranty and the software's author, the holder of the 18 | economic rights, and the successive licensors have only limited 19 | liability. 20 | 21 | In this respect, the user's attention is drawn to the risks associated 22 | with loading, using, modifying and/or developing or reproducing the 23 | software by the user in light of its specific status of free software, 24 | that may mean that it is complicated to manipulate, and that also 25 | therefore means that it is reserved for developers and experienced 26 | professionals having in-depth computer knowledge. Users are therefore 27 | encouraged to load and test the software's suitability as regards their 28 | requirements in conditions enabling the security of their systems and/or 29 | data to be ensured and, more generally, to use and operate it in the 30 | same conditions as regards security. 31 | 32 | The fact that you are presently reading this means that you have had 33 | knowledge of the CeCILL license and that you accept its terms. 34 | */ 35 | #ifndef MC_LIFO 36 | #define MC_LIFO 37 | 38 | #ifdef __cplusplus 39 | extern "C" { 40 | #endif 41 | 42 | #ifndef _MCIMAGE_H 43 | #include 44 | #endif 45 | 46 | typedef struct { 47 | index_t Max; /* taille max de la Lifo */ 48 | index_t Sp; /* index de pile (pointe la 1ere case libre) */ 49 | index_t Pts[1]; 50 | } Lifo; 51 | 52 | /* ============== */ 53 | /* prototypes */ 54 | /* ============== */ 55 | extern Lifo * CreeLifoVide(index_t taillemax); 56 | extern void LifoFlush(Lifo * L); 57 | extern index_t LifoVide(Lifo * L); 58 | extern index_t LifoPop(Lifo * L); 59 | extern index_t LifoHead(Lifo * L); 60 | extern void LifoPush(Lifo * L, index_t V); 61 | extern void LifoPrint(Lifo * L); 62 | extern void LifoPrintLine(Lifo * L); 63 | extern void LifoTermine(Lifo * L); 64 | #ifdef __cplusplus 65 | } 66 | #endif 67 | #endif 68 | -------------------------------------------------------------------------------- /pink/mcindic.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright ESIEE (2009) 3 | 4 | m.couprie@esiee.fr 5 | 6 | This software is an image processing library whose purpose is to be 7 | used primarily for research and teaching. 8 | 9 | This software is governed by the CeCILL license under French law and 10 | abiding by the rules of distribution of free software. You can use, 11 | modify and/ or redistribute the software under the terms of the CeCILL 12 | license as circulated by CEA, CNRS and INRIA at the following URL 13 | "http://www.cecill.info". 14 | 15 | As a counterpart to the access to the source code and rights to copy, 16 | modify and redistribute granted by the license, users are provided only 17 | with a limited warranty and the software's author, the holder of the 18 | economic rights, and the successive licensors have only limited 19 | liability. 20 | 21 | In this respect, the user's attention is drawn to the risks associated 22 | with loading, using, modifying and/or developing or reproducing the 23 | software by the user in light of its specific status of free software, 24 | that may mean that it is complicated to manipulate, and that also 25 | therefore means that it is reserved for developers and experienced 26 | professionals having in-depth computer knowledge. Users are therefore 27 | encouraged to load and test the software's suitability as regards their 28 | requirements in conditions enabling the security of their systems and/or 29 | data to be ensured and, more generally, to use and operate it in the 30 | same conditions as regards security. 31 | 32 | The fact that you are presently reading this means that you have had 33 | knowledge of the CeCILL license and that you accept its terms. 34 | */ 35 | #ifdef __cplusplus 36 | extern "C" { 37 | #endif 38 | 39 | #ifndef _MCIMAGE_H 40 | #include 41 | #endif 42 | 43 | typedef uint8_t Indicstype; 44 | 45 | extern Indicstype *Indics; /* en global pour etre efficace */ 46 | 47 | #define Set(x,INDIC) Indics[x]|=(1< 41 | #endif 42 | 43 | typedef struct { 44 | index_t Max; /* taille max de la fifo */ 45 | index_t In; /* index ou ranger le prochain arrivant */ 46 | index_t Out; /* index d'ou retirer le prochain sortant */ 47 | index_t Pts[1]; 48 | } Fifo; 49 | 50 | /* ============== */ 51 | /* prototypes */ 52 | /* ============== */ 53 | 54 | extern Fifo * CreeFifoVide(index_t taillemax); 55 | extern void FifoFlush(Fifo * L); 56 | extern int32_t FifoVide(Fifo * L); 57 | extern index_t FifoPop(Fifo * L); 58 | extern void FifoPush(Fifo * L, index_t V); 59 | extern void FifoPushFirst(Fifo * L, index_t V); 60 | extern index_t FifoTaille(Fifo * L); 61 | extern void FifoPrint(Fifo * L); 62 | extern void FifoTermine(Fifo * L); 63 | 64 | 65 | 66 | #ifdef __cplusplus 67 | } 68 | #endif 69 | -------------------------------------------------------------------------------- /pink/jclderiche.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright ESIEE (2009) 3 | 4 | m.couprie@esiee.fr 5 | 6 | This software is an image processing library whose purpose is to be 7 | used primarily for research and teaching. 8 | 9 | This software is governed by the CeCILL license under French law and 10 | abiding by the rules of distribution of free software. You can use, 11 | modify and/ or redistribute the software under the terms of the CeCILL 12 | license as circulated by CEA, CNRS and INRIA at the following URL 13 | "http://www.cecill.info". 14 | 15 | As a counterpart to the access to the source code and rights to copy, 16 | modify and redistribute granted by the license, users are provided only 17 | with a limited warranty and the software's author, the holder of the 18 | economic rights, and the successive licensors have only limited 19 | liability. 20 | 21 | In this respect, the user's attention is drawn to the risks associated 22 | with loading, using, modifying and/or developing or reproducing the 23 | software by the user in light of its specific status of free software, 24 | that may mean that it is complicated to manipulate, and that also 25 | therefore means that it is reserved for developers and experienced 26 | professionals having in-depth computer knowledge. Users are therefore 27 | encouraged to load and test the software's suitability as regards their 28 | requirements in conditions enabling the security of their systems and/or 29 | data to be ensured and, more generally, to use and operate it in the 30 | same conditions as regards security. 31 | 32 | The fact that you are presently reading this means that you have had 33 | knowledge of the CeCILL license and that you accept its terms. 34 | */ 35 | #ifdef __cplusplus 36 | extern "C" { 37 | #endif 38 | /* ============== */ 39 | /* prototype for lderiche.c */ 40 | /* ============== */ 41 | 42 | extern int32_t lderiche( 43 | struct xvimage *image1, 44 | double alpha, 45 | int32_t function, 46 | double l 47 | ); 48 | 49 | extern void derichegen(double *x, /* image a traiter */ 50 | int32_t M, /* taille ligne */ 51 | int32_t N, /* taille colonne */ 52 | double *y1, /* zone temporaire de la taille d'une colonne */ 53 | double *y2, /* zone temporaire de la taille d'une ligne */ 54 | double *y, /* stocke un resultat temporaire, puis le resultat final */ 55 | double a1, double a2, double a3, double a4, 56 | double a5, double a6, double a7, double a8, 57 | double b1, double b2, double b3, double b4); 58 | 59 | #ifdef __cplusplus 60 | } 61 | #endif 62 | -------------------------------------------------------------------------------- /pink/lhierarchie.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright ESIEE (2009) 3 | 4 | m.couprie@esiee.fr 5 | 6 | This software is an image processing library whose purpose is to be 7 | used primarily for research and teaching. 8 | 9 | This software is governed by the CeCILL license under French law and 10 | abiding by the rules of distribution of free software. You can use, 11 | modify and/ or redistribute the software under the terms of the CeCILL 12 | license as circulated by CEA, CNRS and INRIA at the following URL 13 | "http://www.cecill.info". 14 | 15 | As a counterpart to the access to the source code and rights to copy, 16 | modify and redistribute granted by the license, users are provided only 17 | with a limited warranty and the software's author, the holder of the 18 | economic rights, and the successive licensors have only limited 19 | liability. 20 | 21 | In this respect, the user's attention is drawn to the risks associated 22 | with loading, using, modifying and/or developing or reproducing the 23 | software by the user in light of its specific status of free software, 24 | that may mean that it is complicated to manipulate, and that also 25 | therefore means that it is reserved for developers and experienced 26 | professionals having in-depth computer knowledge. Users are therefore 27 | encouraged to load and test the software's suitability as regards their 28 | requirements in conditions enabling the security of their systems and/or 29 | data to be ensured and, more generally, to use and operate it in the 30 | same conditions as regards security. 31 | 32 | The fact that you are presently reading this means that you have had 33 | knowledge of the CeCILL license and that you accept its terms. 34 | */ 35 | #ifdef __cplusplus 36 | extern "C" { 37 | #endif 38 | // Bibliotheque pour la segmentation hierarchique a base de LPE sur 39 | // les aretes 40 | 41 | #undef SURFACE 42 | #undef DYNAMIC 43 | #undef VOLUME 44 | #undef OMEGA 45 | #define SURFACE 0 46 | #define DYNAMIC 1 47 | #define VOLUME 2 48 | #define OMEGA 3 49 | 50 | RAG *construitRAG(struct xvimage *ga, struct xvimage *label, struct xvimage *annexe); 51 | 52 | int32_t * surfaceMergeTree(JCctree *CT, RAG *rag); 53 | int32_t * dynaMergeTree(JCctree *CT, RAG *rag); 54 | int32_t * volumeMergeTree(JCctree *CT, RAG *rag); 55 | int32_t * omegaMergeTree(JCctree *CT, RAG *rag); 56 | 57 | void mstCompute(mtree *MT, int32_t *MST, int32_t *Valeur, int32_t *Attribut); 58 | 59 | int32_t computeSaliencyMap(JCctree *CT, struct xvimage *ga, int32_t *label, int32_t *attribut); 60 | 61 | extern int32_t main_cascade(struct xvimage *image, struct xvimage *ga, int32_t param); 62 | extern int32_t saliencyGa(struct xvimage *ga, int32_t param, struct xvimage *annexe); 63 | #ifdef __cplusplus 64 | } 65 | #endif 66 | -------------------------------------------------------------------------------- /pink/mclistechainee.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright ESIEE (2009) 3 | 4 | m.couprie@esiee.fr 5 | 6 | This software is an image processing library whose purpose is to be 7 | used primarily for research and teaching. 8 | 9 | This software is governed by the CeCILL license under French law and 10 | abiding by the rules of distribution of free software. You can use, 11 | modify and/ or redistribute the software under the terms of the CeCILL 12 | license as circulated by CEA, CNRS and INRIA at the following URL 13 | "http://www.cecill.info". 14 | 15 | As a counterpart to the access to the source code and rights to copy, 16 | modify and redistribute granted by the license, users are provided only 17 | with a limited warranty and the software's author, the holder of the 18 | economic rights, and the successive licensors have only limited 19 | liability. 20 | 21 | In this respect, the user's attention is drawn to the risks associated 22 | with loading, using, modifying and/or developing or reproducing the 23 | software by the user in light of its specific status of free software, 24 | that may mean that it is complicated to manipulate, and that also 25 | therefore means that it is reserved for developers and experienced 26 | professionals having in-depth computer knowledge. Users are therefore 27 | encouraged to load and test the software's suitability as regards their 28 | requirements in conditions enabling the security of their systems and/or 29 | data to be ensured and, more generally, to use and operate it in the 30 | same conditions as regards security. 31 | 32 | The fact that you are presently reading this means that you have had 33 | knowledge of the CeCILL license and that you accept its terms. 34 | */ 35 | #ifndef MC_LISTECHAINEE 36 | #define MC_LISTECHAINEE 37 | 38 | #ifdef __cplusplus 39 | extern "C" { 40 | #endif 41 | /* definitions pour le module "mclistechainee.c" */ 42 | 43 | typedef int32_t TypElement; 44 | 45 | typedef struct LISTECHAINEE { /* definition de la structure Listechainee */ 46 | TypElement elt; /* element en tete de listechainee */ 47 | struct LISTECHAINEE *suite; /* pointe sur la suite de la listechainee */ 48 | } TypListechainee; 49 | 50 | extern TypListechainee * ListechaineeVide(); 51 | extern TypElement Tete(TypListechainee * l); 52 | extern TypListechainee * Suite(TypListechainee * l); 53 | extern TypListechainee * Cons(TypElement e, TypListechainee * l); 54 | extern void AfficheListechainee(TypListechainee * l); 55 | extern void DetruitListechainee(TypListechainee * l); 56 | extern int32_t EstVideListechainee(TypListechainee * l); 57 | extern TypListechainee * InListechainee(TypElement el, TypListechainee * lis); 58 | extern TypListechainee * UnionListechainee (TypListechainee * lis1, TypListechainee * lis2); 59 | 60 | #ifdef __cplusplus 61 | } 62 | #endif 63 | #endif 64 | -------------------------------------------------------------------------------- /PWcut/mclistechainee.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright ESIEE (2009) 3 | 4 | m.couprie@esiee.fr 5 | 6 | This software is an image processing library whose purpose is to be 7 | used primarily for research and teaching. 8 | 9 | This software is governed by the CeCILL license under French law and 10 | abiding by the rules of distribution of free software. You can use, 11 | modify and/ or redistribute the software under the terms of the CeCILL 12 | license as circulated by CEA, CNRS and INRIA at the following URL 13 | "http://www.cecill.info". 14 | 15 | As a counterpart to the access to the source code and rights to copy, 16 | modify and redistribute granted by the license, users are provided only 17 | with a limited warranty and the software's author, the holder of the 18 | economic rights, and the successive licensors have only limited 19 | liability. 20 | 21 | In this respect, the user's attention is drawn to the risks associated 22 | with loading, using, modifying and/or developing or reproducing the 23 | software by the user in light of its specific status of free software, 24 | that may mean that it is complicated to manipulate, and that also 25 | therefore means that it is reserved for developers and experienced 26 | professionals having in-depth computer knowledge. Users are therefore 27 | encouraged to load and test the software's suitability as regards their 28 | requirements in conditions enabling the security of their systems and/or 29 | data to be ensured and, more generally, to use and operate it in the 30 | same conditions as regards security. 31 | 32 | The fact that you are presently reading this means that you have had 33 | knowledge of the CeCILL license and that you accept its terms. 34 | */ 35 | #ifndef MC_LISTECHAINEE 36 | #define MC_LISTECHAINEE 37 | 38 | #ifdef __cplusplus 39 | extern "C" { 40 | #endif 41 | /* definitions pour le module "mclistechainee.c" */ 42 | 43 | typedef int32_t TypElement; 44 | 45 | typedef struct LISTECHAINEE { /* definition de la structure Listechainee */ 46 | TypElement elt; /* element en tete de listechainee */ 47 | struct LISTECHAINEE *suite; /* pointe sur la suite de la listechainee */ 48 | } TypListechainee; 49 | 50 | extern TypListechainee * ListechaineeVide(); 51 | extern TypElement Tete(TypListechainee * l); 52 | extern TypListechainee * Suite(TypListechainee * l); 53 | extern TypListechainee * Cons(TypElement e, TypListechainee * l); 54 | extern void AfficheListechainee(TypListechainee * l); 55 | extern void DetruitListechainee(TypListechainee * l); 56 | extern int32_t EstVideListechainee(TypListechainee * l); 57 | extern TypListechainee * InListechainee(TypElement el, TypListechainee * lis); 58 | extern TypListechainee * UnionListechainee (TypListechainee * lis1, TypListechainee * lis2); 59 | 60 | #ifdef __cplusplus 61 | } 62 | #endif 63 | #endif 64 | -------------------------------------------------------------------------------- /pink/llpeGA.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright ESIEE (2009) 3 | 4 | m.couprie@esiee.fr 5 | 6 | This software is an image processing library whose purpose is to be 7 | used primarily for research and teaching. 8 | 9 | This software is governed by the CeCILL license under French law and 10 | abiding by the rules of distribution of free software. You can use, 11 | modify and/ or redistribute the software under the terms of the CeCILL 12 | license as circulated by CEA, CNRS and INRIA at the following URL 13 | "http://www.cecill.info". 14 | 15 | As a counterpart to the access to the source code and rights to copy, 16 | modify and redistribute granted by the license, users are provided only 17 | with a limited warranty and the software's author, the holder of the 18 | economic rights, and the successive licensors have only limited 19 | liability. 20 | 21 | In this respect, the user's attention is drawn to the risks associated 22 | with loading, using, modifying and/or developing or reproducing the 23 | software by the user in light of its specific status of free software, 24 | that may mean that it is complicated to manipulate, and that also 25 | therefore means that it is reserved for developers and experienced 26 | professionals having in-depth computer knowledge. Users are therefore 27 | encouraged to load and test the software's suitability as regards their 28 | requirements in conditions enabling the security of their systems and/or 29 | data to be ensured and, more generally, to use and operate it in the 30 | same conditions as regards security. 31 | 32 | The fact that you are presently reading this means that you have had 33 | knowledge of the CeCILL license and that you accept its terms. 34 | */ 35 | #ifdef __cplusplus 36 | extern "C" { 37 | #endif 38 | #define TYP_VRAGARC int32_t 39 | #define TYP_VARC int32_t 40 | #define TYP_VSOM int32_t 41 | #ifndef HUGE 42 | #define HUGE HUGE_VAL 43 | #endif 44 | #define IN_PROCESS -2 45 | #define NO_LABEL -1 46 | 47 | #ifndef TRUE 48 | #define TRUE 1 49 | #endif 50 | 51 | #ifndef FALSE 52 | #define FALSE 0 53 | #endif 54 | 55 | #define IN_PROCESS -2 56 | #define NO_LABEL -1 57 | 58 | extern struct xvimage *mBorderWshed(struct xvimage *ga); 59 | extern struct xvimage *SeparatingEdge(struct xvimage *labels); 60 | extern struct xvimage *mBorderWshed2d(struct xvimage *ga); 61 | extern struct xvimage *mBorderWshed2drapide(struct xvimage *ga); 62 | extern int32_t flowMapping(struct xvimage* ga, int32_t* Label); 63 | extern int32_t flowMappingRecursif(struct xvimage* ga, int32_t* Label); 64 | extern int32_t flowMappingFloat(struct xvimage* ga, int32_t* Label); 65 | extern int32_t flowMappingDouble(struct xvimage* ga, int32_t* Label); 66 | //extern int32_t lpeGrapheAreteValuee(GrapheValue *gv, int32_t* Label); 67 | extern int32_t altitudePoint(struct xvimage *ga, int32_t i); 68 | #ifdef __cplusplus 69 | } 70 | #endif 71 | -------------------------------------------------------------------------------- /pink/lderiche.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright ESIEE (2009) 3 | 4 | m.couprie@esiee.fr 5 | 6 | This software is an image processing library whose purpose is to be 7 | used primarily for research and teaching. 8 | 9 | This software is governed by the CeCILL license under French law and 10 | abiding by the rules of distribution of free software. You can use, 11 | modify and/ or redistribute the software under the terms of the CeCILL 12 | license as circulated by CEA, CNRS and INRIA at the following URL 13 | "http://www.cecill.info". 14 | 15 | As a counterpart to the access to the source code and rights to copy, 16 | modify and redistribute granted by the license, users are provided only 17 | with a limited warranty and the software's author, the holder of the 18 | economic rights, and the successive licensors have only limited 19 | liability. 20 | 21 | In this respect, the user's attention is drawn to the risks associated 22 | with loading, using, modifying and/or developing or reproducing the 23 | software by the user in light of its specific status of free software, 24 | that may mean that it is complicated to manipulate, and that also 25 | therefore means that it is reserved for developers and experienced 26 | professionals having in-depth computer knowledge. Users are therefore 27 | encouraged to load and test the software's suitability as regards their 28 | requirements in conditions enabling the security of their systems and/or 29 | data to be ensured and, more generally, to use and operate it in the 30 | same conditions as regards security. 31 | 32 | The fact that you are presently reading this means that you have had 33 | knowledge of the CeCILL license and that you accept its terms. 34 | */ 35 | #ifdef __cplusplus 36 | extern "C" { 37 | #endif 38 | /* ============== */ 39 | /* prototype for lderiche.c */ 40 | /* ============== */ 41 | 42 | extern void derichegen(double *x, 43 | int32_t M, 44 | int32_t N, 45 | double *y1, 46 | double *y2, 47 | double *y, 48 | double a1, double a2, double a3, double a4, 49 | double a5, double a6, double a7, double a8, 50 | double b1, double b2, double b3, double b4); 51 | 52 | extern int32_t lderiche( 53 | struct xvimage *image1, 54 | double alpha, 55 | int32_t function, 56 | double l 57 | ); 58 | 59 | extern int32_t lshencastan(struct xvimage *image, double beta); 60 | 61 | extern int32_t lderiche3d( 62 | struct xvimage *image1, 63 | double alpha, 64 | int32_t function, 65 | double l 66 | ); 67 | 68 | extern int32_t llisseurrec3d( 69 | struct xvimage *image1, 70 | double alpha 71 | ); 72 | 73 | extern int32_t lgradientcd(struct xvimage *image, double alpha); 74 | extern int32_t lgaussianfilter(struct xvimage *image, double alpha); 75 | 76 | #ifdef __cplusplus 77 | } 78 | #endif 79 | -------------------------------------------------------------------------------- /pink/mincover.c: -------------------------------------------------------------------------------- 1 | /* 2 | MinCover algorithm: 3 | returns a topological cover (a collection of non-disjoint sets) in 4 | which weights are minimal 5 | author: Clement Farabet 6 | */ 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | #define false 0 23 | #define true 1 24 | 25 | // a helper to insert an index into a list 26 | static void insert(list **sl, int index) { 27 | list *tmp = NULL; 28 | list *csl = *sl; 29 | list *elem = (list*) malloc(sizeof(list)); 30 | if(!elem) exit(EXIT_FAILURE); 31 | elem->index = index; 32 | while(csl) 33 | { 34 | tmp = csl; 35 | csl = csl->next; 36 | } 37 | elem->next = csl; 38 | if(tmp) tmp->next = elem; 39 | else *sl = elem; 40 | } 41 | 42 | // recursive helper 43 | static void getmins(JCctree *CT, float *weights, long idx, float *min, long *argmin) { 44 | if (CT->tabnodes[idx].nbsons > 0) { 45 | JCsoncell *s; 46 | for (s = CT->tabnodes[idx].sonlist; s != NULL; s = s->next) { 47 | long sidx = s->son; 48 | if (weights[sidx] < weights[idx]) { 49 | min[sidx] = weights[sidx]; 50 | argmin[sidx] = sidx; 51 | } else { 52 | min[sidx] = min[idx]; 53 | argmin[sidx] = argmin[idx]; 54 | } 55 | getmins(CT, weights, sidx, min, argmin); 56 | } 57 | } 58 | } 59 | 60 | // returns a list of nodes correspondig to the min cover 61 | list * Min_Cover(MergeTree * MT) { 62 | // vars 63 | long i; 64 | mtree *T= MT->tree; 65 | float *weights = MT->weights; 66 | JCctree *CT = T->CT; 67 | int root = CT->root; 68 | 69 | // nb nodes 70 | long nbnodes = CT->nbnodes; 71 | 72 | // alloc two arrays, to store min/argmin 73 | float *min = (float *)malloc(sizeof(float)*nbnodes); 74 | long *argmin = (long *)malloc(sizeof(long)*nbnodes); 75 | 76 | // recursion - init 77 | min[root] = weights[root]; 78 | argmin[root] = root; 79 | 80 | // recursion 81 | getmins(CT, weights, root, min, argmin); 82 | 83 | // generate the cover 84 | char *done = (char *)calloc(sizeof(char),nbnodes); 85 | list *cut = NULL; 86 | for (i = 0; i < nbnodes; i++) { 87 | if (CT->tabnodes[i].nbsons == 0) { // only consider leaves 88 | long mini = argmin[i]; // for this leave, this is the index of the min node 89 | if (!done[mini]) { 90 | insert(&cut, mini); // store the min node ... 91 | done[mini] = 1; // ... only once 92 | } 93 | } 94 | } 95 | 96 | // cleanup 97 | free(min); 98 | free(argmin); 99 | free(done); 100 | 101 | // return cut 102 | return cut; 103 | } 104 | -------------------------------------------------------------------------------- /pink/lppm2GA.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright ESIEE (2009) 3 | 4 | m.couprie@esiee.fr 5 | 6 | This software is an image processing library whose purpose is to be 7 | used primarily for research and teaching. 8 | 9 | This software is governed by the CeCILL license under French law and 10 | abiding by the rules of distribution of free software. You can use, 11 | modify and/ or redistribute the software under the terms of the CeCILL 12 | license as circulated by CEA, CNRS and INRIA at the following URL 13 | "http://www.cecill.info". 14 | 15 | As a counterpart to the access to the source code and rights to copy, 16 | modify and redistribute granted by the license, users are provided only 17 | with a limited warranty and the software's author, the holder of the 18 | economic rights, and the successive licensors have only limited 19 | liability. 20 | 21 | In this respect, the user's attention is drawn to the risks associated 22 | with loading, using, modifying and/or developing or reproducing the 23 | software by the user in light of its specific status of free software, 24 | that may mean that it is complicated to manipulate, and that also 25 | therefore means that it is reserved for developers and experienced 26 | professionals having in-depth computer knowledge. Users are therefore 27 | encouraged to load and test the software's suitability as regards their 28 | requirements in conditions enabling the security of their systems and/or 29 | data to be ensured and, more generally, to use and operate it in the 30 | same conditions as regards security. 31 | 32 | The fact that you are presently reading this means that you have had 33 | knowledge of the CeCILL license and that you accept its terms. 34 | */ 35 | #ifdef __cplusplus 36 | extern "C" { 37 | #endif 38 | extern int32_t lpgm2ga(struct xvimage *im, struct xvimage *ga, int32_t param, double alpha); 39 | extern int32_t lpgm2gafloat(struct xvimage *im, struct xvimage *ga, int32_t param, double alpha); 40 | extern int32_t lpgm2gaDouble(struct xvimage *im, struct xvimage *ga, int32_t param, double alpha); 41 | extern int32_t lpgm2gaDouble(struct xvimage *im, struct xvimage *ga, int32_t param, double alpha); 42 | extern int32_t lppm2ga(struct xvimage *r, struct xvimage *v, struct xvimage *b, struct xvimage *ga, int32_t param); 43 | extern int32_t lpgm2ga3d(struct xvimage *im, struct xvimage *ga, int32_t param); 44 | extern int32_t lpgm2ga4d(struct xvimage4D *im, struct GA4d * ga, int32_t param); 45 | extern int32_t compute_scale(uint8_t **image, uint8_t **scale_image, float *scale_map, int32_t *sphere_no_points, /*int16_t ***sphere_points,*/ int32_t N, int32_t rs, int32_t cs, double * feature_mean, int32_t *feature_thr, int32_t * pow_value); 46 | extern void compute_homogeneitysb(uint8_t ** image, double *feature_mean, uint8_t *x_affinity, uint8_t *y_affinity, uint8_t* scale_image, int32_t *sphere_no_points, /*int16_t ***sphere_points,*/ int32_t *feature_thr, float **homogeneity_map, int32_t N, int32_t rs, int32_t cs, int32_t * pow_value); 47 | #ifdef __cplusplus 48 | } 49 | #endif 50 | -------------------------------------------------------------------------------- /PWcut/union_find.cpp: -------------------------------------------------------------------------------- 1 | /*Copyright ESIEE (2009) 2 | 3 | Author : 4 | Camille Couprie (c.couprie@esiee.fr) 5 | 6 | Contributors : 7 | Hugues Talbot (h.talbot@esiee.fr) 8 | Leo Grady (leo.grady@siemens.com) 9 | Laurent Najman (l.najman@esiee.fr) 10 | 11 | This software contains some image processing algorithms whose purpose is to be 12 | used primarily for research. 13 | 14 | This software is governed by the CeCILL license under French law and 15 | abiding by the rules of distribution of free software. You can use, 16 | modify and/ or redistribute the software under the terms of the CeCILL 17 | license as circulated by CEA, CNRS and INRIA at the following URL 18 | "http://www.cecill.info". 19 | 20 | As a counterpart to the access to the source code and rights to copy, 21 | modify and redistribute granted by the license, users are provided only 22 | with a limited warranty and the software's author, the holder of the 23 | economic rights, and the successive licensors have only limited 24 | liability. 25 | 26 | In this respect, the user's attention is drawn to the risks associated 27 | with loading, using, modifying and/or developing or reproducing the 28 | software by the user in light of its specific status of free software, 29 | that may mean that it is complicated to manipulate, and that also 30 | therefore means that it is reserved for developers and experienced 31 | professionals having in-depth computer knowledge. Users are therefore 32 | encouraged to load and test the software's suitability as regards their 33 | requirements in conditions enabling the security of their systems and/or 34 | data to be ensured and, more generally, to use and operate it in the 35 | same conditions as regards security. 36 | 37 | The fact that you are presently reading this means that you have had 38 | knowledge of the CeCILL license and that you accept its terms. 39 | */ 40 | 41 | #include 42 | #include 43 | #include 44 | #include 45 | 46 | /*! 47 | 48 | \file union_find.c 49 | \brief Implements Tarjan's union find structure 50 | 51 | \ingroup morpho 52 | 53 | \author Camille Couprie 54 | */ 55 | 56 | /*================================================*/ 57 | int element_link( int x,int y, uint32_t *Rnk, uint32_t *Fth) 58 | /*================================================*/ 59 | { 60 | if( Rnk[x] > Rnk[y]) 61 | { 62 | int t; 63 | t=x; 64 | x=y; 65 | y=t; 66 | } 67 | if( Rnk[x] == Rnk[y]) 68 | { 69 | Rnk[y]=Rnk[y]+1; 70 | } 71 | Fth[x] = y; 72 | return y; 73 | } 74 | 75 | 76 | 77 | /*===============================*/ 78 | int element_find(int x, uint32_t *Fth ) 79 | /*===============================*/ 80 | { 81 | if (Fth[x] != x) 82 | Fth[x] = element_find(Fth[x], Fth); 83 | return Fth[x]; 84 | } 85 | 86 | 87 | /*===============================*/ 88 | uint32_t element_find_iteratif(uint32_t x, uint32_t *Fth ) 89 | /*===============================*/ 90 | { 91 | 92 | while (Fth[x] != x) 93 | { 94 | x = Fth[x]; 95 | } 96 | return x; 97 | } 98 | -------------------------------------------------------------------------------- /PWcut/random_walker.h: -------------------------------------------------------------------------------- 1 | /*Copyright ESIEE (2009) 2 | 3 | Author : 4 | 5 | Camille Couprie (c.couprie@esiee.fr) 6 | 7 | Contributors : 8 | Leo Grady (leo.grady@siemens.com) 9 | Hugues Talbot (h.talbot@esiee.fr) 10 | Laurent Najman (l.najman@esiee.fr) 11 | 12 | This software contains some image processing algorithms whose purpose is to be 13 | used primarily for research. 14 | 15 | This software is governed by the CeCILL license under French law and 16 | abiding by the rules of distribution of free software. You can use, 17 | modify and/ or redistribute the software under the terms of the CeCILL 18 | license as circulated by CEA, CNRS and INRIA at the following URL 19 | "http://www.cecill.info". 20 | 21 | As a counterpart to the access to the source code and rights to copy, 22 | modify and redistribute granted by the license, users are provided only 23 | with a limited warranty and the software's author, the holder of the 24 | economic rights, and the successive licensors have only limited 25 | liability. 26 | 27 | In this respect, the user's attention is drawn to the risks associated 28 | with loading, using, modifying and/or developing or reproducing the 29 | software by the user in light of its specific status of free software, 30 | that may mean that it is complicated to manipulate, and that also 31 | therefore means that it is reserved for developers and experienced 32 | professionals having in-depth computer knowledge. Users are therefore 33 | encouraged to load and test the software's suitability as regards their 34 | requirements in conditions enabling the security of their systems and/or 35 | data to be ensured and, more generally, to use and operate it in the 36 | same conditions as regards security. 37 | 38 | The fact that you are presently reading this means that you have had 39 | knowledge of the CeCILL license and that you accept its terms. 40 | */ 41 | 42 | //#include 43 | #ifdef __cplusplus 44 | extern "C" { 45 | #endif 46 | 47 | #include 48 | #include 49 | typedef float DBL_TYPE; 50 | 51 | /******************************************************* 52 | Function RandomWalker computes the solution to the Dirichlet problem (RW potential function) 53 | on a general graph represented by an edge list, given boundary conditions (seeds, etc.) 54 | *******************************************************/ 55 | extern bool RandomWalker(uint32_t** index_edges, /* list of edges */ 56 | int M, /* number of edges */ 57 | uint32_t * index, /* list of vertices */ 58 | uint32_t * indic_vertex, /* boolean array of vertices*/ 59 | int N, /* number of vertices */ 60 | uint32_t* index_seeds, /* list of nodes that are seeded*/ 61 | DBL_TYPE ** boundary_values, /* associated values for seeds (labels)*/ 62 | int numb_boundary, /* number of seeded nodes */ 63 | int nb_labels, /* nb of different labels*/ 64 | DBL_TYPE ** proba) ; /* solution to the Dirichlet problem*/ 65 | 66 | 67 | #ifdef __cplusplus 68 | } 69 | #endif 70 | -------------------------------------------------------------------------------- /pink/mcutil.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright ESIEE (2009) 3 | 4 | m.couprie@esiee.fr 5 | 6 | This software is an image processing library whose purpose is to be 7 | used primarily for research and teaching. 8 | 9 | This software is governed by the CeCILL license under French law and 10 | abiding by the rules of distribution of free software. You can use, 11 | modify and/ or redistribute the software under the terms of the CeCILL 12 | license as circulated by CEA, CNRS and INRIA at the following URL 13 | "http://www.cecill.info". 14 | 15 | As a counterpart to the access to the source code and rights to copy, 16 | modify and redistribute granted by the license, users are provided only 17 | with a limited warranty and the software's author, the holder of the 18 | economic rights, and the successive licensors have only limited 19 | liability. 20 | 21 | In this respect, the user's attention is drawn to the risks associated 22 | with loading, using, modifying and/or developing or reproducing the 23 | software by the user in light of its specific status of free software, 24 | that may mean that it is complicated to manipulate, and that also 25 | therefore means that it is reserved for developers and experienced 26 | professionals having in-depth computer knowledge. Users are therefore 27 | encouraged to load and test the software's suitability as regards their 28 | requirements in conditions enabling the security of their systems and/or 29 | data to be ensured and, more generally, to use and operate it in the 30 | same conditions as regards security. 31 | 32 | The fact that you are presently reading this means that you have had 33 | knowledge of the CeCILL license and that you accept its terms. 34 | */ 35 | #ifdef __cplusplus 36 | extern "C" { 37 | #endif 38 | 39 | #define max(a,b) error_max_function_is_ambigous_use_mcmax_instead 40 | #define min(a,b) error_min_function_is_ambigous_use_mcmin_instead 41 | #define abs(b) error_abs_function_is_ambigous_use_mcabs_instead 42 | #define sign(b) error_sign_function_is_ambigous_use_mcsign_instead 43 | #define odd(b) error_odd_function_is_ambigous_use_mcodd_instead 44 | #define even(b) error_even_function_is_ambigous_use_mceven_instead 45 | #define sqr(b) error_sqr_function_is_ambigous_use_mcsqr_instead 46 | 47 | #define mcabs(X) ((X)>=0?(X):-(X)) 48 | #define mcmax(X,Y) ((X)>=(Y)?(X):(Y)) 49 | #define mcmin(X,Y) ((X)<=(Y)?(X):(Y)) 50 | #define mcodd(X) ((X)&1) 51 | #define mceven(X) (((X)&1)==0) 52 | #define arrondi(z) (((z)-(double)((int32_t)(z)))<=0.5?((int32_t)(z)):((int32_t)(z+1))) 53 | #define signe(z) (((z)>0.0)?1.0:-1.0) 54 | #define mcsqr(x) ((x)*(x)) 55 | 56 | #ifndef M_PI 57 | # define M_E 2.7182818284590452354 /* e */ 58 | # define M_LOG2E 1.4426950408889634074 /* log_2 e */ 59 | # define M_LOG10E 0.43429448190325182765 /* log_10 e */ 60 | # define M_LN2 0.69314718055994530942 /* log_e 2 */ 61 | # define M_LN10 2.30258509299404568402 /* log_e 10 */ 62 | # define M_PI 3.14159265358979323846 /* pi */ 63 | # define M_PI_2 1.57079632679489661923 /* pi/2 */ 64 | # define M_PI_4 0.78539816339744830962 /* pi/4 */ 65 | # define M_1_PI 0.31830988618379067154 /* 1/pi */ 66 | # define M_2_PI 0.63661977236758134308 /* 2/pi */ 67 | # define M_2_SQRTPI 1.12837916709551257390 /* 2/sqrt(pi) */ 68 | # define M_SQRT2 1.41421356237309504880 /* sqrt(2) */ 69 | # define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */ 70 | #endif 71 | #ifdef __cplusplus 72 | } 73 | #endif 74 | -------------------------------------------------------------------------------- /pink/mtrand64.h: -------------------------------------------------------------------------------- 1 | /* 2 | A C-program for MT19937-64 (2004/9/29 version). 3 | Coded by Takuji Nishimura and Makoto Matsumoto. 4 | 5 | This is a 64-bit version of Mersenne Twister pseudorandom number 6 | generator. 7 | 8 | Before using, initialize the state by using init_genrand64(seed) 9 | or init_by_array64(init_key, key_length). 10 | 11 | Copyright (C) 2004, Makoto Matsumoto and Takuji Nishimura, 12 | All rights reserved. 13 | 14 | Redistribution and use in source and binary forms, with or without 15 | modification, are permitted provided that the following conditions 16 | are met: 17 | 18 | 1. Redistributions of source code must retain the above copyright 19 | notice, this list of conditions and the following disclaimer. 20 | 21 | 2. Redistributions in binary form must reproduce the above copyright 22 | notice, this list of conditions and the following disclaimer in the 23 | documentation and/or other materials provided with the distribution. 24 | 25 | 3. The names of its contributors may not be used to endorse or promote 26 | products derived from this software without specific prior written 27 | permission. 28 | 29 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 30 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 31 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 32 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 33 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 34 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 35 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 36 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 37 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 38 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 39 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 40 | 41 | References: 42 | T. Nishimura, ``Tables of 64-bit Mersenne Twisters'' 43 | ACM Transactions on Modeling and 44 | Computer Simulation 10. (2000) 348--357. 45 | M. Matsumoto and T. Nishimura, 46 | ``Mersenne Twister: a 623-dimensionally equidistributed 47 | uniform pseudorandom number generator'' 48 | ACM Transactions on Modeling and 49 | Computer Simulation 8. (Jan. 1998) 3--30. 50 | 51 | Any feedback is very welcome. 52 | http://www.math.hiroshima-u.ac.jp/~m-mat/MT/emt.html 53 | email: m-mat @ math.sci.hiroshima-u.ac.jp (remove spaces) 54 | */ 55 | 56 | 57 | /* initializes mt[NN] with a seed */ 58 | void init_genrand64(unsigned long long seed); 59 | 60 | /* initialize by an array with array-length */ 61 | /* init_key is the array for initializing keys */ 62 | /* key_length is its length */ 63 | void init_by_array64(unsigned long long init_key[], 64 | unsigned long long key_length); 65 | 66 | /* generates a random number on [0, 2^64-1]-interval */ 67 | unsigned long long genrand64_int64(void); 68 | 69 | 70 | /* generates a random number on [0, 2^63-1]-interval */ 71 | long long genrand64_int63(void); 72 | 73 | /* generates a random number on [0,1]-real-interval */ 74 | double genrand64_real1(void); 75 | 76 | /* generates a random number on [0,1)-real-interval */ 77 | double genrand64_real2(void); 78 | 79 | /* generates a random number on (0,1)-real-interval */ 80 | double genrand64_real3(void); 81 | -------------------------------------------------------------------------------- /pink/mcfahsalembier.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright ESIEE (2009) 3 | 4 | m.couprie@esiee.fr 5 | 6 | This software is an image processing library whose purpose is to be 7 | used primarily for research and teaching. 8 | 9 | This software is governed by the CeCILL license under French law and 10 | abiding by the rules of distribution of free software. You can use, 11 | modify and/ or redistribute the software under the terms of the CeCILL 12 | license as circulated by CEA, CNRS and INRIA at the following URL 13 | "http://www.cecill.info". 14 | 15 | As a counterpart to the access to the source code and rights to copy, 16 | modify and redistribute granted by the license, users are provided only 17 | with a limited warranty and the software's author, the holder of the 18 | economic rights, and the successive licensors have only limited 19 | liability. 20 | 21 | In this respect, the user's attention is drawn to the risks associated 22 | with loading, using, modifying and/or developing or reproducing the 23 | software by the user in light of its specific status of free software, 24 | that may mean that it is complicated to manipulate, and that also 25 | therefore means that it is reserved for developers and experienced 26 | professionals having in-depth computer knowledge. Users are therefore 27 | encouraged to load and test the software's suitability as regards their 28 | requirements in conditions enabling the security of their systems and/or 29 | data to be ensured and, more generally, to use and operate it in the 30 | same conditions as regards security. 31 | 32 | The fact that you are presently reading this means that you have had 33 | knowledge of the CeCILL license and that you accept its terms. 34 | */ 35 | #ifdef __cplusplus 36 | extern "C" { 37 | #endif 38 | 39 | #ifndef _MCIMAGE_H 40 | #include 41 | #endif 42 | 43 | typedef struct FAHSELT { 44 | index_t Point; 45 | struct FAHSELT * Next; 46 | struct FAHSELT * Prev; 47 | } FahsElt; 48 | 49 | //#define FAHS_NPRIO 256 50 | #define FAHS_NPRIO 65536 51 | 52 | typedef struct { 53 | index_t Max; /* taille max de la fah (en nombre de points) */ 54 | int32_t Niv; /* niveau a partir duquel des listes existent */ 55 | index_t Util; /* nombre de points courant dans la fah */ 56 | index_t Maxutil; /* nombre de points utilises max (au cours du temps) */ 57 | FahsElt *Tete[FAHS_NPRIO]; /* tableau des tetes de liste (la ou l'on insere) */ 58 | FahsElt *Queue[FAHS_NPRIO];/* tableau des queues de liste (la ou l'on preleve) */ 59 | FahsElt *Libre; /* pile des cellules libres */ 60 | FahsElt Elts[1]; /* tableau des elements physiques */ 61 | } Fahs; 62 | 63 | /* ============== */ 64 | /* prototypes */ 65 | /* ============== */ 66 | 67 | extern Fahs * CreeFahsVide( 68 | index_t taillemax 69 | ); 70 | 71 | extern void FahsFlush( 72 | Fahs * L 73 | ); 74 | 75 | extern int32_t FahsVide( 76 | Fahs * L 77 | ); 78 | 79 | extern int32_t FahsVideNiveau( 80 | Fahs * L, 81 | int32_t niv 82 | ); 83 | 84 | extern index_t FahsPop( 85 | Fahs * L 86 | ); 87 | 88 | extern index_t FahsPopNiveau( 89 | Fahs * L, 90 | int32_t niv 91 | ); 92 | 93 | extern void FahsPush( 94 | Fahs * L, 95 | index_t Po, 96 | int32_t Ni 97 | ); 98 | 99 | extern void FahsTermine( 100 | Fahs * L 101 | ); 102 | 103 | extern void FahsPrint( 104 | Fahs * L 105 | ); 106 | #ifdef __cplusplus 107 | } 108 | #endif 109 | -------------------------------------------------------------------------------- /pink/mcfah.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright ESIEE (2009) 3 | 4 | m.couprie@esiee.fr 5 | 6 | This software is an image processing library whose purpose is to be 7 | used primarily for research and teaching. 8 | 9 | This software is governed by the CeCILL license under French law and 10 | abiding by the rules of distribution of free software. You can use, 11 | modify and/ or redistribute the software under the terms of the CeCILL 12 | license as circulated by CEA, CNRS and INRIA at the following URL 13 | "http://www.cecill.info". 14 | 15 | As a counterpart to the access to the source code and rights to copy, 16 | modify and redistribute granted by the license, users are provided only 17 | with a limited warranty and the software's author, the holder of the 18 | economic rights, and the successive licensors have only limited 19 | liability. 20 | 21 | In this respect, the user's attention is drawn to the risks associated 22 | with loading, using, modifying and/or developing or reproducing the 23 | software by the user in light of its specific status of free software, 24 | that may mean that it is complicated to manipulate, and that also 25 | therefore means that it is reserved for developers and experienced 26 | professionals having in-depth computer knowledge. Users are therefore 27 | encouraged to load and test the software's suitability as regards their 28 | requirements in conditions enabling the security of their systems and/or 29 | data to be ensured and, more generally, to use and operate it in the 30 | same conditions as regards security. 31 | 32 | The fact that you are presently reading this means that you have had 33 | knowledge of the CeCILL license and that you accept its terms. 34 | */ 35 | #ifdef __cplusplus 36 | extern "C" { 37 | #endif 38 | 39 | #ifndef _MCIMAGE_H 40 | #include 41 | #endif 42 | 43 | typedef struct FAHELT { 44 | index_t Point; 45 | struct FAHELT * Next; 46 | } FahElt; 47 | 48 | #ifndef NPRIO 49 | #define NPRIO 512 50 | #endif 51 | 52 | typedef struct { 53 | index_t Max; /* taille max de la fah (en nombre de points) */ 54 | int32_t Niv; /* niveau a partir duquel des listes existent */ 55 | index_t Util; /* nombre de points courant dans la fah */ 56 | index_t Maxutil; /* nombre de points utilises max (au cours du temps) */ 57 | FahElt *Tete[NPRIO]; /* tableau des tetes de liste */ 58 | FahElt *Queue; /* queue de liste (la ou l'on preleve) */ 59 | FahElt *QueueUrg; /* queue de liste d'urgence (la ou l'on preleve) */ 60 | FahElt *TeteUrg; /* tete de liste d'urgence (la ou l'on insere) */ 61 | FahElt *Libre; /* pile des cellules libres */ 62 | FahElt Elts[1]; /* tableau des elements physiques */ 63 | } Fah; 64 | 65 | /* ============== */ 66 | /* prototypes */ 67 | /* ============== */ 68 | 69 | extern Fah * CreeFahVide( 70 | index_t taillemax 71 | ); 72 | 73 | extern void FahFlush( 74 | Fah * L 75 | ); 76 | 77 | extern int32_t FahVide( 78 | Fah * L 79 | ); 80 | 81 | extern int32_t FahVideUrg( 82 | Fah * L 83 | ); 84 | 85 | extern int32_t FahVideNiveau( 86 | Fah * L, 87 | int32_t niv 88 | ); 89 | 90 | extern int32_t FahNiveau( 91 | Fah * L 92 | ); 93 | 94 | extern index_t FahPop( 95 | Fah * L 96 | ); 97 | 98 | extern index_t FahFirst( 99 | Fah * L 100 | ); 101 | 102 | extern void FahPush( 103 | Fah * L, 104 | index_t Po, 105 | int32_t Ni 106 | ); 107 | 108 | extern void FahTermine( 109 | Fah * L 110 | ); 111 | 112 | extern void FahPrint( 113 | Fah * L 114 | ); 115 | #ifdef __cplusplus 116 | } 117 | #endif 118 | -------------------------------------------------------------------------------- /mergetree.h: -------------------------------------------------------------------------------- 1 | #ifndef _MERGETREESTRUCT_ 2 | #define _MERGETREESTRUCT_ 3 | typedef struct { 4 | mtree *tree; 5 | RAG *rag; 6 | struct xvimage *labels; 7 | int32_t *altitudes; 8 | float *weights; 9 | int cs; 10 | int rs; 11 | } MergeTree; 12 | 13 | #endif 14 | 15 | 16 | #ifndef _MERGETREE_ 17 | #define _MERGETREE_ 18 | 19 | 20 | 21 | 22 | // create a proper Lua class to represent a merge tree 23 | #define MT "imgraph.MergeTree" 24 | 25 | static MergeTree *lua_toMergeTree (lua_State *L, int index) 26 | { 27 | MergeTree *mt = (MergeTree *)lua_touserdata(L, index); 28 | if (mt == NULL) luaL_typerror(L, index, MT); 29 | return mt; 30 | } 31 | 32 | static MergeTree *lua_checkMergeTree (lua_State *L, int index) 33 | { 34 | MergeTree *mt; 35 | luaL_checktype(L, index, LUA_TUSERDATA); 36 | mt = (MergeTree *)luaL_checkudata(L, index, MT); 37 | if (mt == NULL) luaL_typerror(L, index, MT); 38 | return mt; 39 | } 40 | 41 | static MergeTree *lua_pushMergeTree (lua_State *L) 42 | { 43 | MergeTree *mt = (MergeTree *)lua_newuserdata(L, sizeof(MergeTree)); 44 | mt->tree = NULL; 45 | mt->labels = NULL; 46 | mt->rag = NULL; 47 | mt->altitudes = NULL; 48 | mt->weights = NULL; 49 | mt->cs = 0; 50 | mt->rs = 0; 51 | luaL_getmetatable(L, MT); 52 | lua_setmetatable(L, -2); 53 | return mt; 54 | } 55 | 56 | static int MergeTree_gc (lua_State *L) 57 | { 58 | MergeTree *t = lua_toMergeTree(L, 1); 59 | if (t->tree) mergeTreeFree(t->tree); 60 | if (t->labels) freeimage(t->labels); 61 | if (t->rag) termineRAG(t->rag); 62 | if (t->altitudes) free(t->altitudes); 63 | if (t->weights) free(t->weights); 64 | return 0; 65 | } 66 | 67 | static int MergeTree_tostring (lua_State *L) 68 | { 69 | MergeTree *t = lua_toMergeTree(L, 1); 70 | char *cstr = (char *)malloc(10*1024); 71 | char *str = cstr; 72 | str += sprintf(str, "<%s>\n", MT); 73 | 74 | int32_t i; 75 | JCsoncell *s; 76 | JCctree *CT = t->tree->CT; 77 | str += sprintf(str, " + root: %d ; nbnodes: %d ; nbsoncells: %d", CT->root, CT->nbnodes, CT->nbsoncells); 78 | for (i = 0; i < CT->nbnodes; i++) 79 | { 80 | str += sprintf(str, "\n"); 81 | str += sprintf(str, " - node: %d ; level %d ; nbsons: %d ; father: %d ; ", 82 | i, CT->tabnodes[i].data, CT->tabnodes[i].nbsons, CT->tabnodes[i].father); 83 | if (t->weights) { 84 | str += sprintf(str, "weight: %f ; ", t->weights[i]); 85 | } 86 | if (CT->tabnodes[i].nbsons > 0) { 87 | str += sprintf(str, "sons: "); 88 | for (s = CT->tabnodes[i].sonlist; s != NULL; s = s->next) 89 | str += sprintf(str, "%d ", s->son); 90 | } 91 | if ((str-cstr) > 9*1024) { 92 | str += sprintf(str, "\n ... "); 93 | break; 94 | } 95 | } 96 | 97 | lua_pushfstring(L, "%s", cstr); 98 | free(cstr); 99 | return 1; 100 | } 101 | 102 | static const luaL_reg MergeTree_meta[] = { 103 | {"__gc", MergeTree_gc}, 104 | {"__tostring", MergeTree_tostring}, 105 | {0, 0} 106 | }; 107 | 108 | static int MergeTree_register (lua_State *L) 109 | { 110 | luaL_newmetatable(L, MT); /* create metatable for Graph, 111 | and add it to the Lua registry */ 112 | luaL_openlib(L, 0, MergeTree_meta, 0); /* fill metatable */ 113 | lua_pushliteral(L, "__metatable"); 114 | lua_pushvalue(L, -3); /* dup methods table*/ 115 | lua_rawset(L, -3); /* hide metatable: 116 | metatable.__metatable = methods */ 117 | lua_pop(L, 1); /* drop metatable */ 118 | } 119 | 120 | #endif 121 | -------------------------------------------------------------------------------- /pink/mcrbt.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright ESIEE (2009) 3 | 4 | m.couprie@esiee.fr 5 | 6 | This software is an image processing library whose purpose is to be 7 | used primarily for research and teaching. 8 | 9 | This software is governed by the CeCILL license under French law and 10 | abiding by the rules of distribution of free software. You can use, 11 | modify and/ or redistribute the software under the terms of the CeCILL 12 | license as circulated by CEA, CNRS and INRIA at the following URL 13 | "http://www.cecill.info". 14 | 15 | As a counterpart to the access to the source code and rights to copy, 16 | modify and redistribute granted by the license, users are provided only 17 | with a limited warranty and the software's author, the holder of the 18 | economic rights, and the successive licensors have only limited 19 | liability. 20 | 21 | In this respect, the user's attention is drawn to the risks associated 22 | with loading, using, modifying and/or developing or reproducing the 23 | software by the user in light of its specific status of free software, 24 | that may mean that it is complicated to manipulate, and that also 25 | therefore means that it is reserved for developers and experienced 26 | professionals having in-depth computer knowledge. Users are therefore 27 | encouraged to load and test the software's suitability as regards their 28 | requirements in conditions enabling the security of their systems and/or 29 | data to be ensured and, more generally, to use and operate it in the 30 | same conditions as regards security. 31 | 32 | The fact that you are presently reading this means that you have had 33 | knowledge of the CeCILL license and that you accept its terms. 34 | */ 35 | #ifdef __cplusplus 36 | extern "C" { 37 | #endif 38 | 39 | #ifndef _MCIMAGE_H 40 | #include 41 | #endif 42 | 43 | #define RBT_Black 0 44 | #define RBT_Red 1 45 | 46 | typedef double TypRbtKey; 47 | typedef index_t TypRbtAuxData; 48 | 49 | typedef struct RBTELT { 50 | TypRbtAuxData auxdata; 51 | TypRbtKey key; 52 | char color; 53 | struct RBTELT * left; 54 | struct RBTELT * right; 55 | struct RBTELT * parent; 56 | } RbtElt; 57 | 58 | typedef struct { 59 | index_t max; /* taille max du rbt (en nombre de points) */ 60 | index_t util; /* nombre de points courant dans le rbt */ 61 | index_t maxutil; /* nombre de points utilises max (au cours du temps) */ 62 | RbtElt *root; /* racine de l'arbre */ 63 | RbtElt *nil; /* sentinelle et element dont l'adresse joue le role de NIL */ 64 | RbtElt *libre; /* pile des cellules libres */ 65 | RbtElt elts[1]; /* tableau des elements physiques */ 66 | } Rbt; 67 | 68 | /* ============== */ 69 | /* prototypes */ 70 | /* ============== */ 71 | 72 | extern Rbt * mcrbt_CreeRbtVide( 73 | index_t taillemax); 74 | 75 | extern void RbtFlush( 76 | Rbt * T); 77 | 78 | extern int32_t mcrbt_RbtVide( 79 | Rbt * T); 80 | 81 | extern void mcrbt_RbtTermine( 82 | Rbt * T); 83 | 84 | extern void RbtPrint( 85 | Rbt * T); 86 | 87 | extern RbtElt * RbtSearch( 88 | Rbt * T, TypRbtKey k); 89 | 90 | extern RbtElt * mcrbt_RbtMinimum( 91 | Rbt * T, RbtElt * x); 92 | 93 | extern RbtElt * RbtMaximum( 94 | Rbt * T, RbtElt * x); 95 | 96 | extern RbtElt * RbtSuccessor( 97 | Rbt * T, RbtElt * x); 98 | 99 | extern RbtElt * mcrbt_RbtInsert( 100 | Rbt ** T, TypRbtKey k, TypRbtAuxData d); 101 | 102 | extern void RbtDelete( 103 | Rbt * T, RbtElt * z); 104 | 105 | extern TypRbtAuxData RbtPopMin( 106 | Rbt * T); 107 | 108 | extern TypRbtAuxData RbtPopMax( 109 | Rbt * T); 110 | 111 | extern TypRbtKey RbtMinLevel( 112 | Rbt * T); 113 | 114 | extern TypRbtKey RbtMaxLevel( 115 | Rbt * T); 116 | #ifdef __cplusplus 117 | } 118 | #endif 119 | -------------------------------------------------------------------------------- /pink/mcindic.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright ESIEE (2009) 3 | 4 | m.couprie@esiee.fr 5 | 6 | This software is an image processing library whose purpose is to be 7 | used primarily for research and teaching. 8 | 9 | This software is governed by the CeCILL license under French law and 10 | abiding by the rules of distribution of free software. You can use, 11 | modify and/ or redistribute the software under the terms of the CeCILL 12 | license as circulated by CEA, CNRS and INRIA at the following URL 13 | "http://www.cecill.info". 14 | 15 | As a counterpart to the access to the source code and rights to copy, 16 | modify and redistribute granted by the license, users are provided only 17 | with a limited warranty and the software's author, the holder of the 18 | economic rights, and the successive licensors have only limited 19 | liability. 20 | 21 | In this respect, the user's attention is drawn to the risks associated 22 | with loading, using, modifying and/or developing or reproducing the 23 | software by the user in light of its specific status of free software, 24 | that may mean that it is complicated to manipulate, and that also 25 | therefore means that it is reserved for developers and experienced 26 | professionals having in-depth computer knowledge. Users are therefore 27 | encouraged to load and test the software's suitability as regards their 28 | requirements in conditions enabling the security of their systems and/or 29 | data to be ensured and, more generally, to use and operate it in the 30 | same conditions as regards security. 31 | 32 | The fact that you are presently reading this means that you have had 33 | knowledge of the CeCILL license and that you accept its terms. 34 | */ 35 | /* gestion d'indicateurs binaires (jusqu'a 8) */ 36 | /* les indicateurs sont numerotes de 0 a 7 */ 37 | /* M. Couprie juillet 1996 */ 38 | 39 | /* gestion d'un indicateur binaire compact */ 40 | /* M. Couprie novembre 1999 */ 41 | 42 | /* 43 | #define TESTINDIC 44 | */ 45 | 46 | #include 47 | #include 48 | #include 49 | #include 50 | #include 51 | #include 52 | 53 | Indicstype *Indics = NULL; /* en global pour etre efficace */ 54 | 55 | /* ==================================== */ 56 | void IndicsInit(index_t Size) 57 | /* ==================================== */ 58 | { 59 | Indics = (Indicstype *)calloc(Size, sizeof(Indicstype)); 60 | if (Indics == NULL) 61 | { 62 | fprintf(stderr, "erreur allocation Indics\n"); 63 | exit(1); 64 | } 65 | } 66 | 67 | /* ==================================== */ 68 | void Indics1bitInit(index_t Size) 69 | /* ==================================== */ 70 | { 71 | Indics = (Indicstype *)calloc((Size-1)/8 + 1, sizeof(Indicstype)); 72 | if (Indics == NULL) 73 | { 74 | fprintf(stderr, "erreur allocation Indics\n"); 75 | exit(1); 76 | } 77 | } 78 | 79 | /* ==================================== */ 80 | void Indics1bitReInit(index_t Size) 81 | /* ==================================== */ 82 | { 83 | memset(Indics, 0, ((Size-1)/8 + 1) * sizeof(Indicstype)); 84 | } 85 | 86 | /* ==================================== */ 87 | void IndicsTermine() 88 | /* ==================================== */ 89 | { 90 | free(Indics); 91 | } 92 | 93 | #ifdef TESTINDIC 94 | void main() 95 | { 96 | IndicsInit(3); 97 | Set(0, 0); if (IsSet(0, 0)) printf("test1 ok\n"); 98 | printf("->%d\n", Indics[0]); 99 | Set(0, 1); if (IsSet(0, 1)) printf("test2 ok\n"); 100 | printf("->%d\n", Indics[0]); 101 | UnSet(0, 1); if (!IsSet(0, 1)) printf("test3 ok\n"); 102 | printf("->%d\n", Indics[0]); 103 | if (IsSet(0, 0)) printf("test4 ok\n"); 104 | UnSetAll(0); if (!IsSet(0, 0)) printf("test5 ok\n"); 105 | printf("->%d\n", Indics[0]); 106 | 107 | IndicsTermine(); 108 | } 109 | #endif 110 | -------------------------------------------------------------------------------- /pink/overlap.c: -------------------------------------------------------------------------------- 1 | /* 2 | Propagation algorithm for computating an overlap measure from 2 images 3 | author: Camille Couprie 4 | 1 aug. 2012 5 | */ 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | #define false 0 18 | #define true 1 19 | 20 | 21 | /*=====================================================================================*/ 22 | float * Overlap(struct xvimage * Isegment, struct xvimage * Imask, int nb_classes) 23 | /*=====================================================================================*/ 24 | // Computes the overlap score between a segment and the ground truth. 25 | // Overlap scores are given for each classes and stacked in a tensor. 26 | // inputs : * segment: binary image: foreground backround segmentation 27 | // * mask: ground truth image: integers between 1 and 22 28 | { 29 | int i, j, k, p, q; 30 | 31 | // get pointer to Isegment and Imask 32 | uint8_t *segment = UCHARDATA(Isegment); 33 | uint8_t *mask = UCHARDATA(Imask); 34 | 35 | int rs = rowsize(Isegment); 36 | int cs = colsize(Isegment); 37 | int N = rs*cs; 38 | 39 | Lifo * LIFO; 40 | LIFO = CreeLifoVide(N); 41 | if (LIFO == NULL) { fprintf(stderr, "Overlap : CreeLifoVide failed\n"); exit(0); } 42 | 43 | float * overlaping_class = (float*)calloc(nb_classes ,sizeof(float)); 44 | float * union_class = (float*)calloc(nb_classes ,sizeof(float)); 45 | 46 | uint8_t * Mrk = (uint8_t*)calloc(N ,sizeof(uint8_t)); 47 | if (Mrk == NULL) { fprintf(stderr, "Overlap : malloc failed\n"); exit(0); } 48 | 49 | 50 | // first pass to count the nb of different ground truth class intersecting with the segment 51 | int cpt_pixels_in_segment=0; 52 | for (i=0;i0.5) //for each class present in the segment 63 | { 64 | for (i=0;iseq_size) 79 | 80 | /* 81 | Codage du voisinage 82 | 83 | 84 | 3 2 1 85 | 4 X 0 86 | 5 6 7 87 | */ 88 | 89 | #define nonbord(p,rs,N) ((p%rs!=rs-1)&&(p>=rs)&&(p%rs!=0)&&(p=ps)&&(p=rs)&&(p%psUsage: ./ powerwatexample.exe 46 | 47 | \ingroup graph 48 | 49 | \author Camille Couprie 50 | */ 51 | 52 | 53 | #include 54 | #include 55 | #include 56 | 57 | 58 | /* =============================================================== */ 59 | int main(int argc, char **argv) 60 | /* =============================================================== */ 61 | /*Example showing how to call the power watershed solver on the 62 | following weighted graph 63 | 64 | (Seeded) node 2, value=0 65 | / \ 66 | 1/ \6 67 | / 2.5 \ 68 | node0 ----- node1 69 | \ / 70 | 5\ /6 71 | \ / 72 | (Seeded) node 3, value = 1 73 | */ 74 | { 75 | struct graph *G; 76 | int j; 77 | G = (struct graph *)malloc(sizeof(struct graph)); 78 | G->weight_type=1; // 1:double 0:uint32_t 79 | 80 | Allocate_Graph(G, 81 | 4,/*Number of nodes */ 82 | 2, /*Max Number of seeded nodes */ 83 | 5); /*Number of edges */ 84 | 85 | G->P = 1; /*we are solving one problem (multiple problems solved for multilabel segmentation)*/ 86 | 87 | /*Fill the seed values */ 88 | G->S=2;/*there are 2 seeded nodes*/ 89 | G->SeededNodes[0] = 2; // The node 2 is the first seeded node 90 | G->Labels[0]=0; // its value is 0 91 | G->SeededNodes[1] = 3; // The node 3 is the second seeded node 92 | G->Labels[1]=1; // its value is 1 93 | 94 | /*Add the weighted edges*/ 95 | AddEdge(G, 2/*node 2*/, 0/*node 0*/, 1/*weight value*/,0/*edge index*/); 96 | AddEdge(G, 2, 1, 6, 1); 97 | AddEdge(G, 0, 1, 2.5, 2); 98 | AddEdge(G, 0, 3, 5, 3); 99 | AddEdge(G, 1, 3, 6, 4); 100 | 101 | G->max_weight= 6; /*maximum weight value*/ 102 | 103 | /*Solving problem with Power Watersheds*/ 104 | 105 | PowerWatershed_q2(G); 106 | 107 | // Writing results 108 | printf("SOLUTION \n"); 109 | for (j = 0; j < 4; j++) 110 | printf("%f \n", G->Solution[0][j]); 111 | 112 | 113 | Free_Graph(G, G->N); 114 | 115 | 116 | return 0; 117 | } 118 | 119 | 120 | 121 | 122 | -------------------------------------------------------------------------------- /MalisCriterion.lua: -------------------------------------------------------------------------------- 1 | require 'nn' 2 | local MalisCriterion, parent = torch.class('nn.MalisCriterion', 'nn.Criterion') 3 | 4 | function MalisCriterion:__init(tree, metric, connex, threshold, margin, alternateposneg) 5 | parent.__init(self) 6 | connex = connex or 4 7 | -- 2d connectivities 8 | if connex == 4 then 9 | self.twoD = true 10 | self.nhood = torch.Tensor(2, 3) 11 | self.nhood[1][1] = 0 -- edge1: z offset 12 | self.nhood[1][2] = 0 -- edge1: y offset 13 | self.nhood[1][3] = 1 -- edge1: x offset 14 | self.nhood[2][1] = 0 -- edge1: z offset 15 | self.nhood[2][2] = 1 -- edge2: y offset 16 | self.nhood[2][3] = 0 -- edge2: x offset 17 | elseif connex == 8 then 18 | self.twoD = true 19 | self.nhood = torch.Tensor(4, 3) 20 | self.nhood[1][1] = 0 -- edge1: z offset 21 | self.nhood[1][2] = 0 -- edge1: y offset 22 | self.nhood[1][3] = 1 -- edge1: x offset 23 | self.nhood[2][1] = 0 -- edge1: z offset 24 | self.nhood[2][2] = 1 -- edge2: y offset 25 | self.nhood[2][3] = 0 -- edge2: x offset 26 | self.nhood[3][1] = 0 -- edge1: z offset 27 | self.nhood[3][2] = 1 -- edge3: y offset 28 | self.nhood[3][3] = 1 -- edge3: x offset 29 | self.nhood[4][1] = 0 -- edge1: z offset 30 | self.nhood[4][2] = 1 -- edge4: y offset 31 | self.nhood[4][3] = -1 -- edge4: x offset 32 | -- 3d connectivities 33 | elseif connex == 6 then 34 | self.twoD = false 35 | self.nhood = torch.Tensor(3, 3) 36 | self.nhood[1][1] = 0 -- edge1: z offset 37 | self.nhood[1][2] = 0 -- edge1: y offset 38 | self.nhood[1][3] = -1 -- edge1: x offset 39 | self.nhood[2][1] = 0 -- edge1: z offset 40 | self.nhood[2][2] = -1 -- edge2: y offset 41 | self.nhood[2][3] = 0 -- edge2: x offset 42 | self.nhood[3][1] = -1 -- edge1: z offset 43 | self.nhood[3][2] = 0 -- edge2: y offset 44 | self.nhood[3][3] = 0 -- edge2: x offset 45 | else 46 | error('connexity must be one of 4 | 8 for 2d images and 6 for 3d images') 47 | end 48 | self.threshold = threshold or 0.5 49 | self.margin = margin or 0.3 50 | self.posexample = true 51 | self.negexample = true 52 | self.alternateposneg = alternateposneg or false 53 | if self.alternateposneg then 54 | self.negexample = false -- negative example first 55 | end 56 | self.metric = metric or 'loss' -- loss | classified | rand 57 | self.tree = tree or 'max' 58 | if self.tree == 'min' then 59 | self.threshold = -self.threshold 60 | end 61 | self.inputtemp = torch.Tensor() 62 | self.targettemp = torch.Tensor() 63 | end 64 | 65 | function MalisCriterion:forward(input, target, posexample, negexample) 66 | self._i = input 67 | self._t = target 68 | 69 | -- pos? neg? 70 | if self.alternateposneg then 71 | self.posexample = not self.posexample 72 | self.negexample = not self.negexample 73 | end 74 | if (posexample ~= nil) then 75 | self.posexample = posexample 76 | end 77 | if (negexample ~= nil) then 78 | self.negexample = negexample 79 | end 80 | 81 | -- ensure contiguity by copying (contiguous() seems not to work properly...? or my scoping is bad...?) 82 | self.inputtemp:resizeAs(input):copy(input) 83 | self.targettemp:resizeAs(target):copy(target) 84 | 85 | -- shapes and signs 86 | if self.tree == 'min' then 87 | self.inputtemp:mul(-1) 88 | end 89 | if self.twoD and (target:size():size()==2) then -- convert to 3d by inserting a dimension 90 | self.inputtemp:resize(input:size(1),1,input:size(2),input:size(3)) 91 | self.targettemp:resize(1,target:size(1),target:size(2)) 92 | end 93 | 94 | -- run the MST and compute the loss and its derivative 95 | local e = {} 96 | e.loss,e.classified,e.rand = input.nn.MalisCriterion_forward(self, self.inputtemp, self.targettemp) 97 | 98 | -- shapes and signs 99 | if self.tree == 'min' then 100 | self.gradInput:mul(-1) 101 | end 102 | if self.twoD then 103 | self.gradInput:resize(input:size()) 104 | end 105 | 106 | -- return the goodness score 107 | self.output = e[self.metric] 108 | return self.output 109 | end 110 | 111 | function MalisCriterion:backward(input, target) 112 | if self._i ~= input or self._t ~= target then 113 | error('forward must be called once before backward()') 114 | end 115 | return self.gradInput 116 | end 117 | -------------------------------------------------------------------------------- /pink/mcweightgraph.h: -------------------------------------------------------------------------------- 1 | #ifdef __cplusplus 2 | extern "C" { 3 | #endif 4 | #include 5 | 6 | #ifndef _MCWEIGHTGRAPH_H_ 7 | #define _MCWEIGHTGRAPH_H_ 8 | 9 | 10 | /* 11 | Copyright ESIEE (2009) 12 | 13 | m.couprie@esiee.fr 14 | 15 | This software is an image processing library whose purpose is to be 16 | used primarily for research and teaching. 17 | 18 | This software is governed by the CeCILL license under French law and 19 | abiding by the rules of distribution of free software. You can use, 20 | modify and/ or redistribute the software under the terms of the CeCILL 21 | license as circulated by CEA, CNRS and INRIA at the following URL 22 | "http://www.cecill.info". 23 | 24 | As a counterpart to the access to the source code and rights to copy, 25 | modify and redistribute granted by the license, users are provided only 26 | with a limited warranty and the software's author, the holder of the 27 | economic rights, and the successive licensors have only limited 28 | liability. 29 | 30 | In this respect, the user's attention is drawn to the risks associated 31 | with loading, using, modifying and/or developing or reproducing the 32 | software by the user in light of its specific status of free software, 33 | that may mean that it is complicated to manipulate, and that also 34 | therefore means that it is reserved for developers and experienced 35 | professionals having in-depth computer knowledge. Users are therefore 36 | encouraged to load and test the software's suitability as regards their 37 | requirements in conditions enabling the security of their systems and/or 38 | data to be ensured and, more generally, to use and operate it in the 39 | same conditions as regards security. 40 | 41 | The fact that you are presently reading this means that you have had 42 | knowledge of the CeCILL license and that you accept its terms. 43 | */ 44 | 45 | /* authors : J. Cousty - L. Najman and M. Couprie */ 46 | 47 | /* $Id: mcgraphe.h,v 1.3 2006/02/28 07:49:12 michel Exp $ */ 48 | 49 | /* ================================================ */ 50 | /* types publics */ 51 | /* ================================================ */ 52 | #define MAXEDGES 2000000 53 | #define MAXDOUBLE FLOAT_MAX 54 | 55 | #define MINDOUBLE (1e-999) 56 | 57 | 58 | #ifndef _GRAPHESTRUCT_ 59 | #define _GRAPHESTRUCT_ 60 | typedef struct cell { 61 | 62 | uint32_t index; 63 | struct cell * next; 64 | } cell; 65 | 66 | typedef cell * pcell; 67 | 68 | typedef struct { 69 | uint32_t v_sommets; 70 | uint32_t nbsom; 71 | uint32_t nbmaxar; 72 | uint32_t nbar; 73 | uint32_t ind; /*number of edges*/ 74 | double * weight; /*edge weight indexed by cell index*/ 75 | uint32_t *tete; 76 | uint32_t *queue; 77 | uint32_t cs; 78 | uint32_t rs; 79 | cell * tasar; /* tableau des cellules (tas) */ 80 | cell * librear; /* liste des cellules libres geree en pile lifo */ 81 | pcell * listar; /* tableau des listes d'aretes indexe par les sommets */ 82 | } graphe; 83 | 84 | #endif 85 | 86 | 87 | /* ================================================ */ 88 | /* prototypes */ 89 | /* ================================================ */ 90 | 91 | extern graphe * initgraphe(uint32_t nbsom, uint32_t nbmaxar); 92 | extern graphe * sjinitgraphe(uint32_t nbsom, uint64_t nbmaxar); 93 | extern void terminegraphe(graphe * g); 94 | extern pcell allouecell(graphe * g); 95 | extern void liberecell(graphe * g, pcell p); 96 | extern void retiretete(graphe * g, pcell * pliste); 97 | extern void retirearete(graphe * g, uint32_t som, uint32_t a); 98 | extern int32_t estarete(graphe * g, uint32_t som, uint32_t a); 99 | extern int32_t indexarete(graphe * g, uint32_t som, uint32_t a, uint32_t ind); 100 | extern void ajoutearete(graphe * g, uint32_t som, uint32_t a); 101 | extern void addarete(graphe * g, uint32_t som, uint32_t a, double weight ); 102 | extern void setweight(graphe * g, uint32_t index, double value); 103 | extern void maille4graphe(graphe * g, uint32_t rs, uint32_t cs); 104 | //extern void nettoiegraphe(graphe * g); 105 | extern void aretesommets(uint32_t a, uint32_t N, uint32_t rs, uint32_t * s1, uint32_t * s2); 106 | extern int32_t estsuccesseur(graphe * g, uint32_t som, uint32_t a); 107 | extern int32_t estsymetrique(graphe * g); 108 | extern double getweight(graphe * g, uint32_t index); 109 | //extern uint32_t voisin(graphe *g, uint32_t x, uint32_t u); 110 | extern graphe * ReadGraphe(char * filename,double **Fv); 111 | extern void SaveGraphe(graphe * g, char *filename,double *Fv ); 112 | extern void setSize(graphe *g, int32_t rs , int32_t cs); 113 | 114 | #endif 115 | 116 | #ifdef __cplusplus 117 | } 118 | #endif 119 | -------------------------------------------------------------------------------- /pink/llpemeyer.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright ESIEE (2009) 3 | 4 | m.couprie@esiee.fr 5 | 6 | This software is an image processing library whose purpose is to be 7 | used primarily for research and teaching. 8 | 9 | This software is governed by the CeCILL license under French law and 10 | abiding by the rules of distribution of free software. You can use, 11 | modify and/ or redistribute the software under the terms of the CeCILL 12 | license as circulated by CEA, CNRS and INRIA at the following URL 13 | "http://www.cecill.info". 14 | 15 | As a counterpart to the access to the source code and rights to copy, 16 | modify and redistribute granted by the license, users are provided only 17 | with a limited warranty and the software's author, the holder of the 18 | economic rights, and the successive licensors have only limited 19 | liability. 20 | 21 | In this respect, the user's attention is drawn to the risks associated 22 | with loading, using, modifying and/or developing or reproducing the 23 | software by the user in light of its specific status of free software, 24 | that may mean that it is complicated to manipulate, and that also 25 | therefore means that it is reserved for developers and experienced 26 | professionals having in-depth computer knowledge. Users are therefore 27 | encouraged to load and test the software's suitability as regards their 28 | requirements in conditions enabling the security of their systems and/or 29 | data to be ensured and, more generally, to use and operate it in the 30 | same conditions as regards security. 31 | 32 | The fact that you are presently reading this means that you have had 33 | knowledge of the CeCILL license and that you accept its terms. 34 | */ 35 | #ifdef __cplusplus 36 | extern "C" { 37 | #endif 38 | /* ============== */ 39 | /* prototype for llpemeyer.c */ 40 | /* ============== */ 41 | 42 | extern int32_t llpemeyer( 43 | struct xvimage *image, 44 | struct xvimage *marqueurs, 45 | struct xvimage *marqueursfond, 46 | struct xvimage *masque, 47 | int32_t connex 48 | ); 49 | 50 | extern int32_t llpemeyersansligne( 51 | struct xvimage *image, 52 | struct xvimage *marqueurs, 53 | struct xvimage *marqueursfond, 54 | struct xvimage *masque, 55 | int32_t connex, 56 | struct xvimage *result 57 | ); 58 | 59 | extern int32_t llpemeyersanslignelab( 60 | struct xvimage *image, 61 | struct xvimage *marqueurs, // entree-sortie 62 | struct xvimage *masque, 63 | int32_t connex 64 | ); 65 | 66 | extern int32_t llpemeyer2( 67 | struct xvimage *image, 68 | struct xvimage *marqueurs, 69 | struct xvimage *masque, 70 | int32_t connex 71 | ); 72 | 73 | extern int32_t llpemeyer3( 74 | struct xvimage *image, 75 | struct xvimage *marqueurs, 76 | struct xvimage *masque, 77 | int32_t connex 78 | ); 79 | 80 | extern int32_t llpemeyer3d( 81 | struct xvimage *image, 82 | struct xvimage *marqueurs, 83 | struct xvimage *marqueursfond, 84 | struct xvimage *masque, 85 | int32_t connex 86 | ); 87 | 88 | extern int32_t llpemeyer3dsansligne( 89 | struct xvimage *image, 90 | struct xvimage *marqueurs, 91 | struct xvimage *marqueursfond, 92 | struct xvimage *masque, 93 | int32_t connex, 94 | struct xvimage *result 95 | ); 96 | 97 | extern int32_t llpemeyer3dsanslignelab( 98 | struct xvimage *image, 99 | struct xvimage *marqueurs, // entree-sortie 100 | struct xvimage *masque, 101 | int32_t connex 102 | ); 103 | 104 | extern int32_t llpemeyer3d2( 105 | struct xvimage *image, 106 | struct xvimage *marqueurs, 107 | struct xvimage *masque, 108 | int32_t connex 109 | ); 110 | 111 | extern int32_t llpemeyer3d2b( 112 | struct xvimage *image, 113 | struct xvimage *marqueurs, 114 | struct xvimage *masque, 115 | int32_t connex); 116 | 117 | extern int32_t llpemeyer3d3( 118 | struct xvimage *image, 119 | struct xvimage *marqueurs, 120 | struct xvimage *masque, 121 | int32_t connex 122 | ); 123 | 124 | extern int32_t llpemeyerkhalimsky( 125 | struct xvimage *image, 126 | struct xvimage *marqueurs, 127 | struct xvimage *marqueursfond, 128 | struct xvimage *masque 129 | ); 130 | 131 | extern int32_t llpemeyerbiconnecte( 132 | struct xvimage *image, 133 | struct xvimage *marqueurs, 134 | struct xvimage *marqueursfond, 135 | struct xvimage *masque, 136 | int32_t parite); 137 | 138 | int32_t llpemeyerbiconnecte3d( 139 | struct xvimage *image, 140 | struct xvimage *marqueurs, 141 | struct xvimage *marqueursfond, 142 | struct xvimage *masque); 143 | #ifdef __cplusplus 144 | } 145 | #endif 146 | -------------------------------------------------------------------------------- /graphcuts/README.TXT: -------------------------------------------------------------------------------- 1 | ################################################################### 2 | # # 3 | # MAXFLOW - software for computing mincut/maxflow in a graph # 4 | # Version 3.0 # 5 | # http://www.cs.adastral.ucl.ac.uk/~vnk/software.html # 6 | # # 7 | # Yuri Boykov (yuri@csd.uwo.ca) # 8 | # Vladimir Kolmogorov (vnk@adastral.ucl.ac.uk) # 9 | # 2001-2006 # 10 | # # 11 | ################################################################### 12 | 13 | 1. Introduction. 14 | 15 | This software library implements the maxflow algorithm described in 16 | 17 | "An Experimental Comparison of Min-Cut/Max-Flow Algorithms for Energy Minimization in Vision." 18 | Yuri Boykov and Vladimir Kolmogorov. 19 | In IEEE Transactions on Pattern Analysis and Machine Intelligence (PAMI), 20 | September 2004 21 | 22 | This algorithm was developed by Yuri Boykov and Vladimir Kolmogorov 23 | at Siemens Corporate Research. To make it available for public use, 24 | it was later reimplemented by Vladimir Kolmogorov based on open publications. 25 | 26 | If you use this software for research purposes, you should cite 27 | the aforementioned paper in any resulting publication. 28 | 29 | ---------------------------------------------------------------------- 30 | 31 | REUSING TREES: 32 | 33 | Starting with version 3.0, there is a also an option of reusing search 34 | trees from one maxflow computation to the next, as described in 35 | 36 | "Efficiently Solving Dynamic Markov Random Fields Using Graph Cuts." 37 | Pushmeet Kohli and Philip H.S. Torr 38 | International Conference on Computer Vision (ICCV), 2005 39 | 40 | If you use this option, you should cite 41 | the aforementioned paper in any resulting publication. 42 | 43 | Tested under windows, Visual C++ 6.0 compiler and unix (SunOS 5.8 44 | and RedHat Linux 7.0, GNU c++ compiler). 45 | 46 | ################################################################## 47 | 48 | 2. License & disclaimer. 49 | 50 | Copyright 2001 Vladimir Kolmogorov (vnk@adastral.ucl.ac.uk), Yuri Boykov (yuri@csd.uwo.ca). 51 | 52 | This software can be used for research purposes only. 53 | 54 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 55 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 56 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 57 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 58 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 59 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 60 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 61 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 62 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 63 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 64 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 65 | 66 | ################################################################## 67 | 68 | 3. Example usage. 69 | 70 | This section shows how to use the library to compute 71 | a minimum cut on the following graph: 72 | 73 | SOURCE 74 | / \ 75 | 1/ \2 76 | / 3 \ 77 | node0 -----> node1 78 | | <----- | 79 | | 4 | 80 | \ / 81 | 5\ /6 82 | \ / 83 | SINK 84 | 85 | /////////////////////////////////////////////////// 86 | 87 | #include 88 | #include "graph.h" 89 | 90 | int main() 91 | { 92 | typedef Graph GraphType; 93 | GraphType *g = new GraphType(/*estimated # of nodes*/ 2, /*estimated # of edges*/ 1); 94 | 95 | g -> add_node(); 96 | g -> add_node(); 97 | 98 | g -> add_tweights( 0, /* capacities */ 1, 5 ); 99 | g -> add_tweights( 1, /* capacities */ 2, 6 ); 100 | g -> add_edge( 0, 1, /* capacities */ 3, 4 ); 101 | 102 | int flow = g -> maxflow(); 103 | 104 | printf("Flow = %d\n", flow); 105 | printf("Minimum cut:\n"); 106 | if (g->what_segment(0) == GraphType::SOURCE) 107 | printf("node0 is in the SOURCE set\n"); 108 | else 109 | printf("node0 is in the SINK set\n"); 110 | if (g->what_segment(1) == GraphType::SOURCE) 111 | printf("node1 is in the SOURCE set\n"); 112 | else 113 | printf("node1 is in the SINK set\n"); 114 | 115 | delete g; 116 | 117 | return 0; 118 | } 119 | 120 | 121 | /////////////////////////////////////////////////// 122 | -------------------------------------------------------------------------------- /pink/MSF_utils.c: -------------------------------------------------------------------------------- 1 | /* 2 | Useful functions for MSF-cut algorithms 3 | author: Camille Couprie 4 | 21 oct. 2011 5 | */ 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include "MSF_utils.h" 20 | 21 | 22 | /*================================================*/ 23 | int nb_neighbors(int x, JCctree *CT, int nb_leafs) 24 | /*================================================*/ 25 | // returns the nb of neighbors of a node x in a component tree CT. 26 | { 27 | int tmp; 28 | if (xnbnodes) 29 | { 30 | tmp = CT->tabnodes[x].nbsons; 31 | if (tmp==0) tmp=1; 32 | return tmp+1; 33 | } 34 | else if (xnbnodes+nb_leafs) 35 | return 1; //CT->tabnodes[CT->root].nbsons; 36 | else return 1; 37 | } 38 | 39 | 40 | /*================================================*/ 41 | int neighbor(int x, int k, JCctree *CT, int nb_leafs, int * SeededNodes) 42 | /*================================================*/ 43 | { 44 | 45 | JCsoncell *s;int i, tmp; 46 | if (xnbnodes) 47 | { 48 | tmp = CT->tabnodes[x].nbsons; 49 | if (tmp==0) 50 | { if (k==0) return CT->tabnodes[x].father; 51 | return SeededNodes[x+1]; 52 | } 53 | else if (k<=tmp) 54 | { 55 | if (k==tmp) return CT->tabnodes[x].father; 56 | s = CT->tabnodes[x].sonlist; 57 | for (i=0;inext; // INEFFICACE A REFAIRE 58 | //fprintf(stderr," ici "); 59 | return s->son; 60 | } 61 | } 62 | else if (xnbnodes+nb_leafs) 63 | return x-CT->nbnodes; 64 | else 65 | { 66 | return CT->root; 67 | } 68 | } 69 | 70 | /*================================================*/ 71 | int element_link( int x,int y, uint32_t *Rnk, uint32_t *Fth) 72 | /*================================================*/ 73 | { 74 | if( Rnk[x] > Rnk[y]) 75 | { 76 | int t; 77 | t=x; 78 | x=y; 79 | y=t; 80 | } 81 | if( Rnk[x] == Rnk[y]) 82 | { 83 | Rnk[y]=Rnk[y]+1; 84 | } 85 | Fth[x] = y; 86 | return y; 87 | } 88 | 89 | /*===============================*/ 90 | int element_find(int x, uint32_t *Fth ) 91 | /*===============================*/ 92 | { 93 | if (Fth[x] != x) 94 | Fth[x] = element_find(Fth[x], Fth); 95 | return Fth[x]; 96 | } 97 | 98 | /* =============================================================== */ 99 | long Partitionner_dec(float *A, uint32_t * I, long p, long r) 100 | /* =============================================================== */ 101 | /* 102 | partitionne les elements de A entre l'indice p (compris) et l'indice r (compris) 103 | en deux groupes : ceux <= A[p] et les autres. 104 | */ 105 | { 106 | float t; 107 | int t1; 108 | float x = A[p]; 109 | long i = p - 1; 110 | long j = r + 1; 111 | while (1) 112 | { 113 | do j--; while (A[j] < x); 114 | do i++; while (A[i] > x); 115 | if (i < j) 116 | { 117 | t = A[i]; 118 | A[i] = A[j]; 119 | A[j] = t; 120 | t1 = I[i]; 121 | I[i] = I[j]; 122 | I[j] = t1; 123 | } 124 | else return j; 125 | } /* while (1) */ 126 | } /* Partitionner() */ 127 | 128 | /* =============================================================== */ 129 | long PartitionStochastique_dec (float *A, uint32_t * I, long p, long r) 130 | /* =============================================================== */ 131 | /* 132 | partitionne les elements de A entre l'indice p (compris) et l'indice r (compris) 133 | en deux groupes : ceux <= A[q] et les autres, avec q tire au hasard dans [p,r]. 134 | */ 135 | { 136 | float t; 137 | int t1; 138 | long q; 139 | /* rand must be 64-bit safe, should be OK now */ 140 | q = p + (genrand64_int64() % (r - p + 1)); 141 | // q = p + (rand() % (r - p + 1)); 142 | t = A[p]; /* echange A[p] et A[q] */ 143 | A[p] = A[q]; 144 | A[q] = t; 145 | 146 | t1 = I[p]; /* echange I[p] et I[q] */ 147 | I[p] = I[q]; 148 | I[q] = t1; 149 | 150 | return Partitionner_dec(A, I, p, r); 151 | } /* PartitionStochastique() */ 152 | 153 | /* =============================================================== */ 154 | void TriRapideStochastique_dec (float * A, uint32_t *I, long p, long r) 155 | /* =============================================================== */ 156 | /* 157 | trie les valeurs du tableau A de l'indice p (compris) a l'indice r (compris) 158 | par ordre decroissant 159 | */ 160 | { 161 | long q; 162 | if (p < r) 163 | { 164 | q = PartitionStochastique_dec(A, I, p, r); 165 | TriRapideStochastique_dec (A, I, p, q) ; 166 | TriRapideStochastique_dec (A, I, q+1, r) ; 167 | } 168 | } /* TriRapideStochastique() */ 169 | -------------------------------------------------------------------------------- /pink/mccomptree.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright ESIEE (2009) 3 | 4 | m.couprie@esiee.fr 5 | 6 | This software is an image processing library whose purpose is to be 7 | used primarily for research and teaching. 8 | 9 | This software is governed by the CeCILL license under French law and 10 | abiding by the rules of distribution of free software. You can use, 11 | modify and/ or redistribute the software under the terms of the CeCILL 12 | license as circulated by CEA, CNRS and INRIA at the following URL 13 | "http://www.cecill.info". 14 | 15 | As a counterpart to the access to the source code and rights to copy, 16 | modify and redistribute granted by the license, users are provided only 17 | with a limited warranty and the software's author, the holder of the 18 | economic rights, and the successive licensors have only limited 19 | liability. 20 | 21 | In this respect, the user's attention is drawn to the risks associated 22 | with loading, using, modifying and/or developing or reproducing the 23 | software by the user in light of its specific status of free software, 24 | that may mean that it is complicated to manipulate, and that also 25 | therefore means that it is reserved for developers and experienced 26 | professionals having in-depth computer knowledge. Users are therefore 27 | encouraged to load and test the software's suitability as regards their 28 | requirements in conditions enabling the security of their systems and/or 29 | data to be ensured and, more generally, to use and operate it in the 30 | same conditions as regards security. 31 | 32 | The fact that you are presently reading this means that you have had 33 | knowledge of the CeCILL license and that you accept its terms. 34 | */ 35 | #ifdef __cplusplus 36 | extern "C" { 37 | #endif 38 | /* ============================================================================== */ 39 | /* 40 | Structure de donnees pour la construction de l'arbre des composantes. 41 | 42 | Les sommets de cet arbre representent les composantes des coupes de F, 43 | a l'exception de celles qui sont egales a une composante d'un niveau inferieur. 44 | Il y a donc moins de N sommets (N = nombre de pixels) et de N-1 arcs. 45 | 46 | Une composante (sommet) est representee par une structure ctreenode. 47 | */ 48 | /* ============================================================================== */ 49 | 50 | #define ATTRIB_AREA 51 | #define ATTRIB_VOL 52 | 53 | typedef struct soncell // cell structure for the lists of sons 54 | { 55 | int32_t son; // index of the son in table tabnodes [struct ctree] 56 | struct soncell *next; // points to next cell 57 | } soncell; 58 | 59 | typedef struct // structure for one node in the component tree 60 | { 61 | uint8_t data; // node's level 62 | int32_t father; // index of the father node. value -1 indicates the root 63 | int32_t nbsons; // number or sons. value -1 indicates a deleted node 64 | #ifdef ATTRIB_AREA 65 | int32_t area; // number of pixels in the component 66 | #endif 67 | #ifdef ATTRIB_VOL 68 | int32_t vol; // volume of the component 69 | #endif 70 | soncell *sonlist; // list of sons (points to the first son cell) 71 | soncell *lastson; // direct pointer to the last son cell 72 | } ctreenode; 73 | 74 | typedef struct // structure for a component tree 75 | { 76 | int32_t nbnodes; // total number of nodes 77 | int32_t nbleafs; // total number of leafs 78 | int32_t nbsoncells; // number of avaliable son cells 79 | int32_t root; // index of the root node in table tabnodes 80 | ctreenode * tabnodes; // table which contains all the nodes 81 | soncell * tabsoncells; // table which contains all the son cells 82 | uint8_t *flags; // each flag is associated to the node with the same index 83 | } ctree; 84 | 85 | /* ==================================== */ 86 | /* PROTOTYPES */ 87 | /* ==================================== */ 88 | #define IMGCHAR 89 | //#define IMGLONG 90 | 91 | #ifdef IMGCHAR 92 | #define MAXGREY 256 93 | #else 94 | #define MAXGREY 65536 95 | #endif 96 | 97 | extern ctree * ComponentTreeAlloc(int32_t N); 98 | extern void ComponentTreeFree(ctree * CT); 99 | #ifdef IMGCHAR 100 | extern int32_t ComponentTree( uint8_t *F, int32_t rs, int32_t N, int32_t connex, // inputs 101 | #endif 102 | #ifdef IMGLONG 103 | extern int32_t ComponentTree( uint32_t *F, int32_t rs, int32_t N, int32_t connex, // inputs 104 | #endif 105 | ctree **CompTree, // output 106 | int32_t **CompMap // output 107 | ); 108 | #ifdef IMGCHAR 109 | extern int32_t ComponentTree3d( uint8_t *F, int32_t rs, int32_t ps, int32_t N, int32_t connex, // inputs 110 | #endif 111 | #ifdef IMGLONG 112 | extern int32_t ComponentTree3d( uint32_t *F, int32_t rs, int32_t ps, int32_t N, int32_t connex, // inputs 113 | #endif 114 | ctree **CompTree, // output 115 | int32_t **CompMap // output 116 | ); 117 | #ifdef __cplusplus 118 | } 119 | #endif 120 | -------------------------------------------------------------------------------- /pink/mcimage.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright ESIEE (2009) 3 | 4 | m.couprie@esiee.fr 5 | 6 | This software is an image processing library whose purpose is to be 7 | used primarily for research and teaching. 8 | 9 | This software is governed by the CeCILL license under French law and 10 | abiding by the rules of distribution of free software. You can use, 11 | modify and/ or redistribute the software under the terms of the CeCILL 12 | license as circulated by CEA, CNRS and INRIA at the following URL 13 | "http://www.cecill.info". 14 | 15 | As a counterpart to the access to the source code and rights to copy, 16 | modify and redistribute granted by the license, users are provided only 17 | with a limited warranty and the software's author, the holder of the 18 | economic rights, and the successive licensors have only limited 19 | liability. 20 | 21 | In this respect, the user's attention is drawn to the risks associated 22 | with loading, using, modifying and/or developing or reproducing the 23 | software by the user in light of its specific status of free software, 24 | that may mean that it is complicated to manipulate, and that also 25 | therefore means that it is reserved for developers and experienced 26 | professionals having in-depth computer knowledge. Users are therefore 27 | encouraged to load and test the software's suitability as regards their 28 | requirements in conditions enabling the security of their systems and/or 29 | data to be ensured and, more generally, to use and operate it in the 30 | same conditions as regards security. 31 | 32 | The fact that you are presently reading this means that you have had 33 | knowledge of the CeCILL license and that you accept its terms. 34 | */ 35 | #ifdef __cplusplus 36 | extern "C" { 37 | #endif 38 | 39 | #ifndef _MCIMAGE_H 40 | 41 | // attention : les index doivent être signés (pour les parcours rétro : for(i = N-1; i >=0; i--)) 42 | #ifdef MC_64_BITS 43 | typedef int64_t index_t; 44 | #else 45 | typedef int32_t index_t; 46 | #endif 47 | 48 | /* ============== */ 49 | /* prototypes for mcimage.c */ 50 | /* ============== */ 51 | 52 | extern struct xvimage *allocimage(char * name, index_t rs, index_t cs, index_t ds, int32_t t); 53 | extern struct xvimage *allocmultimage(char * name, index_t rs, index_t cs, index_t ds, index_t ts, index_t nb, int32_t t); 54 | extern void razimage(struct xvimage *f); 55 | extern struct xvimage *allocheader(char * name, index_t rs, index_t cs, index_t d, int32_t t); 56 | extern int32_t showheader(char * name); 57 | extern void freeimage(struct xvimage *image); 58 | extern struct xvimage *copyimage(struct xvimage *f); 59 | extern int32_t copy2image(struct xvimage *dest, struct xvimage *source); 60 | extern int32_t equalimages(struct xvimage *im1, struct xvimage *im2); 61 | extern void list2image(struct xvimage * image, double *P, index_t n); 62 | extern double * image2list(struct xvimage * image, index_t *n); 63 | 64 | extern void writeimage( 65 | struct xvimage * image, 66 | char *filename 67 | ); 68 | 69 | extern void writese( 70 | struct xvimage * image, 71 | char *filename, 72 | index_t x, index_t y, index_t z 73 | ); 74 | 75 | extern void writelongimage( 76 | struct xvimage * image, 77 | char *filename 78 | ); 79 | 80 | extern void writerawimage( 81 | struct xvimage * image, 82 | char *filename 83 | ); 84 | 85 | extern void writeascimage( 86 | struct xvimage * image, 87 | char *filename 88 | ); 89 | 90 | extern void printimage( 91 | struct xvimage * image 92 | ); 93 | 94 | extern void writergbimage( 95 | struct xvimage * redimage, 96 | struct xvimage * greenimage, 97 | struct xvimage * blueimage, 98 | char *filename 99 | ); 100 | 101 | extern void writergbascimage( 102 | struct xvimage * redimage, 103 | struct xvimage * greenimage, 104 | struct xvimage * blueimage, 105 | char *filename 106 | ); 107 | 108 | extern struct xvimage * readimage( 109 | char *filename 110 | ); 111 | 112 | extern struct xvimage * readheader( 113 | char *filename 114 | ); 115 | 116 | extern struct xvimage * readse(char *filename, index_t *x, index_t *y, index_t*z); 117 | 118 | extern struct xvimage * readlongimage( 119 | char *filename 120 | ); 121 | 122 | extern int32_t readrgbimage( 123 | char *filename, 124 | struct xvimage ** r, 125 | struct xvimage ** g, 126 | struct xvimage ** b 127 | ); 128 | 129 | extern int32_t readbmp( 130 | char *filename, 131 | struct xvimage ** r, 132 | struct xvimage ** g, 133 | struct xvimage ** b 134 | ); 135 | 136 | extern void writebmp( 137 | struct xvimage * redimage, 138 | struct xvimage * greenimage, 139 | struct xvimage * blueimage, 140 | char *filename 141 | ); 142 | 143 | extern int32_t readrgb( 144 | char *filename, 145 | struct xvimage ** r, 146 | struct xvimage ** g, 147 | struct xvimage ** b 148 | ); 149 | 150 | extern int32_t convertgen(struct xvimage **f1, struct xvimage **f2); 151 | extern int32_t convertlong(struct xvimage **f1); 152 | extern int32_t convertfloat(struct xvimage **f1); 153 | 154 | #define _MCIMAGE_H 155 | #endif 156 | 157 | #ifdef __cplusplus 158 | } 159 | #endif 160 | -------------------------------------------------------------------------------- /PWcut/powerwatershed.c: -------------------------------------------------------------------------------- 1 | /* 2 | Power watershed algorithm for Maximum Spanning Forest (MSF) computation 3 | implemented to compute an MSF cut in a tree (hierarchy) 4 | author: Camille Couprie 5 | 31 oct. 2011 6 | */ 7 | 8 | #include 9 | #include 10 | #include 11 | /*#include 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include */ 20 | 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | #ifndef _LISTSTRUCT_ 28 | #define _LISTSTRUCT_ 29 | typedef struct list 30 | { 31 | int index; 32 | struct list *next; 33 | } list ; 34 | #endif 35 | 36 | 37 | 38 | //#define false 0 39 | //#define true 1 40 | 41 | /*================================================*/ 42 | void Insert(list **sl, int index) 43 | /*================================================*/ 44 | { 45 | list *tmp = NULL; 46 | list *csl = *sl; 47 | list *elem = (list*) malloc(sizeof(list)); 48 | if(!elem) exit(EXIT_FAILURE); 49 | elem->index = index; 50 | while(csl) 51 | { 52 | tmp = csl; 53 | csl = csl->next; 54 | } 55 | elem->next = csl; 56 | if(tmp) tmp->next = elem; 57 | else *sl = elem; 58 | } 59 | 60 | /*=====================================================================================*/ 61 | list * Powerwatershed(MergeTree * MT) 62 | /*=====================================================================================*/ 63 | /*Segment a tree into two components. 64 | Returns a list of nodes correspunding to the Max Spanning Forest cut, 65 | computed using Power watershed's algorithm */ 66 | { 67 | int y, i, j, tmp; 68 | int nb_markers; int nb_leafs; 69 | int N, M; 70 | float val=1; //weight parameter for leafs. 71 | 72 | // -------- Gathering usefull input graph (MT) informations ----------- 73 | 74 | mtree * T= MT->tree; 75 | float * W = MT->weights; 76 | JCctree *CT = T->CT; 77 | int root_node = CT->root; 78 | JCsoncell *s; 79 | 80 | //nb nodes 81 | M = CT->nbnodes; 82 | 83 | // nb_edges 84 | nb_leafs = 0; 85 | for (i = 0; i < M; i++) 86 | if (CT->tabnodes[i].nbsons == 0) 87 | nb_leafs++; 88 | 89 | nb_markers = nb_leafs+1; 90 | N=M+nb_markers; 91 | M=N-1; 92 | printf("Nb nodes:%d Nb edges: %d Nb leafs :%d \n", N, M, nb_leafs); 93 | 94 | 95 | struct graph *G; 96 | int j; 97 | G = (struct graph *)malloc(sizeof(struct graph)); 98 | G->weight_type=1; // 1:double 0:uint32_t 99 | 100 | Allocate_Graph(G, 101 | N,/*Number of nodes */ 102 | nb_markers, /*Max Number of seeded nodes */ 103 | M); /*Number of edges */ 104 | 105 | G->P = 1; /*we are solving one problem (multiple problems solved for multilabel segmentation)*/ 106 | 107 | /*Fill the seeds values */ 108 | G->S=nb_markers;/*there are nb_markers seeded nodes*/ 109 | G->SeededNodes[0]= M; 110 | G->Labels[0]=0; 111 | j=1; 112 | for (i = 0; i < CT->nbnodes; i++) 113 | if (CT->tabnodes[i].nbsons == 0) 114 | { 115 | G->SeededNodes[j]= i+CT->nbnodes; 116 | G->Labels[j]=1; 117 | j++; 118 | } 119 | 120 | /*Add the weighted edges*/ 121 | for (i=0;inbnodes;i++) 122 | { 123 | tmp = CT->tabnodes[i].nbsons; 124 | if (tmp==0) //leaf 125 | { 126 | y= SeededNodes[i+1]; // edge index 127 | // fprintf(stderr,"edge (%d %d) %d \n", i,y, (int)(weights[y]*CTE_WEIGHTS )); 128 | AddEdge(G, i, SeededNodes[i], weights[y],y/*edge index*/); 129 | 130 | } 131 | else 132 | { 133 | for ( s = CT->tabnodes[i].sonlist;s!=NULL;s = s->next) 134 | { 135 | y=s->son; 136 | // fprintf(stderr,"edge (%d %d) %d \n", i,y, (int)(weights[y]*CTE_WEIGHTS )); 137 | AddEdge(G, i, y, weights[y],y/*edge index*/); 138 | } 139 | } 140 | } 141 | AddEdge(G, root_node, M, weights[y],y/*edge index*/); 142 | 143 | G->max_weight= val; /*maximum weight value*/ 144 | 145 | /*Solving problem with Power Watersheds*/ 146 | 147 | PowerWatershed_q2(G); 148 | 149 | // Writing results 150 | printf("SOLUTION \n"); 151 | for (j = 0; j < G->N; j++) 152 | printf("%f \n", G->Solution[0][j]); 153 | 154 | // ------------------ Process the tree to find the cut ---------------------- 155 | list * cut = NULL; 156 | for (i = 0; i < CT->nbnodes; i++) 157 | { 158 | // nodes having a different value than their father are in the cut 159 | if ((CT->tabnodes[i].father != -1) && (G->Solution[0][CT->tabnodes[i].father] != G->Solution[0][i])) 160 | Insert(&cut, i); 161 | // leafs having the same label as the root are in the cut 162 | if ((CT->tabnodes[i].nbsons == 0) && (G->Solution[0][i]==0)) 163 | Insert(&cut, i); 164 | } 165 | 166 | 167 | if (cut == NULL) Insert(&cut, root_node); 168 | //PrintList(cut); 169 | 170 | free(SeededNodes); 171 | Free_Graph(G, G->N); 172 | 173 | return cut; 174 | 175 | 176 | 177 | } 178 | 179 | -------------------------------------------------------------------------------- /pink/mckhalimsky2d.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright ESIEE (2009) 3 | 4 | m.couprie@esiee.fr 5 | 6 | This software is an image processing library whose purpose is to be 7 | used primarily for research and teaching. 8 | 9 | This software is governed by the CeCILL license under French law and 10 | abiding by the rules of distribution of free software. You can use, 11 | modify and/ or redistribute the software under the terms of the CeCILL 12 | license as circulated by CEA, CNRS and INRIA at the following URL 13 | "http://www.cecill.info". 14 | 15 | As a counterpart to the access to the source code and rights to copy, 16 | modify and redistribute granted by the license, users are provided only 17 | with a limited warranty and the software's author, the holder of the 18 | economic rights, and the successive licensors have only limited 19 | liability. 20 | 21 | In this respect, the user's attention is drawn to the risks associated 22 | with loading, using, modifying and/or developing or reproducing the 23 | software by the user in light of its specific status of free software, 24 | that may mean that it is complicated to manipulate, and that also 25 | therefore means that it is reserved for developers and experienced 26 | professionals having in-depth computer knowledge. Users are therefore 27 | encouraged to load and test the software's suitability as regards their 28 | requirements in conditions enabling the security of their systems and/or 29 | data to be ensured and, more generally, to use and operate it in the 30 | same conditions as regards security. 31 | 32 | The fact that you are presently reading this means that you have had 33 | knowledge of the CeCILL license and that you accept its terms. 34 | */ 35 | #ifdef __cplusplus 36 | extern "C" { 37 | #endif 38 | 39 | #ifndef _MCIMAGE_H 40 | #include 41 | #endif 42 | 43 | #define CARRE(i,j) ((i%2)+(j%2)==2) 44 | #define INTER(i,j) ((i%2)+(j%2)==1) 45 | #define INTERH(i,j) ((i%2)&&(!(j%2))) 46 | #define INTERV(i,j) ((!(i%2))&&(j%2)) 47 | #define SINGL(i,j) ((i%2)+(j%2)==0) 48 | #define DIM2D(i,j) ((i%2)+(j%2)) 49 | #define NDG_CARRE 255 50 | #define NDG_INTER 200 51 | #define NDG_SINGL 128 52 | #define GRS2D 3 53 | #define GCS2D 3 54 | 55 | #define VAL_NULLE 0 56 | #define VAL_OBJET 255 57 | #define VAL_MARQUE 1 58 | 59 | extern void InitPileGrilles2d(); 60 | extern void TerminePileGrilles2d(); 61 | extern struct xvimage * Khalimskize2d(struct xvimage *o); 62 | extern struct xvimage * KhalimskizeNDG2d(struct xvimage *o); 63 | extern struct xvimage * DeKhalimskize2d(struct xvimage *o); 64 | extern void Khalimskize2d_noalloc(struct xvimage *o, struct xvimage *k); 65 | extern void KhalimskizeNDG2d_noalloc(struct xvimage *o, struct xvimage *k); 66 | extern void DeKhalimskize2d_noalloc(struct xvimage *o, struct xvimage *r); 67 | extern void ndgmin2d(struct xvimage *k); 68 | extern void ndgminbeta2d(struct xvimage *k); 69 | extern void ndgmax2d(struct xvimage *k); 70 | extern void ndgmaxbeta2d(struct xvimage *k); 71 | extern void ndgmoy2d(struct xvimage *k); 72 | extern void ndg2grad2d(struct xvimage *k); 73 | extern void ndg4grad2d(struct xvimage *k); 74 | extern void Connex8Obj2d(struct xvimage *o); 75 | extern void Connex4Obj2d(struct xvimage *o); 76 | extern void Betapoint2d(index_t rs, index_t cs, index_t i, index_t j, index_t *tab, int32_t *n); 77 | extern void Alphapoint2d(index_t rs, index_t cs, index_t i, index_t j, index_t *tab, int32_t *n); 78 | extern void Betacarre2d(index_t rs, index_t cs, index_t i, index_t j, index_t *tab, int32_t *n); 79 | extern void Alphacarre2d(index_t rs, index_t cs, index_t i, index_t j, index_t *tab, int32_t *n); 80 | extern void Thetacarre2d(index_t rs, index_t cs, index_t i, index_t j, index_t *tab, int32_t *n); 81 | extern int32_t CardBetapoint2d(uint8_t *K, index_t rs, index_t cs, index_t i, index_t j); 82 | extern int32_t CardThetaCarre2d(struct xvimage *k, index_t i, index_t j, uint8_t val); 83 | extern int32_t BetaTerminal2d(uint8_t *K, index_t rs, index_t cs, index_t i, index_t j); 84 | extern int32_t ExactementUnBetaTerminal2d(uint8_t *K, index_t rs, index_t cs); 85 | extern void SatureAlphacarre2d(struct xvimage *k); 86 | extern void AjouteAlphacarre2d(struct xvimage *k); 87 | extern void AjouteBetacarre2d(struct xvimage *k); 88 | extern void MaxAlpha2d(struct xvimage *k); 89 | extern void MaxBeta2d(struct xvimage *k); 90 | extern void ColorieKh2d(struct xvimage *k); 91 | extern void EffaceLiensLibres2d(struct xvimage *k); 92 | extern void CopieAlphacarre2d(uint8_t *G,uint8_t *K,index_t rs,index_t cs,index_t i,index_t j); 93 | extern index_t EffaceBetaTerminauxSimples2d(struct xvimage *k); 94 | extern int32_t EnsembleSimple2d(struct xvimage *k); 95 | extern int32_t Ensemble2Contractile2d(struct xvimage *b); 96 | extern void Htkern2d(struct xvimage *b, int32_t n); 97 | extern int32_t AlphaSimple2d(struct xvimage *b, index_t i, index_t j); 98 | extern int32_t BetaSimple2d(struct xvimage *b, index_t i, index_t j); 99 | extern int32_t Alpha2Simple2d(struct xvimage *b, index_t i, index_t j); 100 | extern int32_t Beta2Simple2d(struct xvimage *b, index_t i, index_t j); 101 | extern index_t EulerKh2d(struct xvimage *b); 102 | extern int32_t FaceLibre2d(struct xvimage *b, index_t i, index_t j); 103 | extern int32_t PaireLibre2d(struct xvimage *b, index_t i, index_t j); 104 | extern int32_t Collapse2d(struct xvimage *b, index_t i, index_t j); 105 | #ifdef __cplusplus 106 | } 107 | #endif 108 | -------------------------------------------------------------------------------- /pink/decisionSegmentation.c: -------------------------------------------------------------------------------- 1 | /* 2 | author: Camille Couprie 3 | 13 aug. 2012 4 | */ 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | #define false 0 17 | #define true 1 18 | 19 | typedef struct max_elmt 20 | { float val; 21 | int index; 22 | } max_elmt; 23 | 24 | void maximum(float * f, int index_segment, int nb_classes, max_elmt * M) 25 | { 26 | int i; int index = 0; 27 | M->val = 0; 28 | for (i=0;i M->val ) 30 | { 31 | // fprintf(stderr,"hello=%f %d\n",f[index_segment*nb_classes+i],i); 32 | M->val = f[index_segment*nb_classes+i]; 33 | M->index = i; 34 | } 35 | } 36 | 37 | void maximumg(float * g, int index_pixel, int nb_classes, int N, max_elmt * M) 38 | { 39 | int i; int index = 0; //g[k*N+p] 40 | M->val = 0; 41 | for (i=0;i M->val ) 43 | { 44 | M->val = g[index_pixel + N*i]; 45 | M->index = i; 46 | } 47 | } 48 | 49 | 50 | float Intersect(float *S, int i1, int i2, int N) 51 | //returns intersection score between 2 segments 52 | { 53 | int i; 54 | float inter=0; float interS1 = 0;float interS2 = 0; 55 | for (i=0;iindex; 101 | max_scores[i] = M->val; 102 | } 103 | //for (i=0;it1) 122 | L[index_segments[i]]= true; 123 | } 124 | //6) For each pixel p in the image, compute pixel score g for each class k as 125 | // gk(p) = sum_{Si in L} (w_i 1(p in Si) fk(Si)) 126 | for (p=0;pvalindex+3; 148 | 149 | 150 | // 12) end if 13) end for 151 | } 152 | 153 | //14) if max_kj gk(pj) > t3 154 | 155 | //15) The score of the mask is given by the highest pixel score in the mask. 156 | //It must exceed threshold to be retained in the final semantic segmentation 157 | break; 158 | //16) end if 159 | 160 | //17) delete all segments L from S 161 | for (i=1;i 45 | #include 46 | #include 47 | #include 48 | #include 49 | 50 | /* ==================================== */ 51 | Lifo * CreeLifoVide(index_t taillemax) 52 | /* ==================================== */ 53 | { 54 | Lifo * L = (Lifo *)calloc(1,sizeof(Lifo) + sizeof(index_t) * (taillemax-1)); 55 | if (L == NULL) 56 | { 57 | #ifdef MC_64_BITS 58 | fprintf(stderr, "CreeLifoVide() : malloc failed : %lld bytes\n", sizeof(Lifo) + sizeof(index_t) * (taillemax-1)); 59 | #else 60 | fprintf(stderr, "CreeLifoVide() : malloc failed : %ld bytes\n", sizeof(Lifo) + sizeof(index_t) * (taillemax-1)); 61 | #endif 62 | return NULL; 63 | } 64 | L->Max = taillemax; 65 | L->Sp = 0; 66 | return L; 67 | } 68 | 69 | /* ==================================== */ 70 | void LifoFlush(Lifo * L) 71 | /* ==================================== */ 72 | { 73 | L->Sp = 0; 74 | } 75 | 76 | /* ==================================== */ 77 | index_t LifoVide(Lifo * L) 78 | /* ==================================== */ 79 | { 80 | return (L->Sp == 0); 81 | } 82 | 83 | /* ==================================== */ 84 | index_t LifoPop(Lifo * L) 85 | /* ==================================== */ 86 | { 87 | if (L->Sp == 0) 88 | { 89 | fprintf(stderr, "erreur Lifo vide\n"); 90 | exit(1); 91 | } 92 | L->Sp -= 1; 93 | return L->Pts[L->Sp]; 94 | } 95 | 96 | /* ==================================== */ 97 | index_t LifoHead(Lifo * L) 98 | /* ==================================== */ 99 | { 100 | if (L->Sp == 0) 101 | { 102 | fprintf(stderr, "erreur Lifo vide\n"); 103 | exit(1); 104 | } 105 | return L->Pts[L->Sp-1]; 106 | } 107 | 108 | /* ==================================== */ 109 | void LifoPush(Lifo * L, index_t V) 110 | /* ==================================== */ 111 | { 112 | if (L->Sp > L->Max - 1) 113 | { 114 | fprintf(stderr, "erreur Lifo pleine\n"); 115 | exit(1); 116 | } 117 | L->Pts[L->Sp] = V; 118 | L->Sp += 1; 119 | } 120 | 121 | /* ==================================== */ 122 | void LifoPrint(Lifo * L) 123 | /* ==================================== */ 124 | { 125 | index_t i; 126 | if (LifoVide(L)) {printf("[]"); return;} 127 | printf("[ "); 128 | for (i = 0; i < L->Sp; i++) 129 | #ifdef MC_64_BITS 130 | printf("%lld ", L->Pts[i]); 131 | #else 132 | printf("%d ", L->Pts[i]); 133 | #endif 134 | printf("]"); 135 | } 136 | 137 | /* ==================================== */ 138 | void LifoPrintLine(Lifo * L) 139 | /* ==================================== */ 140 | { 141 | index_t i; 142 | if (LifoVide(L)) {printf("[]\n"); return;} 143 | printf("[ "); 144 | for (i = 0; i < L->Sp; i++) 145 | #ifdef MC_64_BITS 146 | printf("%lld ", L->Pts[i]); 147 | #else 148 | printf("%d ", L->Pts[i]); 149 | #endif 150 | printf("]\n"); 151 | } 152 | 153 | /* ==================================== */ 154 | void LifoTermine(Lifo * L) 155 | /* ==================================== */ 156 | { 157 | free(L); 158 | } 159 | 160 | #ifdef TESTLifo 161 | void main() 162 | { 163 | Lifo * L = CreeLifoVide(3); 164 | LifoPrint(L); 165 | if (LifoVide(L)) printf("LifoVide OUI\n"); 166 | LifoPush(L,1); 167 | LifoPrint(L); 168 | if (!LifoVide(L)) printf("LifoVide NON\n"); 169 | LifoPush(L,2); 170 | LifoPrint(L); 171 | LifoPush(L,3); 172 | LifoPrint(L); 173 | printf("LifoPop %d attendu 3\n", LifoPop(L)); 174 | LifoPrint(L); 175 | LifoPush(L,4); 176 | LifoPrint(L); 177 | printf("LifoPop %d attendu 4\n", LifoPop(L)); 178 | LifoPrint(L); 179 | printf("LifoPop %d attendu 2\n", LifoPop(L)); 180 | LifoPrint(L); 181 | printf("LifoPop %d attendu 1\n", LifoPop(L)); 182 | LifoPrint(L); 183 | if (LifoVide(L)) printf("LifoVide OUI\n"); 184 | printf("maintenant sortie attendue sur lifo pleine :\n"); 185 | LifoPush(L,3); 186 | LifoPush(L,3); 187 | LifoPush(L,3); 188 | LifoPush(L,3); 189 | } 190 | #endif 191 | 192 | -------------------------------------------------------------------------------- /PWcut/powerwatershed.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Power watershed algorithm for Maximum Spanning Forest (MSF) computation 3 | implemented to compute an MSF cut in a tree (hierarchy) 4 | author: Camille Couprie 5 | 31 oct. 2011 6 | */ 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | #ifndef _MERGETREESTRUCT_ 18 | #define _MERGETREESTRUCT_ 19 | typedef struct { 20 | mtree *tree; 21 | RAG *rag; 22 | struct xvimage *labels; 23 | int32_t *altitudes; 24 | float *weights; 25 | int cs; 26 | int rs; 27 | } MergeTree; 28 | #endif 29 | 30 | 31 | #ifndef _LISTSTRUCT_ 32 | #define _LISTSTRUCT_ 33 | typedef struct list 34 | { 35 | int index; 36 | struct list *next; 37 | } list ; 38 | #endif 39 | 40 | 41 | /*================================================*/ 42 | void PrintList4(list *sl) 43 | /*================================================*/ 44 | { 45 | fprintf(stderr, "Nodes of the cut:\n"); 46 | while(sl) 47 | { 48 | printf("%d\n",sl->index); 49 | sl = sl->next; 50 | } 51 | } 52 | 53 | void Insert4(list **sl, int index); 54 | 55 | /*=====================================================================================*/ 56 | list * Powerwatershed(MergeTree * MT) 57 | /*=====================================================================================*/ 58 | /*Segment a tree into two components. 59 | Returns a list of nodes correspunding to the Max Spanning Forest cut, 60 | computed using Power watershed's algorithm */ 61 | { 62 | int y, i, j, tmp; 63 | int nb_markers; int nb_leafs; 64 | int N, M; 65 | float val=1; //weight parameter for leafs. 66 | 67 | // -------- Gathering usefull input graph (MT) informations ----------- 68 | 69 | mtree * T= MT->tree; 70 | float * W = MT->weights; 71 | JCctree *CT = T->CT; 72 | int root_node = CT->root; 73 | JCsoncell *s; 74 | 75 | //nb nodes 76 | M = CT->nbnodes; 77 | 78 | // nb_edges 79 | nb_leafs = 0; 80 | for (i = 0; i < M; i++) 81 | if (CT->tabnodes[i].nbsons == 0) 82 | nb_leafs++; 83 | 84 | nb_markers = nb_leafs+1; 85 | N=M+nb_markers; 86 | M=N-1; 87 | // printf("Nb nodes:%d Nb edges: %d Nb leafs :%d \n", N, M, nb_leafs); 88 | 89 | 90 | struct graph *G; 91 | G = (struct graph *)malloc(sizeof(struct graph)); 92 | G->weight_type=1; // 1:double 0:uint32_t 93 | 94 | Allocate_Graph(G, 95 | N,/*Number of nodes */ 96 | nb_markers, /*Max Number of seeded nodes */ 97 | M); /*Number of edges */ 98 | 99 | G->P = 1; /*we are solving one problem (multiple problems solved for multilabel segmentation)*/ 100 | 101 | /*Fill the seeds values */ 102 | G->S=nb_markers;/*there are nb_markers seeded nodes*/ 103 | G->SeededNodes[0]= M; 104 | G->Labels[0]=0; 105 | j=1; 106 | for (i = 0; i < CT->nbnodes; i++) 107 | if (CT->tabnodes[i].nbsons == 0) 108 | { 109 | G->SeededNodes[j]= i+CT->nbnodes; 110 | G->Labels[j]=1; 111 | j++; 112 | } 113 | // weights 114 | 115 | float * weights = (float *)malloc(N*sizeof(float)); 116 | for(i=0;inbnodes;i++) 117 | { 118 | weights[i]=W[i]; 119 | if (valnbnodes+i]=val; 123 | 124 | 125 | /*Add the weighted edges*/ 126 | for (i=0;inbnodes;i++) 127 | { 128 | tmp = CT->tabnodes[i].nbsons; 129 | if (tmp==0) //leaf 130 | { 131 | y= G->SeededNodes[i+1]; // edge index 132 | // fprintf(stderr,"%d edge (%d %d) %f \n", y, i,y, weights[y] ); 133 | AddEdge(G, i, y, weights[y],y/*edge index*/); 134 | 135 | } 136 | else 137 | { 138 | for ( s = CT->tabnodes[i].sonlist;s!=NULL;s = s->next) 139 | { 140 | y=s->son; 141 | // fprintf(stderr,"%d edge (%d %d) %f \n",y, i,y, weights[y] ); 142 | AddEdge(G, i, y, weights[y],y/*edge index*/); 143 | } 144 | } 145 | } 146 | AddEdge(G, root_node, M, weights[root_node],root_node/*edge index*/); 147 | 148 | G->max_weight= val; /*maximum weight value*/ 149 | 150 | /*Solving problem with Power Watersheds*/ 151 | 152 | PowerWatershed_q2(G); 153 | 154 | // Writing results 155 | // printf("SOLUTION \n"); 156 | for (j = 0; j < G->N; j++) 157 | { 158 | // printf("%f \n", G->Solution[0][j]); 159 | if (G->Solution[0][j]>0.5) G->Solution[0][j]=1; 160 | else G->Solution[0][j]=0; 161 | 162 | } 163 | 164 | // ------------------ Process the tree to find the cut ---------------------- 165 | list * cut = NULL; 166 | for (i = 0; i < CT->nbnodes; i++) 167 | { 168 | // nodes having a different value than their father are in the cut 169 | if ((CT->tabnodes[i].father != -1) && (fabs(G->Solution[0][CT->tabnodes[i].father] - G->Solution[0][i]))>0.01) 170 | Insert4(&cut, i); 171 | // leafs having the same label as the root are in the cut 172 | if ((CT->tabnodes[i].nbsons == 0) && (G->Solution[0][i]<0.5)) 173 | Insert4(&cut, i); 174 | } 175 | 176 | 177 | if (cut == NULL) Insert4(&cut, root_node); 178 | //PrintList4(cut); 179 | 180 | 181 | Free_Graph(G, G->N); 182 | 183 | return cut; 184 | 185 | 186 | 187 | } 188 | 189 | 190 | /*================================================*/ 191 | void Insert4(list **sl, int index) 192 | /*================================================*/ 193 | { 194 | list *tmp = NULL; 195 | list *csl = *sl; 196 | list *elem = (list*) malloc(sizeof(list)); 197 | if(!elem) exit(EXIT_FAILURE); 198 | elem->index = index; 199 | while(csl) 200 | { 201 | tmp = csl; 202 | csl = csl->next; 203 | } 204 | elem->next = csl; 205 | if(tmp) tmp->next = elem; 206 | else *sl = elem; 207 | } 208 | -------------------------------------------------------------------------------- /PWcut/MSF_RW.cpp: -------------------------------------------------------------------------------- 1 | /*Copyright ESIEE (2009) 2 | 3 | Author : 4 | Camille Couprie (c.couprie@esiee.fr) 5 | 6 | Contributors : 7 | Hugues Talbot (h.talbot@esiee.fr) 8 | Leo Grady (leo.grady@siemens.com) 9 | Laurent Najman (l.najman@esiee.fr) 10 | 11 | This software contains some image processing algorithms whose purpose is to be 12 | used primarily for research. 13 | 14 | This software is governed by the CeCILL license under French law and 15 | abiding by the rules of distribution of free software. You can use, 16 | modify and/ or redistribute the software under the terms of the CeCILL 17 | license as circulated by CEA, CNRS and INRIA at the following URL 18 | "http://www.cecill.info". 19 | 20 | As a counterpart to the access to the source code and rights to copy, 21 | modify and redistribute granted by the license, users are provided only 22 | with a limited warranty and the software's author, the holder of the 23 | economic rights, and the successive licensors have only limited 24 | liability. 25 | 26 | In this respect, the user's attention is drawn to the risks associated 27 | with loading, using, modifying and/or developing or reproducing the 28 | software by the user in light of its specific status of free software, 29 | that may mean that it is complicated to manipulate, and that also 30 | therefore means that it is reserved for developers and experienced 31 | professionals having in-depth computer knowledge. Users are therefore 32 | encouraged to load and test the software's suitability as regards their 33 | requirements in conditions enabling the security of their systems and/or 34 | data to be ensured and, more generally, to use and operate it in the 35 | same conditions as regards security. 36 | 37 | The fact that you are presently reading this means that you have had 38 | knowledge of the CeCILL license and that you accept its terms. 39 | */ 40 | 41 | /*! \file MSF_RW.c 42 | \brief Implements the power watershed algorithm with q=2 43 | \ingroup morpho 44 | 45 | \author Camille Couprie 46 | */ 47 | 48 | #include 49 | #include 50 | #include 51 | //#include 52 | //#include 53 | //#include 54 | //#include 55 | #include 56 | #include 57 | #include 58 | #include 59 | #include 60 | 61 | 62 | /*========================================================================================================*/ 63 | void memory_allocation_PW(Lifo ** LIFO, /* stack for plateau labeling */ 64 | Lifo ** LCP, /* list of the edges belonging to a plateau */ 65 | bool ** indic_E, /* indicator for edges */ 66 | bool ** indic_P, /* indicator for edges */ 67 | uint32_t ** indic_VP, /* indicator for nodes */ 68 | uint32_t ** Rnk, /* array needed for union-find efficiency */ 69 | uint32_t ** Fth, /* array for storing roots of merged nodes trees */ 70 | uint32_t ** local_seeds, /* array for storing the index of seeded nodes of a plateau */ 71 | uint32_t ** LCVP , /* list of vertices of a plateau */ 72 | uint32_t ** NEs, /* array of sorted edges according their weight */ 73 | int N, /* number of vertices */ 74 | int M) /* number of edges*/ 75 | /*==========================================================================================================*/ 76 | { 77 | #undef F_NAME 78 | #define F_NAME "memory_allocation_PW" 79 | 80 | *LIFO = CreeLifoVide(M); 81 | if (*LIFO == NULL) { fprintf(stderr, "%s : CreeLifoVide failed\n", F_NAME); exit(0); } 82 | 83 | *LCP = CreeLifoVide(M); 84 | if (*LCP == NULL) { fprintf(stderr, "%s : CreeLifoVide failed\n", F_NAME); exit(0); } 85 | 86 | *indic_E = (bool*)calloc(M ,sizeof(bool)); 87 | if (*indic_E == NULL) { fprintf(stderr, "%s: calloc indic_E failed\n", F_NAME); exit(0);} 88 | *indic_P = (bool*)calloc(M ,sizeof(bool)); 89 | if (*indic_P == NULL) { fprintf(stderr, "%s: calloc indic_P failed\n", F_NAME); exit(0);} 90 | *indic_VP = (uint32_t*)calloc(N ,sizeof(uint32_t)); 91 | if (*indic_VP == NULL) { fprintf(stderr, "%s: calloc indic_VP failed\n", F_NAME); exit(0);} 92 | *Rnk = (uint32_t*)calloc(N, sizeof(uint32_t)); 93 | if (*Rnk == NULL) { fprintf(stderr, "%s: malloc Rnk failed\n", F_NAME); exit(0);} 94 | *Fth = (uint32_t*)malloc(N*sizeof(uint32_t)); 95 | if (*Fth == NULL) { fprintf(stderr, "%s: malloc Fth failed\n", F_NAME); exit(0);} 96 | 97 | *local_seeds = (uint32_t*)malloc(N*sizeof(uint32_t)); 98 | if (local_seeds == NULL) { fprintf(stderr, "%s: malloc local_seeds failed\n", F_NAME); exit(0);} 99 | 100 | *LCVP = (uint32_t*)malloc(N*sizeof(uint32_t)); // vertices of a plateau. 101 | if (*LCVP == NULL) { fprintf(stderr, "%s: malloc LCVP failed\n", F_NAME); exit(0);} 102 | 103 | 104 | *NEs = ( uint32_t*)malloc(M*sizeof( uint32_t)); 105 | if (*NEs == NULL) { fprintf(stderr, "%s: malloc NEs failed\n", F_NAME); exit(0);} 106 | } 107 | 108 | 109 | 110 | /*===================================================================================*/ 111 | void merge_node (int e1, /* index of node 1 */ 112 | int e2, /* index of node 2 */ 113 | uint32_t *Rnk, /* array needed for union-find efficiency */ 114 | uint32_t *Fth, /* array for storing roots of merged nodes trees */ 115 | DBL_TYPE ** proba, /* array for storing the result x */ 116 | int nb_labels) /* nb of labels */ 117 | /*===================================================================================*/ 118 | /* update the result, Rnk and Fth arrays when 2 nodes are merged */ 119 | { 120 | int k,re1, re2; 121 | re1 = element_find(e1, Fth ); 122 | re2 = element_find(e2, Fth ); 123 | 124 | if ((re1 != re2) && (!(proba[0][re1]>=0 && proba[0][re2]>=0))) 125 | { 126 | element_link(re1,re2, Rnk, Fth); 127 | // printf("link %d %d \n", re1,re2); 128 | if (proba[0][re2]>=0 && proba[0][re1]<0) 129 | for(k=0;k=0 && proba[0][re2]<0) 132 | for(k=0;k 44 | #include 45 | #include 46 | #include 47 | #include 48 | #include 49 | 50 | /* ==================================== */ 51 | Fifo * CreeFifoVide( 52 | index_t taillemax) 53 | /* ==================================== */ 54 | { 55 | Fifo * L = (Fifo *)calloc(1,sizeof(Fifo) + sizeof(index_t) * taillemax); /* sic (+1) */ 56 | if (L == NULL) 57 | { 58 | #ifdef MC_64_BITS 59 | fprintf(stderr, "CreeFifoVide() : malloc failed : %lld bytes\n", sizeof(Fifo) + sizeof(index_t) * taillemax); 60 | #else 61 | fprintf(stderr, "CreeFifoVide() : malloc failed : %ld bytes\n", sizeof(Fifo) + sizeof(index_t) * taillemax); 62 | #endif 63 | return NULL; 64 | } 65 | L->Max = taillemax+1; 66 | L->In = 0; 67 | L->Out = 0; 68 | return L; 69 | } 70 | 71 | /* ==================================== */ 72 | void FifoFlush( 73 | Fifo * L) 74 | /* ==================================== */ 75 | { 76 | L->In = 0; 77 | L->Out = 0; 78 | } 79 | 80 | /* ==================================== */ 81 | int32_t FifoVide( 82 | Fifo * L) 83 | /* ==================================== */ 84 | { 85 | return (L->In == L->Out); 86 | } 87 | 88 | /* ==================================== */ 89 | index_t FifoPop( 90 | Fifo * L) 91 | /* ==================================== */ 92 | { 93 | index_t V; 94 | if (L->In == L->Out) 95 | { 96 | fprintf(stderr, "erreur fifo vide\n"); 97 | exit(1); 98 | } 99 | V = L->Pts[L->Out]; 100 | L->Out = (L->Out + 1) % L->Max; 101 | return V; 102 | } 103 | 104 | /* ==================================== */ 105 | void FifoPushFirst( 106 | Fifo * L, 107 | index_t V) 108 | /* ==================================== */ 109 | { 110 | L->Out = (L->Out - 1) % L->Max; 111 | L->Pts[L->Out] = V; 112 | if (L->In == L->Out) 113 | { 114 | fprintf(stderr, "erreur fifo pleine\n"); 115 | exit(1); 116 | } 117 | } 118 | 119 | /* ==================================== */ 120 | void FifoPush( 121 | Fifo * L, 122 | index_t V) 123 | /* ==================================== */ 124 | { 125 | L->Pts[L->In] = V; 126 | L->In = (L->In + 1) % L->Max; 127 | if (L->In == L->Out) 128 | { 129 | fprintf(stderr, "erreur fifo pleine\n"); 130 | exit(1); 131 | } 132 | } 133 | 134 | /* ==================================== */ 135 | void FifoPrint( 136 | Fifo * L) 137 | /* ==================================== */ 138 | { 139 | index_t i; 140 | if (FifoVide(L)) {printf("[]\n"); return;} 141 | #ifdef MC_64_BITS 142 | printf("Taille Fifo: %lld \n",FifoTaille(L)); 143 | #else 144 | printf("Taille Fifo: %d \n",FifoTaille(L)); 145 | #endif 146 | #ifdef MC_64_BITS 147 | printf("Max = %lld ; Out = %lld ; In = %lld\n", L->Max, L->Out, L->In); 148 | #else 149 | printf("Max = %d ; Out = %d ; In = %d\n", L->Max, L->Out, L->In); 150 | #endif 151 | printf("[ "); 152 | for (i = L->Out; i != L->In; i = (i+1) % L->Max) 153 | #ifdef MC_64_BITS 154 | printf("%lld ", L->Pts[i]); 155 | #else 156 | printf("%d ", L->Pts[i]); 157 | #endif 158 | printf("]\n"); 159 | } 160 | 161 | /* ==================================== */ 162 | void FifoTermine( 163 | Fifo * L) 164 | /* ==================================== */ 165 | { 166 | free(L); 167 | } 168 | 169 | /* ==================================== */ 170 | index_t FifoTaille( 171 | Fifo * L) 172 | /* ==================================== */ 173 | { 174 | if (L->In < L->Out) 175 | return (L->Max - (L->Out-L->In)); 176 | else 177 | return (L->In - L->Out); 178 | } 179 | 180 | #ifdef TESTFIFO 181 | void main() 182 | { 183 | Fifo * L = CreeFifoVide(3); 184 | FifoPrint(L); 185 | if (FifoVide(L)) printf("FifoVide OUI\n"); 186 | FifoPush(L,1); 187 | FifoPrint(L); 188 | if (!FifoVide(L)) printf("FifoVide NON\n"); 189 | FifoPush(L,2); 190 | FifoPrint(L); 191 | FifoPush(L,3); 192 | FifoPrint(L); 193 | printf("FifoPop %d attendu 1\n", FifoPop(L)); 194 | FifoPrint(L); 195 | FifoPushFirst(L,225); 196 | FifoPrint(L); 197 | printf("FifoPop %d attendu par christophe 225\n", FifoPop(L)); 198 | FifoPrint(L); 199 | FifoPush(L,4); 200 | FifoPrint(L); 201 | printf("FifoPop %d attendu 2\n", FifoPop(L)); 202 | FifoPrint(L); 203 | printf("FifoPop %d attendu 3\n", FifoPop(L)); 204 | FifoPrint(L); 205 | printf("FifoPop %d attendu 4\n", FifoPop(L)); 206 | FifoPrint(L); 207 | if (FifoVide(L)) printf("FifoVide OUI\n"); 208 | } 209 | #endif 210 | 211 | 212 | -------------------------------------------------------------------------------- /pink/mtrand64.c: -------------------------------------------------------------------------------- 1 | /* 2 | A C-program for MT19937-64 (2004/9/29 version). 3 | Coded by Takuji Nishimura and Makoto Matsumoto. 4 | 5 | This is a 64-bit version of Mersenne Twister pseudorandom number 6 | generator. 7 | 8 | Before using, initialize the state by using init_genrand64(seed) 9 | or init_by_array64(init_key, key_length). 10 | 11 | Copyright (C) 2004, Makoto Matsumoto and Takuji Nishimura, 12 | All rights reserved. 13 | 14 | Redistribution and use in source and binary forms, with or without 15 | modification, are permitted provided that the following conditions 16 | are met: 17 | 18 | 1. Redistributions of source code must retain the above copyright 19 | notice, this list of conditions and the following disclaimer. 20 | 21 | 2. Redistributions in binary form must reproduce the above copyright 22 | notice, this list of conditions and the following disclaimer in the 23 | documentation and/or other materials provided with the distribution. 24 | 25 | 3. The names of its contributors may not be used to endorse or promote 26 | products derived from this software without specific prior written 27 | permission. 28 | 29 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 30 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 31 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 32 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 33 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 34 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 35 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 36 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 37 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 38 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 39 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 40 | 41 | References: 42 | T. Nishimura, ``Tables of 64-bit Mersenne Twisters'' 43 | ACM Transactions on Modeling and 44 | Computer Simulation 10. (2000) 348--357. 45 | M. Matsumoto and T. Nishimura, 46 | ``Mersenne Twister: a 623-dimensionally equidistributed 47 | uniform pseudorandom number generator'' 48 | ACM Transactions on Modeling and 49 | Computer Simulation 8. (Jan. 1998) 3--30. 50 | 51 | Any feedback is very welcome. 52 | http://www.math.hiroshima-u.ac.jp/~m-mat/MT/emt.html 53 | email: m-mat @ math.sci.hiroshima-u.ac.jp (remove spaces) 54 | */ 55 | 56 | 57 | #include 58 | #include "mtrand64.h" 59 | 60 | #define NN 312 61 | #define MM 156 62 | #define MATRIX_A 0xB5026F5AA96619E9ULL 63 | #define UM 0xFFFFFFFF80000000ULL /* Most significant 33 bits */ 64 | #define LM 0x7FFFFFFFULL /* Least significant 31 bits */ 65 | 66 | 67 | /* The array for the state vector */ 68 | static unsigned long long mt[NN]; 69 | /* mti==NN+1 means mt[NN] is not initialized */ 70 | static int mti=NN+1; 71 | 72 | /* initializes mt[NN] with a seed */ 73 | void init_genrand64(unsigned long long seed) 74 | { 75 | mt[0] = seed; 76 | for (mti=1; mti> 62)) + mti); 78 | } 79 | 80 | /* initialize by an array with array-length */ 81 | /* init_key is the array for initializing keys */ 82 | /* key_length is its length */ 83 | void init_by_array64(unsigned long long init_key[], 84 | unsigned long long key_length) 85 | { 86 | unsigned long long i, j, k; 87 | init_genrand64(19650218ULL); 88 | i=1; j=0; 89 | k = (NN>key_length ? NN : key_length); 90 | for (; k; k--) { 91 | mt[i] = (mt[i] ^ ((mt[i-1] ^ (mt[i-1] >> 62)) * 3935559000370003845ULL)) 92 | + init_key[j] + j; /* non linear */ 93 | i++; j++; 94 | if (i>=NN) { mt[0] = mt[NN-1]; i=1; } 95 | if (j>=key_length) j=0; 96 | } 97 | for (k=NN-1; k; k--) { 98 | mt[i] = (mt[i] ^ ((mt[i-1] ^ (mt[i-1] >> 62)) * 2862933555777941757ULL)) 99 | - i; /* non linear */ 100 | i++; 101 | if (i>=NN) { mt[0] = mt[NN-1]; i=1; } 102 | } 103 | 104 | mt[0] = 1ULL << 63; /* MSB is 1; assuring non-zero initial array */ 105 | } 106 | 107 | /* generates a random number on [0, 2^64-1]-interval */ 108 | unsigned long long genrand64_int64(void) 109 | { 110 | int i; 111 | unsigned long long x; 112 | static unsigned long long mag01[2]={0ULL, MATRIX_A}; 113 | 114 | if (mti >= NN) { /* generate NN words at one time */ 115 | 116 | /* if init_genrand64() has not been called, */ 117 | /* a default initial seed is used */ 118 | if (mti == NN+1) 119 | init_genrand64(5489ULL); 120 | 121 | for (i=0;i>1) ^ mag01[(int)(x&1ULL)]; 124 | } 125 | for (;i>1) ^ mag01[(int)(x&1ULL)]; 128 | } 129 | x = (mt[NN-1]&UM)|(mt[0]&LM); 130 | mt[NN-1] = mt[MM-1] ^ (x>>1) ^ mag01[(int)(x&1ULL)]; 131 | 132 | mti = 0; 133 | } 134 | 135 | x = mt[mti++]; 136 | 137 | x ^= (x >> 29) & 0x5555555555555555ULL; 138 | x ^= (x << 17) & 0x71D67FFFEDA60000ULL; 139 | x ^= (x << 37) & 0xFFF7EEE000000000ULL; 140 | x ^= (x >> 43); 141 | 142 | return x; 143 | } 144 | 145 | /* generates a random number on [0, 2^63-1]-interval */ 146 | long long genrand64_int63(void) 147 | { 148 | return (long long)(genrand64_int64() >> 1); 149 | } 150 | 151 | /* generates a random number on [0,1]-real-interval */ 152 | double genrand64_real1(void) 153 | { 154 | return (genrand64_int64() >> 11) * (1.0/9007199254740991.0); 155 | } 156 | 157 | /* generates a random number on [0,1)-real-interval */ 158 | double genrand64_real2(void) 159 | { 160 | return (genrand64_int64() >> 11) * (1.0/9007199254740992.0); 161 | } 162 | 163 | /* generates a random number on (0,1)-real-interval */ 164 | double genrand64_real3(void) 165 | { 166 | return ((genrand64_int64() >> 12) + 0.5) * (1.0/4503599627370496.0); 167 | } 168 | -------------------------------------------------------------------------------- /PWcut/gageodesic.h: -------------------------------------------------------------------------------- 1 | /*Copyright ESIEE (2009) 2 | 3 | Author : 4 | Camille Couprie (c.couprie@esiee.fr) 5 | 6 | Contributors : 7 | Hugues Talbot (h.talbot@esiee.fr) 8 | Leo Grady (leo.grady@siemens.com) 9 | Laurent Najman (l.najman@esiee.fr) 10 | 11 | This software contains some image processing algorithms whose purpose is to be 12 | used primarily for research. 13 | 14 | This software is governed by the CeCILL license under French law and 15 | abiding by the rules of distribution of free software. You can use, 16 | modify and/ or redistribute the software under the terms of the CeCILL 17 | license as circulated by CEA, CNRS and INRIA at the following URL 18 | "http://www.cecill.info". 19 | 20 | As a counterpart to the access to the source code and rights to copy, 21 | modify and redistribute granted by the license, users are provided only 22 | with a limited warranty and the software's author, the holder of the 23 | economic rights, and the successive licensors have only limited 24 | liability. 25 | 26 | In this respect, the user's attention is drawn to the risks associated 27 | with loading, using, modifying and/or developing or reproducing the 28 | software by the user in light of its specific status of free software, 29 | that may mean that it is complicated to manipulate, and that also 30 | therefore means that it is reserved for developers and experienced 31 | professionals having in-depth computer knowledge. Users are therefore 32 | encouraged to load and test the software's suitability as regards their 33 | requirements in conditions enabling the security of their systems and/or 34 | data to be ensured and, more generally, to use and operate it in the 35 | same conditions as regards security. 36 | 37 | The fact that you are presently reading this means that you have had 38 | knowledge of the CeCILL license and that you accept its terms. 39 | */ 40 | 41 | #ifndef GA_GEODESIC_H 42 | #define GA_GEODESIC_H 43 | 44 | #include 45 | #include 46 | #include 47 | #include 48 | #include 49 | 50 | 51 | /*===========================================================*/ 52 | template void element_link_geod_dilate( int n, 53 | int p, 54 | uint32_t *Fth, 55 | wtype *G, 56 | wtype *O, 57 | wtype MAX) 58 | /*============================================================*/ 59 | { 60 | int r = element_find(n, Fth); 61 | 62 | if (r != p) 63 | { 64 | if((G[r] == G[p])||(G[p]>=O[r])) 65 | { 66 | Fth[r] = p; 67 | //O[p] = max(O[r],O[p]); 68 | if(O[r]>O[p])O[p] = O[r]; 69 | } 70 | else O[p] = MAX; 71 | } 72 | } 73 | 74 | /* ==================================================================================================== */ 75 | template void geodilate_union_find( wtype *H, /* h : image weights */ 76 | wtype *O, /* f : image seeds O : 77 | result of the reconstruction by dilation of h under f */ 78 | struct graph *G, 79 | wtype max_weight) 80 | 81 | 82 | /* ===================================================================================================== */ 83 | /* reconstruction by dilation of h under f. Union-find method described by Luc Vicent. */ 84 | { 85 | int k, p, n, e_jp; 86 | bool * Mrk = (bool*)calloc(G->M,sizeof(bool)); 87 | uint32_t * Fth = (uint32_t*)malloc(G->M*sizeof(uint32_t)); 88 | uint32_t * Es = (uint32_t*)malloc(G->M*sizeof(uint32_t)); 89 | wtype *W = (wtype*)malloc(G->M*sizeof(wtype)); 90 | TypListechainee * lis; 91 | 92 | for(k=0;kM;k++) 93 | { 94 | Fth[k]=k; 95 | Es[k]=k; 96 | W[k]=G->Weights[k]; 97 | } 98 | int t1, t2,t3; 99 | t1=clock(); 100 | 101 | // Sort values of F 102 | // if (G->weight_type==0) 103 | // Es = linsortimageup(H, G->M, max_weight+1); 104 | //else 105 | TriRapideStochastique_inc(H, Es, 0, G->M-1); 106 | for(k=0;kM;k++) 107 | G->Weights[k]=W[k]; 108 | //int i;for(i=0;iM;i++) fprintf(stderr,"%d %d %f\n" , i, Es[i], H[i] ); 109 | int r; 110 | t2=clock(); 111 | // fprintf(stderr, "sort : %.6lf seconds elapsed\n", ((double)t2-t1)/CLOCKS_PER_SEC); 112 | /* first pass */ 113 | for(k=G->M-1;k>=0;k--) 114 | { 115 | p = Es[k]; 116 | 117 | // parcourt les 4 premiers voisins de p 118 | e_jp = G->Edges[0][p]; 119 | // printf("edge %d, node %d \n neigh. edges", p, e_jp); 120 | 121 | for (lis=G->Neighbors[e_jp]; lis != NULL; lis = lis->suite) 122 | { 123 | n= lis->elt; 124 | // printf(" %d ", n); 125 | if(Mrk[n]==true) 126 | { 127 | /* element_link_geod_dilate(n,p, Fth,H, O, max_weight); */ 128 | r = element_find(n, Fth); 129 | 130 | if (r != p) 131 | { 132 | if((abs(H[r] - H[p])<0.00001)||(H[p]>=O[r])) 133 | { 134 | Fth[r] = p; 135 | if(O[r]>O[p])O[p] = O[r]; 136 | } 137 | else O[p] = max_weight; 138 | } 139 | } 140 | Mrk[p]=true; 141 | } 142 | // printf("\n"); 143 | 144 | 145 | 146 | // parcourt les 4 derniers voisins de p 147 | e_jp = G->Edges[1][p]; 148 | 149 | for (lis=G->Neighbors[e_jp]; lis != NULL; lis = lis->suite) 150 | { 151 | n= lis->elt; 152 | if(Mrk[n]==true) 153 | { 154 | /* element_link_geod_dilate(n,p, Fth,H, O, max_weight); */ 155 | //r = element_find_iteratif(n, Fth ); 156 | r = element_find(n, Fth); 157 | 158 | if (r != p) 159 | { 160 | if((H[r] == H[p])||(H[p]>=O[r])) 161 | { 162 | Fth[r] = p; 163 | if(O[r]>O[p])O[p] = O[r]; 164 | } 165 | else O[p] = max_weight; 166 | } 167 | } 168 | } 169 | 170 | } 171 | free(Mrk); 172 | t3=clock(); 173 | // fprintf(stderr, "Premiere passe reconstruction : %.6lf seconds elapsed\n", ((double)t3-t2)/CLOCKS_PER_SEC); 174 | /* second pass */ 175 | 176 | for(k=0;kM;k++) 177 | { 178 | p = Es[k]; 179 | if (Fth[p]==(uint32_t)p) // p is root 180 | { 181 | if (O[p]==max_weight) O[p]=H[p]; 182 | } 183 | else O[p]= O[Fth[p]]; 184 | } 185 | t1=clock(); 186 | // fprintf(stderr, "Deuxieme passe reconstruction : %.6lf seconds elapsed\n", ((double)t1-t3)/CLOCKS_PER_SEC); 187 | free(Es); 188 | free(Fth); 189 | 190 | free(W); 191 | 192 | } 193 | 194 | #endif 195 | -------------------------------------------------------------------------------- /PWcut/cs.h: -------------------------------------------------------------------------------- 1 | #ifndef _CS_H 2 | #define _CS_H 3 | #include 4 | #include 5 | #include 6 | #include 7 | #ifdef MATLAB_MEX_FILE 8 | #include "mex.h" 9 | #endif 10 | #define CS_VER 2 /* CSparse Version 2.2.3 */ 11 | #define CS_SUBVER 2 12 | #define CS_SUBSUB 3 13 | #define CS_DATE "Jan 20, 2009" /* CSparse release date */ 14 | #define CS_COPYRIGHT "Copyright (c) Timothy A. Davis, 2006-2009" 15 | 16 | /* --- primary CSparse routines and data structures ------------------------- */ 17 | typedef struct cs_sparse /* matrix in compressed-column or triplet form */ 18 | { 19 | int nzmax ; /* maximum number of entries */ 20 | int m ; /* number of rows */ 21 | int n ; /* number of columns */ 22 | int *p ; /* column pointers (size n+1) or col indices (size nzmax) */ 23 | int *i ; /* row indices, size nzmax */ 24 | double *x ; /* numerical values, size nzmax */ 25 | int nz ; /* # of entries in triplet matrix, -1 for compressed-col */ 26 | } cs ; 27 | 28 | cs *cs_add (const cs *A, const cs *B, double alpha, double beta) ; 29 | int cs_cholsol (int order, const cs *A, double *b) ; 30 | cs *cs_compress (const cs *T) ; 31 | int cs_dupl (cs *A) ; 32 | int cs_entry (cs *T, int i, int j, double x) ; 33 | int cs_gaxpy (const cs *A, const double *x, double *y) ; 34 | cs *cs_load (FILE *f) ; 35 | int cs_lusol (int order, const cs *A, double *b, double tol) ; 36 | cs *cs_multiply (const cs *A, const cs *B) ; 37 | double cs_norm (const cs *A) ; 38 | int cs_print (const cs *A, int brief) ; 39 | int cs_qrsol (int order, const cs *A, double *b) ; 40 | cs *cs_transpose (const cs *A, int values) ; 41 | /* utilities */ 42 | void *cs_calloc (int n, size_t size) ; 43 | void *cs_free (void *p) ; 44 | void *cs_realloc (void *p, int n, size_t size, int *ok) ; 45 | cs *cs_spalloc (int m, int n, int nzmax, int values, int triplet) ; 46 | cs *cs_spfree (cs *A) ; 47 | int cs_sprealloc (cs *A, int nzmax) ; 48 | void *cs_malloc (int n, size_t size) ; 49 | 50 | /* --- secondary CSparse routines and data structures ----------------------- */ 51 | typedef struct cs_symbolic /* symbolic Cholesky, LU, or QR analysis */ 52 | { 53 | int *pinv ; /* inverse row perm. for QR, fill red. perm for Chol */ 54 | int *q ; /* fill-reducing column permutation for LU and QR */ 55 | int *parent ; /* elimination tree for Cholesky and QR */ 56 | int *cp ; /* column pointers for Cholesky, row counts for QR */ 57 | int *leftmost ; /* leftmost[i] = min(find(A(i,:))), for QR */ 58 | int m2 ; /* # of rows for QR, after adding fictitious rows */ 59 | double lnz ; /* # entries in L for LU or Cholesky; in V for QR */ 60 | double unz ; /* # entries in U for LU; in R for QR */ 61 | } css ; 62 | 63 | typedef struct cs_numeric /* numeric Cholesky, LU, or QR factorization */ 64 | { 65 | cs *L ; /* L for LU and Cholesky, V for QR */ 66 | cs *U ; /* U for LU, R for QR, not used for Cholesky */ 67 | int *pinv ; /* partial pivoting for LU */ 68 | double *B ; /* beta [0..n-1] for QR */ 69 | } csn ; 70 | 71 | typedef struct cs_dmperm_results /* cs_dmperm or cs_scc output */ 72 | { 73 | int *p ; /* size m, row permutation */ 74 | int *q ; /* size n, column permutation */ 75 | int *r ; /* size nb+1, block k is rows r[k] to r[k+1]-1 in A(p,q) */ 76 | int *s ; /* size nb+1, block k is cols s[k] to s[k+1]-1 in A(p,q) */ 77 | int nb ; /* # of blocks in fine dmperm decomposition */ 78 | int rr [5] ; /* coarse row decomposition */ 79 | int cc [5] ; /* coarse column decomposition */ 80 | } csd ; 81 | 82 | int *cs_amd (int order, const cs *A) ; 83 | csn *cs_chol (const cs *A, const css *S) ; 84 | csd *cs_dmperm (const cs *A, int seed) ; 85 | int cs_droptol (cs *A, double tol) ; 86 | int cs_dropzeros (cs *A) ; 87 | int cs_happly (const cs *V, int i, double beta, double *x) ; 88 | int cs_ipvec (const int *p, const double *b, double *x, int n) ; 89 | int cs_lsolve (const cs *L, double *x) ; 90 | int cs_ltsolve (const cs *L, double *x) ; 91 | csn *cs_lu (const cs *A, const css *S, double tol) ; 92 | cs *cs_permute (const cs *A, const int *pinv, const int *q, int values) ; 93 | int *cs_pinv (const int *p, int n) ; 94 | int cs_pvec (const int *p, const double *b, double *x, int n) ; 95 | csn *cs_qr (const cs *A, const css *S) ; 96 | css *cs_schol (int order, const cs *A) ; 97 | css *cs_sqr (int order, const cs *A, int qr) ; 98 | cs *cs_symperm (const cs *A, const int *pinv, int values) ; 99 | int cs_updown (cs *L, int sigma, const cs *C, const int *parent) ; 100 | int cs_usolve (const cs *U, double *x) ; 101 | int cs_utsolve (const cs *U, double *x) ; 102 | /* utilities */ 103 | css *cs_sfree (css *S) ; 104 | csn *cs_nfree (csn *N) ; 105 | csd *cs_dfree (csd *D) ; 106 | 107 | /* --- tertiary CSparse routines -------------------------------------------- */ 108 | int *cs_counts (const cs *A, const int *parent, const int *post, int ata) ; 109 | double cs_cumsum (int *p, int *c, int n) ; 110 | int cs_dfs (int j, cs *G, int top, int *xi, int *pstack, const int *pinv) ; 111 | int cs_ereach (const cs *A, int k, const int *parent, int *s, int *w) ; 112 | int *cs_etree (const cs *A, int ata) ; 113 | int cs_fkeep (cs *A, int (*fkeep) (int, int, double, void *), void *other) ; 114 | double cs_house (double *x, double *beta, int n) ; 115 | int cs_leaf (int i, int j, const int *first, int *maxfirst, int *prevleaf, 116 | int *ancestor, int *jleaf) ; 117 | int *cs_maxtrans (const cs *A, int seed) ; 118 | int *cs_post (const int *parent, int n) ; 119 | int *cs_randperm (int n, int seed) ; 120 | int cs_reach (cs *G, const cs *B, int k, int *xi, const int *pinv) ; 121 | int cs_scatter (const cs *A, int j, double beta, int *w, double *x, int mark, 122 | cs *C, int nz) ; 123 | csd *cs_scc (cs *A) ; 124 | int cs_spsolve (cs *G, const cs *B, int k, int *xi, double *x, 125 | const int *pinv, int lo) ; 126 | int cs_tdfs (int j, int k, int *head, const int *next, int *post, 127 | int *stack) ; 128 | /* utilities */ 129 | csd *cs_dalloc (int m, int n) ; 130 | csd *cs_ddone (csd *D, cs *C, void *w, int ok) ; 131 | cs *cs_done (cs *C, void *w, void *x, int ok) ; 132 | int *cs_idone (int *p, cs *C, void *w, int ok) ; 133 | csn *cs_ndone (csn *N, cs *C, void *w, void *x, int ok) ; 134 | 135 | #define CS_MAX(a,b) (((a) > (b)) ? (a) : (b)) 136 | #define CS_MIN(a,b) (((a) < (b)) ? (a) : (b)) 137 | #define CS_FLIP(i) (-(i)-2) 138 | #define CS_UNFLIP(i) (((i) < 0) ? CS_FLIP(i) : (i)) 139 | #define CS_MARKED(w,j) (w [j] < 0) 140 | #define CS_MARK(w,j) { w [j] = CS_FLIP (w [j]) ; } 141 | #define CS_CSC(A) (A && (A->nz == -1)) 142 | #define CS_TRIPLET(A) (A && (A->nz >= 0)) 143 | #endif 144 | -------------------------------------------------------------------------------- /pink/prim.c: -------------------------------------------------------------------------------- 1 | /* 2 | Prim's algorithm for Maximum Spanning Forest (MSF) computation 3 | implemented to compute an MSF cut in a tree (hierarchy) 4 | author: Camille Couprie 5 | 21 oct. 2011 6 | */ 7 | 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include "MSF_utils.h" 21 | #include 22 | 23 | #define false 0 24 | #define true 1 25 | #define minimum(X,Y) ((X)<=(Y)?(X):(Y)) 26 | #define maximum(X,Y) ((X)>=(Y)?(X):(Y)) 27 | 28 | void Insert3(list **sl, int index); 29 | 30 | /*=====================================================================================*/ 31 | list * MSF_Prim(MergeTree * MT) 32 | /*=====================================================================================*/ 33 | /*Segment a tree into two components. 34 | Returns a list of nodes correspunding to the Max Spanning Forest cut, 35 | computed using Prim's algorithm */ 36 | { 37 | int32_t i, j,u,v, x,y,z, x_1,y_1; 38 | int nb_markers; int nb_leafs; 39 | long N, M; 40 | 41 | // -------- Gathering usefull input graph (MT) informations ----------- 42 | 43 | float val=0; //weight parameter for leafs. 44 | mtree * T= MT->tree; // mergeTreePrint(T); 45 | float * W = MT->weights; 46 | JCctree *CT = T->CT; 47 | int root_node = CT->root; 48 | 49 | //M = nb nodes 50 | M = CT->nbnodes; 51 | 52 | //N = nb_edges 53 | nb_leafs = 0; 54 | for (i = 0; i < M; i++) 55 | if (CT->tabnodes[i].nbsons == 0) 56 | nb_leafs++; 57 | 58 | nb_markers = nb_leafs+1; 59 | N=M+nb_markers; 60 | M=N-1; 61 | 62 | 63 | //init Prim 64 | //Creates a Red-Black tree to sort edges 65 | Rbt *L; 66 | IndicsInit(M); 67 | L = mcrbt_CreeRbtVide(M); 68 | i=0; 69 | int sizeL = 0; 70 | 71 | // Set for already checked edges 72 | for(u = 0; u < M; u ++) 73 | Set(u, false); 74 | 75 | // marked nodes 76 | uint32_t * SeededNodes = (uint32_t*)malloc(nb_markers*sizeof(uint32_t)); 77 | if (SeededNodes == NULL) { fprintf(stderr, "prim : malloc failed\n"); exit(0);} 78 | 79 | // Resulting node labeling goes into G2 80 | uint8_t * G2 = (uint8_t*)calloc(N ,sizeof(uint8_t)); 81 | 82 | // fill the array SeededNodes with marked index nodes 83 | // fill the tree L only with the marked edges 84 | SeededNodes[0]= M; 85 | j=1; 86 | for (i = 0; i < CT->nbnodes; i++) 87 | if (CT->tabnodes[i].nbsons == 0) 88 | { 89 | SeededNodes[j]= i+CT->nbnodes; 90 | G2[SeededNodes[j]] = 2; 91 | mcrbt_RbtInsert(&L, (TypRbtKey)(val), SeededNodes[j]); 92 | sizeL++; 93 | // fprintf(stderr,"L=%d", sizeL); 94 | Set(SeededNodes[j], true); 95 | j++; 96 | } 97 | G2[root_node]=1; 98 | mcrbt_RbtInsert(&L, (TypRbtKey)(1-W[root_node]), root_node); 99 | sizeL++; 100 | Set(root_node, true); 101 | 102 | // weights 103 | float * Weights = (float *)malloc(M*sizeof(float)); 104 | for(j=0;jnbnodes;j++) 105 | Weights[j]=W[j]; 106 | 107 | for(j=0;jnbnodes+j]=val; 109 | 110 | // While there exists unprocessed nodes 111 | while(sizeL != 0) 112 | { 113 | //Pick an edge u of min weight in the tree. 114 | u = RbtPopMin(L); // fprintf(stderr, "pop %d\n", u); 115 | sizeL--; 116 | // Find its extreme nodes (x,y) 117 | x = u; // x = G->Edges[0][u]; 118 | if (unbnodes) y= CT->tabnodes[u].father; 119 | else if(u!=M) y= u-CT->nbnodes; 120 | else y=root_node; 121 | if (y==-1)y=M; //y = G->Edges[1][u]; 122 | 123 | // y must correspond to the marked node. 124 | if(G2[x] > G2[y]) 125 | {z=x; x=y; y=z;} 126 | 127 | // if one node is labeled 128 | if((minimum(G2[x],G2[y]) == 0) && (maximum(G2[x],G2[y]) > 0)) 129 | { 130 | // assign the same label to the other one 131 | G2[x] = G2[y]; 132 | //fprintf(stderr,"Map[%d]=Map[%d]\n",x,y); 133 | 134 | // select neighbors edges to place them in the tree 135 | j= nb_neighbors(u, CT, nb_leafs); 136 | //fprintf(stderr,"nb_neigbors= %d \n",j); 137 | for (i=0;inbnodes) y_1= CT->tabnodes[v].father; 149 | else if(v!=M) y_1= v-CT->nbnodes; 150 | else y_1 = root_node; 151 | if (y_1==-1)y_1=M; 152 | //fprintf(stderr," [%d %d] ",x_1, y_1); 153 | if((minimum(G2[x_1],G2[y_1]) == 0) && (maximum(G2[x_1],G2[y_1]) > 0)) 154 | { 155 | //fprintf(stderr,"( insert %d) ",v); 156 | mcrbt_RbtInsert(&L, (TypRbtKey)(1-Weights[v]), v); 157 | sizeL++; 158 | Set(v,true); 159 | } 160 | } 161 | } 162 | // fprintf(stderr," \n"); 163 | } 164 | UnSet(u,true); 165 | } 166 | 167 | /* for (i=0; inbnodes; i++) 173 | { 174 | // nodes having a different value than their father are in the cut 175 | if ((CT->tabnodes[i].father != -1) && (G2[CT->tabnodes[i].father] != G2[i])) 176 | Insert3(&cut, i); 177 | // leafs having the same label as the root are in the cut 178 | if ((CT->tabnodes[i].nbsons == 0) && (G2[i]-1==0)) 179 | Insert3(&cut, i); 180 | } 181 | 182 | if (cut == NULL) Insert3(&cut, root_node); 183 | 184 | // PrintList(cut); 185 | IndicsTermine(); 186 | free(G2); 187 | mcrbt_RbtTermine(L); 188 | free(SeededNodes); 189 | free(Weights); 190 | return cut; 191 | 192 | } 193 | 194 | 195 | 196 | /*================================================*/ 197 | void Insert3(list **sl, int index) 198 | /*================================================*/ 199 | { 200 | list *tmp = NULL; 201 | list *csl = *sl; 202 | list *elem = (list*) malloc(sizeof(list)); 203 | if(!elem) exit(EXIT_FAILURE); 204 | elem->index = index; 205 | while(csl) 206 | { 207 | tmp = csl; 208 | csl = csl->next; 209 | } 210 | elem->next = csl; 211 | if(tmp) tmp->next = elem; 212 | else *sl = elem; 213 | } 214 | -------------------------------------------------------------------------------- /pink/kruskal.c: -------------------------------------------------------------------------------- 1 | /* 2 | Kruskal algorithm for Maximum Spanning Forest (MSF) computation 3 | implemented to compute an MSF cut in a tree (hierarchy) 4 | author: Camille Couprie 5 | 21 oct. 2011 6 | */ 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | 23 | #define false 0 24 | #define true 1 25 | void Insert2(list **sl, int index); 26 | 27 | /*=====================================================================================*/ 28 | list * MSF_Kruskal(MergeTree * MT) 29 | /*=====================================================================================*/ 30 | /*Segment a tree into two components. 31 | Returns a list of nodes correspunding to the Max Spanning Forest cut, 32 | computed using Kruskal's algorithm */ 33 | { 34 | int i, j, k, x, y, e1, e2; 35 | int nb_markers; int nb_leafs; 36 | long N, M; 37 | 38 | // -------- Gathering usefull input graph (MT) informations ----------- 39 | 40 | float val=1; //weight parameter for leafs. 41 | mtree * T= MT->tree; 42 | float * W = MT->weights; 43 | // mergeTreePrint(T); 44 | JCctree *CT = T->CT; 45 | int root_node = CT->root; 46 | 47 | //nb nodes 48 | M = CT->nbnodes; 49 | 50 | // nb_edges 51 | nb_leafs = 0; 52 | for (i = 0; i < M; i++) 53 | if (CT->tabnodes[i].nbsons == 0) 54 | nb_leafs++; 55 | 56 | nb_markers = nb_leafs+1; 57 | N=M+nb_markers; 58 | M=N-1; 59 | //printf("Nb nodes:%d Nb edges: %d Nb leafs :%d \n", N, M, nb_leafs); 60 | 61 | // indexes of edges : son's nodes indexes 62 | //Memory allocation of temporary arrays for Krukal's algorithm 63 | Lifo * LIFO; 64 | LIFO = CreeLifoVide(M); 65 | if (LIFO == NULL) { fprintf(stderr, "kruskal : CreeLifoVide failed\n"); exit(0); } 66 | 67 | int * Mrk = (int*)calloc(N ,sizeof(int)); 68 | if (Mrk == NULL) { fprintf(stderr, "kruskal : malloc failed\n"); exit(0); } 69 | 70 | uint32_t * SeededNodes = (uint32_t*)malloc(nb_markers*sizeof(uint32_t)); 71 | if (SeededNodes == NULL) { fprintf(stderr, "kruskal : malloc failed\n"); exit(0); } 72 | 73 | // markers 74 | SeededNodes[0]= M; 75 | j=1; 76 | for (i = 0; i < CT->nbnodes; i++) 77 | if (CT->tabnodes[i].nbsons == 0) 78 | { 79 | SeededNodes[j]= i+CT->nbnodes; 80 | Mrk[SeededNodes[j]] = 1; 81 | j++; 82 | } 83 | Mrk[M] = 1; 84 | 85 | uint32_t * Rnk = (uint32_t*)calloc(N, sizeof(uint32_t)); 86 | if (Rnk == NULL) { fprintf(stderr, "kruskal : malloc failed\n"); exit(0); } 87 | uint32_t * Fth = (uint32_t*)malloc(N*sizeof(uint32_t)); 88 | if (Fth == NULL) { fprintf(stderr, "kruskal : malloc failed\n"); exit(0); } 89 | for(k=0;knbnodes;k++) 98 | sorted_weights[k]=W[k]; 99 | 100 | for(k=0;knbnodes+k]=val; 102 | 103 | TriRapideStochastique_dec(sorted_weights,Es, 0, M-1); 104 | free(sorted_weights); 105 | 106 | 107 | long nb_arete = 0; 108 | int e_max, root; 109 | long cpt_aretes = 0; 110 | 111 | // ----------- beginning of main loop of Kruskal's algorithm ---------------- 112 | while (nb_arete < N-nb_markers) 113 | { 114 | e_max=Es[cpt_aretes]; 115 | cpt_aretes=cpt_aretes+1; 116 | e1= e_max; // e1 = Edges[0][e_max]; 117 | if (e_maxnbnodes) e2= CT->tabnodes[e_max].father; 118 | else if(e_max!=M) e2= e_max-CT->nbnodes; 119 | else e2=root_node; 120 | if (e2==-1)e2=M; //e2 = Edges[1][e_max]; 121 | //printf("(%d %d)\n", e1,e2); 122 | x = element_find(e1, Fth ); 123 | y = element_find(e2, Fth ); 124 | if ((x != y) && (!(Mrk[x]>=1 && Mrk[y]>=1))) 125 | { 126 | root = element_link( x,y, Rnk, Fth); 127 | //printf("link\n"); 128 | nb_arete=nb_arete+1; 129 | if ( Mrk[x]>=1) Mrk[root]= Mrk[x]; 130 | else if ( Mrk[y]>=1) Mrk[root]= Mrk[y]; 131 | } 132 | } 133 | 134 | //building the labeling for each individual markers in map 135 | // (find the root vertex of each tree) 136 | int * Map2 = (int *)malloc(N*sizeof(int)); 137 | int * Map = (int *)malloc(N*sizeof(int)); 138 | for (i=0; inbnodes; i++) 183 | { 184 | // nodes having a different value than their father are in the cut 185 | if ((CT->tabnodes[i].father != -1) && (Map[CT->tabnodes[i].father] != Map[i])) 186 | Insert2(&cut, i); 187 | // leafs having the same label as the root are in the cut 188 | if ((CT->tabnodes[i].nbsons == 0) && (Map[i]==0)) 189 | Insert2(&cut, i); 190 | } 191 | 192 | 193 | if (cut == NULL) Insert2(&cut, root_node); 194 | //PrintList(cut); 195 | LifoTermine(LIFO); 196 | free(Mrk); 197 | free(SeededNodes); 198 | free(Rnk); 199 | free(Fth); 200 | free(Es); 201 | free(Map); 202 | free(Map2); 203 | return cut; 204 | } 205 | 206 | 207 | 208 | /*================================================*/ 209 | void Insert2(list **sl, int index) 210 | /*================================================*/ 211 | { 212 | list *tmp = NULL; 213 | list *csl = *sl; 214 | list *elem = (list*) malloc(sizeof(list)); 215 | if(!elem) exit(EXIT_FAILURE); 216 | elem->index = index; 217 | while(csl) 218 | { 219 | tmp = csl; 220 | csl = csl->next; 221 | } 222 | elem->next = csl; 223 | if(tmp) tmp->next = elem; 224 | else *sl = elem; 225 | } 226 | 227 | 228 | /*================================================*/ 229 | void PrintList2(list *sl) 230 | /*================================================*/ 231 | { 232 | fprintf(stderr, "Nodes of the cut:\n"); 233 | while(sl) 234 | { 235 | printf("%d\n",sl->index); 236 | sl = sl->next; 237 | } 238 | } 239 | 240 | -------------------------------------------------------------------------------- /pink/mccodimage.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright ESIEE (2009) 3 | 4 | m.couprie@esiee.fr 5 | 6 | This software is an image processing library whose purpose is to be 7 | used primarily for research and teaching. 8 | 9 | This software is governed by the CeCILL license under French law and 10 | abiding by the rules of distribution of free software. You can use, 11 | modify and/ or redistribute the software under the terms of the CeCILL 12 | license as circulated by CEA, CNRS and INRIA at the following URL 13 | "http://www.cecill.info". 14 | 15 | As a counterpart to the access to the source code and rights to copy, 16 | modify and redistribute granted by the license, users are provided only 17 | with a limited warranty and the software's author, the holder of the 18 | economic rights, and the successive licensors have only limited 19 | liability. 20 | 21 | In this respect, the user's attention is drawn to the risks associated 22 | with loading, using, modifying and/or developing or reproducing the 23 | software by the user in light of its specific status of free software, 24 | that may mean that it is complicated to manipulate, and that also 25 | therefore means that it is reserved for developers and experienced 26 | professionals having in-depth computer knowledge. Users are therefore 27 | encouraged to load and test the software's suitability as regards their 28 | requirements in conditions enabling the security of their systems and/or 29 | data to be ensured and, more generally, to use and operate it in the 30 | same conditions as regards security. 31 | 32 | The fact that you are presently reading this means that you have had 33 | knowledge of the CeCILL license and that you accept its terms. 34 | */ 35 | #ifdef __cplusplus 36 | extern "C" { 37 | #endif 38 | 39 | #ifndef _PINK_TYPES_ 40 | #define _PINK_TYPES_ 41 | typedef unsigned char uint8_t; 42 | typedef unsigned short uint16_t; 43 | typedef unsigned int uint32_t; 44 | #endif 45 | 46 | #ifndef _MCIMAGE_H 47 | #include 48 | #endif 49 | 50 | #define NDG_MAX 255 /* niveau de gris max */ 51 | #define NDG_MIN 0 /* niveau de gris min */ 52 | 53 | typedef struct {float re; float im;} complex; 54 | typedef struct {double re; double im;} dcomplex; 55 | 56 | /* definitions for data storage type, 57 | uint32_t data_storage_type; */ 58 | #define VFF_TYP_BIT 0 /* pixels are on or off (binary image)*/ 59 | /* Note: This is an X11 XBitmap 60 | with bits packed into a byte and 61 | padded to a byte */ 62 | #define VFF_TYP_1_BYTE 1 /* pixels are byte (uint8_t) */ 63 | #define VFF_TYP_2_BYTE 2 /* pixels are two byte (int16_t) */ 64 | #define VFF_TYP_4_BYTE 4 /* pixels are four byte (integer) */ 65 | #define VFF_TYP_FLOAT 5 /* pixels are float (single precision)*/ 66 | #define VFF_TYP_DOUBLE 6 /* pixels are float (double precision)*/ 67 | #define VFF_TYP_COMPLEX 7 /* pixels are complex (single precision)*/ 68 | #define VFF_TYP_DCOMPLEX 8 /* pixels are complex (double precision)*/ 69 | 70 | struct xvimage { 71 | char *name; /* dummy - not used anymore */ 72 | index_t row_size; /* Size of a row (number of columns) */ 73 | index_t col_size; /* Size of a column (number of rows) */ 74 | index_t depth_size; /* Number of planes (for 3d images) */ 75 | index_t time_size; /* Number of (2d or 3d) images */ 76 | index_t num_data_bands; /* Number of bands per data pixel, 77 | or number of bands per image, or 78 | dimension of vector data, or 79 | number of elements in a vector */ 80 | int32_t data_storage_type; /* storage type for disk data */ 81 | double xdim, ydim, zdim; /* voxel dimensions in real world */ 82 | index_t xmin, xmax; /* region of interest: x coordinates */ 83 | index_t ymin, ymax; /* region of interest: y coordinates */ 84 | index_t zmin, zmax; /* region of interest: z coordinates */ 85 | void * image_data; /* pointer on raw data */ 86 | }; 87 | 88 | #define SCHARDATA(I) ((int8_t*)((I)->image_data)) 89 | #define UCHARDATA(I) ((uint8_t*)((I)->image_data)) 90 | #define SSHORTDATA(I) ((int16_t*)((I)->image_data)) 91 | #define USHORTDATA(I) ((uint16_t*)((I)->image_data)) 92 | #define SLONGDATA(I) ((int32_t*)((I)->image_data)) 93 | #define ULONGDATA(I) ((uint32_t*)((I)->image_data)) 94 | #define FLOATDATA(I) ((float*)((I)->image_data)) 95 | #define DOUBLEDATA(I) ((double*)((I)->image_data)) 96 | #define COMPLEXDATA(I) ((complex*)((I)->image_data)) 97 | #define DCOMPLEXDATA(I)((dcomplex*)((I)->image_data)) 98 | #define colsize(I) ((I)->col_size) 99 | #define rowsize(I) ((I)->row_size) 100 | #define depth(I) ((I)->depth_size) 101 | #define tsize(I) ((I)->time_size) 102 | #define nbands(I) ((I)->num_data_bands) 103 | #define datatype(I) ((I)->data_storage_type) 104 | #define pixel(I,x,y) (((uint8_t*)((I)->image_data))[(y)*(I)->row_size+(x)]) 105 | #define voxel(I,x,y,z) (((uint8_t*)((I)->image_data))[((z)*(I)->col_size+(y))*(I)->row_size+(x)]) 106 | #define lpixel(I,x,y) (((uint32_t*)((I)->image_data))[(y)*(I)->row_size+(x)]) 107 | #define lvoxel(I,x,y,z) (((uint32_t*)((I)->image_data))[((z)*(I)->col_size+(y))*(I)->row_size+(x)]) 108 | 109 | /* 110 | Codage du voisinage 111 | 112 | 113 | 3 2 1 114 | 4 X 0 115 | 5 6 7 116 | */ 117 | #define EST 0 118 | #define NORD 2 119 | #define OUEST 4 120 | #define SUD 6 121 | #define NORD_EST 1 122 | #define NORD_OUEST 3 123 | #define SUD_OUEST 5 124 | #define SUD_EST 7 125 | #define DEVANT 8 126 | #define DERRIERE 10 127 | 128 | #define nonbord(p,rs,N) ((p%rs!=rs-1)&&(p>=rs)&&(p%rs!=0)&&(p=ps)&&(p=rs)&&(p%ps