Commit 335fd4c00b83719ace1f8b08429cd4d6a2ad4043

Authored by Pierre Lassalle
1 parent ac66c13a
Exists in master

Remove old lss version

README.md
... ... @@ -1,10 +0,0 @@
1   -author: Pierre Lassalle
2   -
3   -Copyright (c) Centre National d'Etudes Spatiales. All rights reserved
4   -
5   -This is free software under the GPL v3 licence. See
6   -http://www.gnu.org/licenses/gpl-3.0.html for details.
7   -
8   -This software is distributed WITHOUT ANY WARRANTY; without even
9   -the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
10   -PURPOSE.
README.md~
code/CMakeLists.txt
... ... @@ -1,101 +0,0 @@
1   -PROJECT(LSS)
2   -
3   -cmake_minimum_required(VERSION 2.8)
4   -
5   -FIND_PACKAGE(OTB)
6   -IF(OTB_FOUND)
7   - INCLUDE(${OTB_USE_FILE})
8   -ELSE(OTB_FOUND)
9   - MESSAGE(FATAL_ERROR
10   - "Cannot build OTB project without OTB. Please set OTB_DIR.")
11   -ENDIF(OTB_FOUND)
12   -
13   -#Check compiler version
14   -if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
15   - # require at least gcc 4.8
16   - if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.8)
17   - message(FATAL_ERROR "GCC version must be at least 4.8!")
18   - endif()
19   -elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
20   - # require at least clang 3.2
21   - if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.2)
22   - message(FATAL_ERROR "Clang version must be at least 3.2!")
23   - endif()
24   -else()
25   - message(WARNING "You are using an unsupported compiler! Compilation has only been tested with Clang and GCC.")
26   -endif()
27   -
28   -include(CheckCXXCompilerFlag)
29   -CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
30   -if(COMPILER_SUPPORTS_CXX11)
31   - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fpermissive")
32   -else()
33   - message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.")
34   -endif()
35   -
36   -set(EXECUTABLE_OUTPUT_PATH bin)
37   -
38   -file(
39   - GLOB_RECURSE
40   - HEADERS
41   - "src/*.h"
42   -)
43   -
44   -file(
45   - GLOB_RECURSE
46   - TEMPLATES
47   - "src/*.txx"
48   -)
49   -
50   -file(
51   - GLOB_RECURSE
52   - SOURCES
53   - "src/*.cxx"
54   -)
55   -
56   -set(LSSS_INCLUDE_DIRS "")
57   -foreach(_headerFile ${HEADERS})
58   - get_filename_component(_dir ${_headerFile} PATH)
59   - list(APPEND LSSS_INCLUDE_DIRS ${_dir})
60   -endforeach()
61   -
62   -foreach(_templateFile ${TEMPLATES})
63   - get_filename_component(_dir ${_templateFile} PATH)
64   - list(APPEND LSSS_INCLUDE_DIRS ${_dir})
65   -endforeach()
66   -
67   -list(REMOVE_DUPLICATES LSSS_INCLUDE_DIRS)
68   -
69   -include_directories(${LSSS_INCLUDE_DIRS})
70   -
71   -ADD_EXECUTABLE(
72   - TiledBaatzSegmentation
73   - apps/TiledBaatzSegmentation.cxx
74   - ${SOURCES}
75   -)
76   -
77   -TARGET_LINK_LIBRARIES(TiledBaatzSegmentation OTBCommon OTBIO)
78   -
79   -ADD_EXECUTABLE(
80   - TiledFLSASegmentation
81   - apps/TiledFLSASegmentation.cxx
82   - ${SOURCES}
83   -)
84   -
85   -TARGET_LINK_LIBRARIES(TiledFLSASegmentation OTBCommon OTBIO)
86   -
87   -ADD_EXECUTABLE(
88   - BaatzSegmentation
89   - apps/BaatzSegmentation.cxx
90   - ${SOURCES}
91   -)
92   -
93   -TARGET_LINK_LIBRARIES(BaatzSegmentation OTBCommon OTBIO)
94   -
95   -ADD_EXECUTABLE(
96   - FLSASegmentation
97   - apps/FLSASegmentation.cxx
98   - ${SOURCES}
99   -)
100   -
101   -TARGET_LINK_LIBRARIES(FLSASegmentation OTBCommon OTBIO)
code/CMakeLists.txt~
... ... @@ -1,101 +0,0 @@
1   -PROJECT(LSS)
2   -
3   -cmake_minimum_required(VERSION 2.8)
4   -
5   -FIND_PACKAGE(OTB)
6   -IF(OTB_FOUND)
7   - INCLUDE(${OTB_USE_FILE})
8   -ELSE(OTB_FOUND)
9   - MESSAGE(FATAL_ERROR
10   - "Cannot build OTB project without OTB. Please set OTB_DIR.")
11   -ENDIF(OTB_FOUND)
12   -
13   -#Check compiler version
14   -if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
15   - # require at least gcc 4.8
16   - if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.8)
17   - message(FATAL_ERROR "GCC version must be at least 4.8!")
18   - endif()
19   -elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
20   - # require at least clang 3.2
21   - if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.2)
22   - message(FATAL_ERROR "Clang version must be at least 3.2!")
23   - endif()
24   -else()
25   - message(WARNING "You are using an unsupported compiler! Compilation has only been tested with Clang and GCC.")
26   -endif()
27   -
28   -include(CheckCXXCompilerFlag)
29   -CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
30   -if(COMPILER_SUPPORTS_CXX11)
31   - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fpermissive")
32   -else()
33   - message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.")
34   -endif()
35   -
36   -set(EXECUTABLE_OUTPUT_PATH bin)
37   -
38   -file(
39   - GLOB_RECURSE
40   - HEADERS
41   - "src/*.h"
42   -)
43   -
44   -file(
45   - GLOB_RECURSE
46   - TEMPLATES
47   - "src/*.txx"
48   -)
49   -
50   -file(
51   - GLOB_RECURSE
52   - SOURCES
53   - "src/*.cxx"
54   -)
55   -
56   -set(LSSS_INCLUDE_DIRS "")
57   -foreach(_headerFile ${HEADERS})
58   - get_filename_component(_dir ${_headerFile} PATH)
59   - list(APPEND LSSS_INCLUDE_DIRS ${_dir})
60   -endforeach()
61   -
62   -foreach(_templateFile ${TEMPLATES})
63   - get_filename_component(_dir ${_templateFile} PATH)
64   - list(APPEND LSSS_INCLUDE_DIRS ${_dir})
65   -endforeach()
66   -
67   -list(REMOVE_DUPLICATES LSSS_INCLUDE_DIRS)
68   -
69   -include_directories(${LSSS_INCLUDE_DIRS})
70   -
71   -ADD_EXECUTABLE(
72   - TiledBaatzSegmentation
73   - apps/TiledBaatzSegmentation.cxx
74   - ${SOURCES}
75   -)
76   -
77   -TARGET_LINK_LIBRARIES(TiledBaatzSegmentation OTBCommon OTBIO)
78   -
79   -ADD_EXECUTABLE(
80   - TiledFLSASegmentation
81   - apps/TiledFLSASegmentation.cxx
82   - ${SOURCES}
83   -)
84   -
85   -TARGET_LINK_LIBRARIES(TiledFLSASegmentation OTBCommon OTBIO)
86   -
87   -ADD_EXECUTABLE(
88   - BaatzSegmentation
89   - apps/BaatzSegmentation.cxx
90   - ${SOURCES}
91   -)
92   -
93   -TARGET_LINK_LIBRARIES(BaatzSegmentation OTBCommon OTBIO)
94   -
95   -ADD_EXECUTABLE(
96   - FLSASegmentation
97   - apps/FLSASegmentation.cxx
98   - ${SOURCES}
99   -)
100   -
101   -TARGET_LINK_LIBRARIES(FLSASegmentation OTBCommon OTBIO)
code/apps/BaatzSegmentation.cxx
... ... @@ -1,100 +0,0 @@
1   -/*=========================================================================
2   -
3   - Program: Large Scale Segmentation (LSS)
4   - Language: C++
5   - author: Lassalle Pierre
6   -
7   -
8   -
9   - Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
10   -
11   -
12   - This software is distributed WITHOUT ANY WARRANTY; without even
13   - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14   - PURPOSE. See the above copyright notices for more information.
15   -
16   -=========================================================================*/
17   -#include <otbVectorImage.h>
18   -#include "BaatzAlgorithm.h"
19   -#include "lss_RegionBasedTileBasedReduction.h"
20   -#include "lss_RegionBasedTileBasedIterativeReduction.h"
21   -#include "lss_RegionBasedFinisher.h"
22   -
23   -// For the command line
24   -#include <boost/program_options/cmdline.hpp>
25   -#include <boost/program_options/parsers.hpp>
26   -#include <boost/program_options/options_description.hpp>
27   -#include <boost/program_options/variables_map.hpp>
28   -
29   -namespace po = boost::program_options;
30   -bool init_args(int argc, char ** argv, po::options_description& desc, po::variables_map& vm);
31   -
32   -int main(int argc, char **argv)
33   -{
34   -
35   - po::options_description desc("Baatz & Schäpe segmentation: usage");
36   - po::variables_map vm;
37   -
38   - if(init_args(argc, argv, desc, vm))
39   - {
40   - BaatzParameters bparams = {(float)vm["color"].as<double>(), (float)vm["compact"].as<double>(), (float)pow(vm["scale"].as<double>(), 2)};
41   - typedef otb::VectorImage<float, 2> ImageType;
42   - typedef BaatzAlgorithm<ImageType> AlgorithmType;
43   - AlgorithmType baatz_segmenter;
44   - baatz_segmenter.SetParameters(bparams);
45   - baatz_segmenter.InitFromTiffImage(vm["input"].as<std::string>());
46   - baatz_segmenter.Segmentation();
47   - baatz_segmenter.WriteResultingImage(vm["output"].as<std::string>());
48   - return 0;
49   - }else{
50   - return 1;
51   - }
52   -
53   - return 0;
54   -}
55   -
56   -bool init_args(int argc, char ** argv, po::options_description& desc, po::variables_map& vm)
57   -{
58   - desc.add_options()
59   - ("help", "Baatz & Schäpe parameters")
60   - ("input", po::value<std::string>(), "set input image path")
61   - ("output", po::value<std::string>(), "set output image path (contour image file (png))")
62   - ("scale", po::value<double>(), "set the scale parameter which has to be positive (40 for example)")
63   - ("color", po::value<double>(), "set the color weight, value between 0 and 1 (0.7 for example)")
64   - ("compact", po::value<double>(), "set the compact weight, value between 0 and 1 (0.3 for example)");
65   -
66   - po::store(po::parse_command_line(argc, argv, desc), vm);
67   - po::notify(vm);
68   -
69   - if (vm.count("help")) {
70   - std::cout << desc << "\n";
71   - return false;
72   - }
73   -
74   - if (!vm.count("input")) {
75   - std::cout << "The input image path was not set (--input).\n";
76   - return false;
77   - }
78   -
79   - if (!vm.count("output")) {
80   - std::cout << "The output image path was not set (--output).\n";
81   - return false;
82   - }
83   -
84   - if (!vm.count("scale")) {
85   - std::cout << "The scale parameter was not set (--scale).\n";
86   - return false;
87   - }
88   -
89   - if(!vm.count("color")){
90   - std::cout << "The color weight was not set (--color).\n";
91   - return false;
92   - }
93   -
94   - if(!vm.count("compact")){
95   - std::cout << "The compact weight was not set (--compact)\n";
96   - return false;
97   - }
98   -
99   - return true;
100   -}
code/apps/FLSASegmentation.cxx
... ... @@ -1,85 +0,0 @@
1   -/*=========================================================================
2   -
3   - Program: Large Scale Segmentation (LSS)
4   - Language: C++
5   - author: Lassalle Pierre
6   -
7   -
8   -
9   - Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
10   -
11   -
12   - This software is distributed WITHOUT ANY WARRANTY; without even
13   - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14   - PURPOSE. See the above copyright notices for more information.
15   -
16   -=========================================================================*/
17   -#include <otbVectorImage.h>
18   -#include "FLSAlgorithm.h"
19   -#include "lss_RegionBasedTileBasedReduction.h"
20   -#include "lss_RegionBasedTileBasedIterativeReduction.h"
21   -#include "lss_RegionBasedFinisher.h"
22   -
23   -// For the command line
24   -#include <boost/program_options/cmdline.hpp>
25   -#include <boost/program_options/parsers.hpp>
26   -#include <boost/program_options/options_description.hpp>
27   -#include <boost/program_options/variables_map.hpp>
28   -
29   -namespace po = boost::program_options;
30   -bool init_args(int argc, char ** argv, po::options_description& desc, po::variables_map& vm);
31   -
32   -int main(int argc, char **argv)
33   -{
34   - po::options_description desc("Baatz & Schäpe segmentation: usage");
35   - po::variables_map vm;
36   -
37   - if(init_args(argc, argv, desc, vm))
38   - {
39   - FLSParameter fparam = vm["lambda"].as<double>();
40   - typedef otb::VectorImage<float, 2> ImageType;
41   - typedef FLSAlgorithm<ImageType> AlgorithmType;
42   - AlgorithmType fls_segmenter;
43   - fls_segmenter.SetParameters(fparam);
44   - fls_segmenter.InitFromTiffImage(vm["input"].as<std::string>());
45   - fls_segmenter.Segmentation();
46   - fls_segmenter.WriteResultingImage(vm["output"].as<std::string>());
47   - return 0;
48   - }
49   - else
50   - return 1;
51   -}
52   -
53   -bool init_args(int argc, char ** argv, po::options_description& desc, po::variables_map& vm)
54   -{
55   - desc.add_options()
56   - ("help", "Full lambda schedule parameters")
57   - ("input", po::value<std::string>(), "set input image path")
58   - ("output", po::value<std::string>(), "set output image path (contour image file (png))")
59   - ("lambda", po::value<double>(), "set the lambda parameter which has to be positive (60 for example)");
60   -
61   - po::store(po::parse_command_line(argc, argv, desc), vm);
62   - po::notify(vm);
63   -
64   - if (vm.count("help")) {
65   - std::cout << desc << "\n";
66   - return false;
67   - }
68   -
69   - if (!vm.count("input")) {
70   - std::cout << "The input image path was not set (--input).\n";
71   - return false;
72   - }
73   -
74   - if (!vm.count("output")) {
75   - std::cout << "The output image path was not set (--output).\n";
76   - return false;
77   - }
78   -
79   - if (!vm.count("lambda")) {
80   - std::cout << "The lambda parameter was not set (--lambda).\n";
81   - return false;
82   - }
83   -
84   - return true;
85   -}
code/apps/TiledBaatzSegmentation.cxx
... ... @@ -1,94 +0,0 @@
1   -/*=========================================================================
2   -
3   - Program: Large Scale Segmentation (LSS)
4   - Language: C++
5   - author: Lassalle Pierre
6   -
7   -
8   -
9   - Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
10   -
11   -
12   - This software is distributed WITHOUT ANY WARRANTY; without even
13   - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14   - PURPOSE. See the above copyright notices for more information.
15   -
16   -=========================================================================*/
17   -#include <otbVectorImage.h>
18   -#include "BaatzAlgorithm.h"
19   -#include "lss_RegionBasedTileBasedReduction.h"
20   -#include "lss_RegionBasedTileBasedIterativeReduction.h"
21   -#include "lss_RegionBasedFinisher.h"
22   -
23   -int main(int argc, char **argv)
24   -{
25   - if(argc != 11)
26   - {
27   - std::cerr << "Usage: " << argv[0] << ": \n"
28   - << "[input image path (jpg, png, tiff, jpeg200)]\n"
29   - << "[output image path (jpg, png, tiff)]\n"
30   - << "[temporary directory path]\n"
31   - << "[tile size according to the width]\n"
32   - << "[tile size according to the height]\n"
33   - << "[number of iteration for Tile-Based reduction step]\n"
34   - << "[scale]\n"
35   - << "[color]\n"
36   - << "[compactness]\n"
37   - << "[memory available (Mo)]";
38   -
39   - return 1;
40   - }
41   -
42   - std::string input = argv[1];
43   - std::string output = argv[2];
44   - std::string tmpdir = argv[3];
45   - unsigned int tilesizeX = atoi(argv[4]);
46   - unsigned int tilesizeY = atoi(argv[5]);
47   - unsigned int niter = atoi(argv[6]);
48   - BaatzParameters bparams = {(float)atof(argv[8]), (float)atof(argv[9]), (float)pow(atof(argv[7]), 2)};
49   - long unsigned int memory = atoi(argv[10]);
50   - unsigned int margin = static_cast<unsigned int>(pow(2, niter+1) - 2);
51   -
52   - typedef otb::VectorImage<float, 2> ImageType;
53   - typedef BaatzAlgorithm<ImageType> AlgorithmType;
54   - typedef lss::RegionBasedTileBasedReduction<ImageType, AlgorithmType> TileBasedReductionType;
55   - typedef lss::RegionBasedTileBasedIterativeReduction<AlgorithmType> TileBasedIterativeReductionType;
56   - typedef lss::RegionBasedFinisher<AlgorithmType> FinisherType;
57   -
58   - // Tile Based Reduction step
59   - std::cout << "***********************************\n";
60   - std::cout << "* Tile Based Reduction Step *\n";
61   - std::cout << "***********************************\n";
62   - TileBasedReductionType tb_reduction;
63   - tb_reduction.SetInputImagePath(input);
64   - tb_reduction.SetTemporaryDirectoryPath(tmpdir);
65   - tb_reduction.SetTileSizeX(tilesizeX);
66   - tb_reduction.SetTileSizeY(tilesizeY);
67   - tb_reduction.SetMarginOfStability(margin);
68   - tb_reduction.SetNumberOfIterations(niter);
69   - tb_reduction.SetSegmentationParameters(bparams);
70   - tb_reduction.GenerateData();
71   -
72   - // Tile Based Iterative reduction step
73   - std::cout << "*********************************************\n";
74   - std::cout << "* Tile Based Iterative Reduction Step *\n";
75   - std::cout << "*********************************************\n";
76   - TileBasedIterativeReductionType tb_itreduction;
77   - tb_itreduction.SetObserver(tb_reduction.GetObserver());
78   - tb_itreduction.SetSegmentationParameters(bparams);
79   - tb_itreduction.SetAvailableMemory(memory);
80   - bool DoSegmentation = tb_itreduction.GenerateData();
81   -
82   - std::cout << "*********************************************\n";
83   - std::cout << "* Aggregating and completion step *\n";
84   - std::cout << "*********************************************\n";
85   - FinisherType finisher;
86   - finisher.SetOutputPath(output);
87   - finisher.SetObserver(tb_itreduction.GetObserver());
88   - finisher.SetDoSegmentation(DoSegmentation);
89   - finisher.SetTiles(tb_itreduction.GetTiles());
90   - finisher.SetSegmentationParameters(bparams);
91   - finisher.GenerateData();
92   -
93   - return 0;
94   -}
code/apps/TiledFLSASegmentation.cxx
... ... @@ -1,92 +0,0 @@
1   -/*=========================================================================
2   -
3   - Program: Large Scale Segmentation (LSS)
4   - Language: C++
5   - author: Lassalle Pierre
6   -
7   -
8   -
9   - Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
10   -
11   -
12   - This software is distributed WITHOUT ANY WARRANTY; without even
13   - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14   - PURPOSE. See the above copyright notices for more information.
15   -
16   -=========================================================================*/
17   -#include <otbVectorImage.h>
18   -#include "FLSAlgorithm.h"
19   -#include "lss_RegionBasedTileBasedReduction.h"
20   -#include "lss_RegionBasedTileBasedIterativeReduction.h"
21   -#include "lss_RegionBasedFinisher.h"
22   -
23   -int main(int argc, char **argv)
24   -{
25   - if(argc != 9)
26   - {
27   - std::cerr << "Usage: " << argv[0] << ": \n"
28   - << "[input image path (jpg, png, tiff, jpeg200)]\n"
29   - << "[output image path (jpg, png, tiff)]\n"
30   - << "[temporary directory path]\n"
31   - << "[tile size according to the width]\n"
32   - << "[tile size according to the height]\n"
33   - << "[number of iteration for Tile-Based reduction step]\n"
34   - << "[lambda threshold]\n"
35   - << "[memory available (Mo)]\n";
36   -
37   - return 1;
38   - }
39   -
40   - std::string input = argv[1];
41   - std::string output = argv[2];
42   - std::string tmpdir = argv[3];
43   - unsigned int tilesizeX = atoi(argv[4]);
44   - unsigned int tilesizeY = atoi(argv[5]);
45   - unsigned int niter = atoi(argv[6]);
46   - FLSParameter sparams = (double)atof(argv[7]);
47   - long unsigned int memory = atoi(argv[8]);
48   - unsigned int margin = static_cast<unsigned int>(pow(2, niter+1) - 2);
49   -
50   - typedef otb::VectorImage<float, 2> ImageType;
51   - typedef FLSAlgorithm<ImageType> AlgorithmType;
52   - typedef lss::RegionBasedTileBasedReduction<ImageType, AlgorithmType> TileBasedReductionType;
53   - typedef lss::RegionBasedTileBasedIterativeReduction<AlgorithmType> TileBasedIterativeReductionType;
54   - typedef lss::RegionBasedFinisher<AlgorithmType> FinisherType;
55   -
56   - // Tile Based Reduction step
57   - std::cout << "***********************************\n";
58   - std::cout << "* Tile Based Reduction Step *\n";
59   - std::cout << "***********************************\n";
60   - TileBasedReductionType tb_reduction;
61   - tb_reduction.SetInputImagePath(input);
62   - tb_reduction.SetTemporaryDirectoryPath(tmpdir);
63   - tb_reduction.SetTileSizeX(tilesizeX);
64   - tb_reduction.SetTileSizeY(tilesizeY);
65   - tb_reduction.SetMarginOfStability(margin);
66   - tb_reduction.SetNumberOfIterations(niter);
67   - tb_reduction.SetSegmentationParameters(sparams);
68   - tb_reduction.GenerateData();
69   -
70   - // Tile Based Iterative reduction step
71   - std::cout << "*********************************************\n";
72   - std::cout << "* Tile Based Iterative Reduction Step *\n";
73   - std::cout << "*********************************************\n";
74   - TileBasedIterativeReductionType tb_itreduction;
75   - tb_itreduction.SetObserver(tb_reduction.GetObserver());
76   - tb_itreduction.SetSegmentationParameters(sparams);
77   - tb_itreduction.SetAvailableMemory(memory);
78   - bool DoSegmentation = tb_itreduction.GenerateData();
79   -
80   - std::cout << "*********************************************\n";
81   - std::cout << "* Aggregating and completion step *\n";
82   - std::cout << "*********************************************\n";
83   - FinisherType finisher;
84   - finisher.SetOutputPath(output);
85   - finisher.SetObserver(tb_itreduction.GetObserver());
86   - finisher.SetDoSegmentation(DoSegmentation);
87   - finisher.SetTiles(tb_itreduction.GetTiles());
88   - finisher.SetSegmentationParameters(sparams);
89   - finisher.GenerateData();
90   -
91   - return 0;
92   -}
code/img/test.tif
No preview for this file type
code/src/algo/BaatzAlgorithm.h
... ... @@ -1,138 +0,0 @@
1   -/*=========================================================================
2   -
3   - Program: Large Scale Segmentation (LSS)
4   - Language: C++
5   - author: Lassalle Pierre
6   -
7   -
8   -
9   - Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
10   -
11   -
12   - This software is distributed WITHOUT ANY WARRANTY; without even
13   - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14   - PURPOSE. See the above copyright notices for more information.
15   -
16   -=========================================================================*/
17   -#ifndef __BaatzAlgorithm_h
18   -#define __BaatzAlgorithm_h
19   -
20   -#include <otbImage.h>
21   -#include <otbVectorImage.h>
22   -#include <otbImageFileReader.h>
23   -#include <otbImageFileWriter.h>
24   -#include <itkImageRegionIterator.h>
25   -#include "lss_GenericLMBFRegionMergingHandler.h"
26   -#include "lss_MacroGenerator.h"
27   -
28   -struct BaatzRegion : public lss::CRPT_Region<BaatzRegion>
29   -{
30   - // Specific attributes for Baatz & Shape criterion
31   - float m_Area;
32   - float m_Perimeter;
33   - std::vector<float> m_Avg_Color;
34   - std::vector<float> m_Avg_Color_Square;
35   - std::vector<float> m_Color_Sum;
36   - std::vector<float> m_Std_Color;
37   -
38   - // Serialization for the storage on the disk (information on the number of bands is considered)
39   - unsigned int GetSizeOfData()
40   - {
41   - return (3 + 4*m_Avg_Color.size());
42   - }
43   -
44   - // store elements in a contiguous way in the memory
45   - void SerializeData(float * data_block)
46   - {
47   - data_block[0] = m_Area;
48   - data_block[1] = m_Perimeter;
49   - data_block[2] = static_cast<float>(m_Avg_Color.size());
50   - for(unsigned int b =0; b<m_Avg_Color.size(); b++)
51   - {
52   - data_block[3+b] = m_Avg_Color[b];
53   - data_block[3 + m_Avg_Color.size() + b] = m_Avg_Color_Square[b];
54   - data_block[3 + 2*m_Avg_Color.size() + b] = m_Color_Sum[b];
55   - data_block[3 + 3*m_Avg_Color.size() + b] = m_Std_Color[b];
56   - }
57   - }
58   -
59   - // Read from the contiguous block of memory returned
60   - void InitAttributesFromSerializeData(float * data_block)
61   - {
62   - m_Area = data_block[0];
63   - m_Perimeter = data_block[1];
64   - unsigned int bands = static_cast<unsigned int>(data_block[2]);
65   - m_Avg_Color.reserve(bands);
66   - m_Avg_Color_Square.reserve(bands);
67   - m_Color_Sum.reserve(bands);
68   - m_Std_Color.reserve(bands);
69   - for(unsigned int b=0; b<bands; b++)
70   - {
71   - m_Avg_Color.push_back(data_block[3+b]);
72   - m_Avg_Color_Square.push_back(data_block[3 + bands + b]);
73   - m_Color_Sum.push_back(data_block[3 + 2*bands + b]);
74   - m_Std_Color.push_back(data_block[3 + 3*bands + b]);
75   - }
76   - }
77   -};
78   -
79   -struct BaatzParameters
80   -{
81   - float m_ColorWeight;
82   - float m_CompactnessWeight;
83   - float m_Scale;
84   -};
85   -
86   -template<class TInputImage>
87   -class BaatzAlgorithm
88   -{
89   - public:
90   -
91   - // Mandatory typedef
92   - typedef BaatzRegion RegionType;
93   - typedef BaatzParameters ParameterType;
94   - typedef std::shared_ptr<BaatzRegion> RegionPointerType;
95   - typedef std::vector<RegionPointerType> RegionListType;
96   - typedef TInputImage InputImageType;
97   - typedef otb::ImageFileReader<InputImageType> ReaderType;
98   - typedef otb::ImageFileWriter<InputImageType> WriterType;
99   - typedef itk::ImageRegionIterator<InputImageType> IteratorType;
100   - typedef itk::ImageRegion<2>::IndexType BboxIndexType;
101   - typedef itk::ImageRegion<2>::SizeType BboxSizeType;
102   -
103   - // Optional: Label Image
104   - typedef unsigned int LabelPixelType;
105   - typedef otb::Image<LabelPixelType,2> LabelImageType;
106   - typedef itk::ImageRegionIterator<LabelImageType> LabelIteratorType;
107   - typedef otb::ImageFileWriter<LabelImageType> LabelWriterType;
108   -
109   - SetMacro(ParameterType, Parameters)
110   - SetMacro(unsigned int, NumberOfIterations);
111   - GetMacro(bool, PreviousMerge);
112   - GetMacro(RegionListType, RegionList);
113   - SetMacro(RegionListType, RegionList);
114   - void SetDimensionForEncoder(unsigned int, unsigned int);
115   -
116   - void InitFromTiffImage(const std::string& input_file);
117   - void Segmentation();
118   - void WriteResultingImage(const std::string& ofname);
119   - void WriteLabelImage(const std::string& ofname);
120   -
121   - private:
122   -
123   - // Specific methods to compute the fusion cost
124   - double ColorComponentCostFusion(RegionPointerType r1, RegionPointerType r2);
125   - double CompactnessComponentCostFusion(RegionPointerType r1, RegionPointerType r2);
126   - void UpdateAttribute(RegionPointerType r1, RegionPointerType r2);
127   -
128   - bool m_PreviousMerge;
129   - ParameterType m_Parameters;
130   - unsigned int m_NumberOfIterations;
131   - RegionListType m_RegionList;
132   - lss::GenericLMBFRegionMergingHandler<BaatzRegion> m_RMHandler;
133   - std::function<double(RegionPointerType, RegionPointerType)> m_ComputeCostFunction;
134   -};
135   -
136   -#include "BaatzAlgorithm.txx"
137   -
138   -#endif
code/src/algo/BaatzAlgorithm.txx
... ... @@ -1,338 +0,0 @@
1   -/*=========================================================================
2   -
3   - Program: Large Scale Segmentation (LSS)
4   - Language: C++
5   - author: Lassalle Pierre
6   -
7   -
8   -
9   - Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
10   -
11   -
12   - This software is distributed WITHOUT ANY WARRANTY; without even
13   - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14   - PURPOSE. See the above copyright notices for more information.
15   -
16   -=========================================================================*/
17   -#ifndef __BaatzAlgorithm_txx
18   -#define __BaatzAlgorithm_txx
19   -
20   -template<class TInputImage>
21   -void
22   -BaatzAlgorithm<TInputImage>::SetDimensionForEncoder(unsigned int cols, unsigned int rows)
23   -{
24   - m_RMHandler.m_Encoder.SetCols(cols);
25   - m_RMHandler.m_Encoder.SetRows(rows);
26   -}
27   -
28   -template<class TInputImage>
29   -void
30   -BaatzAlgorithm<TInputImage>::InitFromTiffImage(const std::string& input_file)
31   -{
32   - auto reader = ReaderType::New();
33   - reader->SetFileName(input_file);
34   - reader->Update();
35   -
36   - auto regionToProcess = reader->GetOutput()->GetLargestPossibleRegion();
37   - unsigned int cols = regionToProcess.GetSize()[0];
38   - unsigned int rows = regionToProcess.GetSize()[1];
39   - unsigned int bands = reader->GetOutput()->GetNumberOfComponentsPerPixel();
40   -
41   - m_RMHandler.m_Encoder.SetRows(rows); // Penser à n'utiliser qu'une seule méthode (SetRegionToProcess)
42   - m_RMHandler.m_Encoder.SetCols(cols);
43   -
44   - m_RegionList.reserve(cols*rows);
45   -
46   - IteratorType it(reader->GetOutput(), regionToProcess);
47   -
48   - // Create the vertices
49   - long unsigned int idx = 0;
50   - for(it.GoToBegin(); !it.IsAtEnd(); ++it)
51   - {
52   - auto r = std::make_shared<BaatzRegion>();
53   - m_RMHandler.InitGenericRegion(r, idx);
54   - r->m_Area = 1;
55   - r->m_Perimeter = 4;
56   - r->m_Avg_Color.reserve(bands);
57   - r->m_Avg_Color_Square.reserve(bands);
58   - r->m_Color_Sum.reserve(bands);
59   - r->m_Std_Color.reserve(bands);
60   -
61   - for(unsigned int b = 0; b < bands; b++)
62   - {
63   - r->m_Avg_Color.push_back(it.Get()[b]);
64   - r->m_Avg_Color_Square.push_back(pow(it.Get()[b], 2));
65   - r->m_Color_Sum.push_back(it.Get()[b]);
66   - r->m_Std_Color.push_back(0);
67   - }
68   -
69   - m_RegionList.push_back(r);
70   - ++idx;
71   - }
72   - m_RMHandler.InitNeighborhood(m_RegionList);
73   -}
74   -
75   -template<class TInputImage>
76   -double
77   -BaatzAlgorithm<TInputImage>::ColorComponentCostFusion(RegionPointerType r1, RegionPointerType r2)
78   -{
79   - unsigned int bands = r1->m_Avg_Color.size();
80   - float mean[bands], colorSum[bands];
81   - float squarePixels[bands];
82   - float stddev[bands];
83   - float stddevNew[bands];
84   - double color_f[bands];
85   - double color_h;
86   - float a_current, a_neighbor, a_sum;
87   - a_current = r1->m_Area;
88   - a_neighbor = r2->m_Area;
89   - a_sum = a_current+a_neighbor;
90   -
91   - for (unsigned int b = 0; b < bands; b++)
92   - {
93   - mean[b] = ((r1->m_Avg_Color[b]*a_current)+(r2->m_Avg_Color[b]*a_neighbor))/a_sum;
94   - squarePixels[b] = (r1->m_Avg_Color_Square[b])+(r2->m_Avg_Color_Square[b]);
95   - colorSum[b] = r1->m_Color_Sum[b] + r2->m_Color_Sum[b];
96   - stddev[b] = 0;
97   - stddevNew[b] = 0;
98   - }
99   -
100   - for(unsigned int b = 0; b < bands; b++)
101   - {
102   - stddevNew[b] = squarePixels[b] - 2*mean[b]*colorSum[b] + a_sum*mean[b]*mean[b];
103   - }
104   -
105   - /* calculates color factor per band and total */
106   - color_h = 0;
107   - for (unsigned int b = 0; b < bands; b++)
108   - {
109   - stddev[b] = sqrt(stddevNew[b]/a_sum);
110   - color_f[b] = (a_current*r1->m_Std_Color[b]) + (a_neighbor*r2->m_Std_Color[b]);
111   - color_f[b] = (a_sum*stddev[b])- color_f[b];
112   - color_h += color_f[b];
113   - }
114   - return color_h;
115   -}
116   -
117   -template<class TInputImage>
118   -double
119   -BaatzAlgorithm<TInputImage>::CompactnessComponentCostFusion(RegionPointerType r1, RegionPointerType r2)
120   -{
121   - double spatial_h, smooth_f, compact_f;
122   - float area[3], perimeter[3], b_box_len[3]; /* 0-current segment; 1-neighbor segment; 2-merged (new) segment */
123   -
124   - /* area */
125   - area[0] = r1->m_Area;
126   - area[1] = r2->m_Area;
127   - area[2] = area[0]+area[1];
128   -
129   - /* perimeter */
130   - perimeter[0] = r1->m_Perimeter;
131   - perimeter[1] = r2->m_Perimeter;
132   - perimeter[2] = r1->m_Perimeter + r2->m_Perimeter - 2*m_RMHandler.GetConnections(r1, r2);
133   -
134   - /* bounding box lenght */
135   - auto mbbox = m_RMHandler.GetResultingBbox(r1, r2);
136   - b_box_len[0] = (r1->m_Bbox.GetSize(0))*2 + (r1->m_Bbox.GetSize(1))*2;
137   - b_box_len[1] = (r2->m_Bbox.GetSize(0))*2 + (r2->m_Bbox.GetSize(1))*2;
138   - b_box_len[2] = (mbbox.GetSize(0))*2 + (mbbox.GetSize(1))*2;
139   -
140   - /* smoothness factor */
141   - smooth_f = (area[2]*perimeter[2]/b_box_len[2] -
142   - (area[1]*perimeter[1]/b_box_len[1] + area[0]*perimeter[0]/b_box_len[0]));
143   -
144   - /* compactness factor */
145   - compact_f = (area[2]*perimeter[2]/sqrt(area[2]) -
146   - (area[1]*perimeter[1]/sqrt(area[1]) + area[0]*perimeter[0]/sqrt(area[0])));
147   -
148   - /* spatial heterogeneity */
149   - spatial_h = m_Parameters.m_CompactnessWeight*compact_f + (1-m_Parameters.m_CompactnessWeight)*smooth_f;
150   -
151   - return spatial_h;
152   -}
153   -
154   -template<class TInputImage>
155   -void
156   -BaatzAlgorithm<TInputImage>::Segmentation()
157   -{
158   - m_PreviousMerge = false;
159   - unsigned int max_iter = 500;
160   - if(m_NumberOfIterations > 0)
161   - max_iter = m_NumberOfIterations;
162   -
163   - unsigned int curr_step = 0;
164   - double cost;
165   - RegionPointerType bestneigh = nullptr;
166   - bool prev_merged = true;
167   -
168   - auto cw = m_Parameters.m_ColorWeight;
169   - auto sc = m_Parameters.m_Scale;
170   - m_ComputeCostFunction = [&](RegionPointerType r1, RegionPointerType r2)->double
171   - {
172   - double spectral_h;
173   - double spatial_h;
174   - double cost = 0;
175   -
176   - spectral_h = ColorComponentCostFusion(r1, r2);
177   - cost += cw * spectral_h;
178   -
179   - if(cost < sc)
180   - {
181   - spatial_h = CompactnessComponentCostFusion(r1, r2);
182   - cost += (1-cw)*spatial_h;
183   - return cost;
184   - }
185   - else
186   - return cost;
187   - };
188   -
189   - while(curr_step < max_iter && prev_merged)
190   - {
191   - prev_merged = false;
192   - std::cout << curr_step << std::endl;
193   - m_RMHandler.UpdateMergingCost(m_RegionList, m_ComputeCostFunction);
194   -
195   - for(auto& r: m_RegionList)
196   - {
197   - if(m_RMHandler.IsLMBF(r, m_Parameters.m_Scale))
198   - {
199   - auto res = m_RMHandler.GetRegionsToMerge(r);
200   - //std::cout << "Merge " << res.first->m_Id << " with " << res.second->m_Id << std::endl;
201   - // User contribution
202   - UpdateAttribute(res.first, res.second);
203   - m_RMHandler.Update(res);
204   - prev_merged = true;
205   - }
206   - }
207   - m_RMHandler.RemoveExpiredVertices(m_RegionList);
208   - curr_step++;
209   - m_PreviousMerge = prev_merged;
210   - }
211   -}
212   -
213   -template<class TInputImage>
214   -void
215   -BaatzAlgorithm<TInputImage>::UpdateAttribute(RegionPointerType r1, RegionPointerType r2)
216   -{
217   - // Update the spectral attributes
218   -
219   - unsigned int bands = r1->m_Avg_Color.size();
220   - float mean[bands], colorSum[bands];
221   - float squarePixels[bands];
222   - float a_current, a_neighbor, a_sum;
223   - a_current = r1->m_Area;
224   - a_neighbor = r2->m_Area;
225   - a_sum = a_current+a_neighbor;
226   -
227   - for (unsigned int b = 0; b < bands; b++)
228   - {
229   - mean[b] = ((r1->m_Avg_Color[b]*a_current)+(r2->m_Avg_Color[b]*a_neighbor))/a_sum;
230   - squarePixels[b] = (r1->m_Avg_Color_Square[b])+(r2->m_Avg_Color_Square[b]);
231   - colorSum[b] = r1->m_Color_Sum[b] + r2->m_Color_Sum[b];
232   - }
233   -
234   - for(unsigned int b = 0; b < bands; b++)
235   - {
236   - r1->m_Avg_Color[b] = mean[b];
237   - r1->m_Avg_Color_Square[b] = squarePixels[b];
238   - r1->m_Color_Sum[b] = colorSum[b];
239   - r1->m_Std_Color[b] = sqrt((squarePixels[b] - 2*mean[b]*colorSum[b] + a_sum*mean[b]*mean[b])/a_sum);
240   - }
241   -
242   - // Update spatial attributes
243   - r1->m_Area += r2->m_Area;
244   - r1->m_Perimeter += r2->m_Perimeter - 2*m_RMHandler.GetConnections(r1,r2);
245   -}
246   -
247   -template<class TInputImage>
248   -void
249   -BaatzAlgorithm<TInputImage>::WriteLabelImage(const std::string& ofname)
250   -{
251   - typename InputImageType::IndexType index;
252   - typename InputImageType::SizeType size;
253   - typename InputImageType::RegionType region;
254   - auto label_image = LabelImageType::New();
255   -
256   - index[0] = 0;
257   - index[1] = 0;
258   - size[0] = m_RMHandler.m_Encoder.GetCols();
259   - size[1] = m_RMHandler.m_Encoder.GetRows();
260   - region.SetIndex(index);
261   - region.SetSize(size);
262   -
263   - label_image->SetRegions(region);
264   - label_image->Allocate();
265   -
266   - unsigned int label = 1;
267   - for(auto& v : m_RegionList)
268   - {
269   - auto pixels = m_RMHandler.m_Encoder.GenerateAllPixels(v->m_Id, v->m_Contour, v->m_Bbox);
270   - for(auto& pix: pixels)
271   - {
272   - index[0] = pix % size[0];
273   - index[1] = pix / size[0];
274   - auto label_pixel = label_image->GetPixel(index);
275   - label_image->SetPixel(index, label);
276   - }
277   - label++;
278   - }
279   -
280   - auto label_writer = LabelWriterType::New();
281   - label_writer->SetFileName(ofname);
282   - label_writer->SetInput(label_image);
283   - label_writer->Update();
284   -}
285   -
286   -template<class TInputImage>
287   -void
288   -BaatzAlgorithm<TInputImage>::WriteResultingImage(const std::string& ofname)
289   -{
290   - auto out_image = InputImageType::New();
291   - typename InputImageType::IndexType index;
292   - typename InputImageType::SizeType size;
293   - typename InputImageType::RegionType region;
294