otbLSGRM.cxx 2.06 KB
Newer Older
1
2
3
4
5
6
#include <iostream>
#include "lsrmBaatzSegmenter.h"
#include "lsgrmController.h"

int main(int argc, char *argv[])
{
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33

  int myrank, nprocs;
  MPI_Init(&argc, &argv);
  MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
  MPI_Comm_rank(MPI_COMM_WORLD, &myrank);

  if (myrank==0)
    std::cout << "Number of MPI process : " << nprocs << std::endl;

  if(argc != 8)
    {
    // img/test.tif tiles/ 125 125 4 tmp/
    std::cerr << "[input image] [tile directory] [tile width] [tile height] [number of first iterations] [temporary directory] [output directory]"
        << std::endl;
    return 1;
    }

  /* Parse command line arguments */
  const std::string imagePath = argv[1];
  std::string tileDir = argv[2]; // May be corrected if badly written.
  const unsigned int tileWidth = atoi(argv[3]);
  const unsigned int tileHeight = atoi(argv[4]);
  const unsigned int niter = atoi(argv[5]);
  std::string tmpDir = argv[6]; // May be corrected if badly written.
  std::string outDir = argv[7];

  /*
34
35
36
37
38
	  To add:
	  internal memory available
	  If we have to do the image division
	  if we have to clean up the directory
	  the output directory in case the global graph cannot fit in memory
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73

   */

  using ImageType = otb::VectorImage<float, 2>;
  using SegmenterType = lsrm::BaatzSegmenter<ImageType>;
  using ControllerType = lsgrm::Controller<SegmenterType>;


  ControllerType controller;
  controller.SetInputImage(imagePath);
  controller.SetTileDirectory(tileDir);
  controller.SetTemporaryDirectory(tmpDir);
  controller.SetOutputGraphDirectory(outDir);

  // Memory configuration
  controller.SetInternalMemoryAvailable(4096ul);
  controller.SetTileWidth(tileWidth);
  controller.SetTileHeight(tileHeight);
  controller.SetNumberOfFirstIterations(niter);

  // MPI configuration
  controller.SetNumberOfProcess(nprocs);
  controller.SetProcessRank(myrank);

  // Specific parameters
  lsrm::BaatzParam params;
  params.m_SpectralWeight = 0.7;
  params.m_ShapeWeight = 0.3;
  controller.SetSpecificParameters(params);
  controller.SetThreshold(60*60);

  controller.RunSegmentation();

  MPI_Finalize();
  return 0;
74
}