lsgrmGraphOperations.h 5.6 KB
Newer Older
1
2
#ifndef __LSGRM_GRAPH_OPERATIONS_H
#define __LSGRM_GRAPH_OPERATIONS_H
remicres's avatar
remicres committed
3

4
#include "lsgrmHeader.h"
5
#include "grmGraphOperations.h"
remicres's avatar
remicres committed
6
7
#include "otbVectorImage.h"
#include "otbMultiChannelExtractROI.h"
8
9
10

namespace lsgrm
{
remicres's avatar
remicres committed
11
12
13
14
15
16

struct ProcessingTile
{
  long int rows[2]; // lower and upper rows (-1 means that the row has not be considered)
  long int columns[2]; // lower and upper columns (-1 means that the row has not be considered)
  long int tileNeighbors[8]; // tile Neighbors at (top, top right, right, bottom right, bottom, bottom left, left, top left)
remicres's avatar
remicres committed
17
  long int margin[4]; // Is there a margin at top, left, bottom or right
remicres's avatar
remicres committed
18
  otb::VectorImage<double>::RegionType region; // The image region
19
20
21
22
23
24

  // Temporary files
  std::string nodeFileName;
  std::string edgeFileName;
  std::string nodeMarginFileName;
  std::string edgeMarginFileName;
remicres's avatar
remicres committed
25
26
27
28
29
30
31
32
33
};

// Read an image region
template<class TSegmenter>
typename TSegmenter::ImageType::Pointer ReadImageRegion(
    typename TSegmenter::ImageType * inputPtr,
    typename TSegmenter::ImageType::RegionType region);

template<class TSegmenter>
34
typename TSegmenter::GraphType
remicres's avatar
remicres committed
35
MergeAllGraphsAndAchieveSegmentation(
36
    const typename TSegmenter::ParamType& params,
remicres's avatar
remicres committed
37
38
39
40
41
42
    const float& threshold,
    std::vector<ProcessingTile>& tiles,
    const unsigned int nbTilesX,
    const unsigned int nbTilesY,
    const unsigned int imageWidth,
    const unsigned int imageHeight,
43
44
    const unsigned int imageBands,
    unsigned int numberOfIterations);
remicres's avatar
remicres committed
45
46
47
48

template<class TSegmenter>
long long unsigned int RunFirstPartialSegmentation(
    typename TSegmenter::ImageType * inputPtr,
49
    const typename TSegmenter::ParamType& params,
remicres's avatar
remicres committed
50
51
52
53
54
55
56
57
58
59
60
61
    const float& threshold,
    const unsigned int niter,
    const unsigned int niter2,
    std::vector<ProcessingTile>& tiles,
    const unsigned int nbTilesX,
    const unsigned int nbTilesY,
    const unsigned int tileWidth,
    const unsigned int tileHeight,
    bool& isFusion);

template<class TSegmenter>
long long unsigned int RunPartialSegmentation(
62
    const typename TSegmenter::ParamType& params,
remicres's avatar
remicres committed
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
    const float& threshold,
    const unsigned int niter,
    std::vector<ProcessingTile>& tiles,
    const unsigned int nbTilesX,
    const unsigned int nbTilesY,
    const unsigned int imageWidth,
    const unsigned int imageHeight,
    const unsigned int imageBands,
    bool& isFusion);

template<class TSegmenter>
void RemoveUselessNodes(ProcessingTile& tile,
    typename TSegmenter::GraphType& graph,
    const unsigned int imageWidth,
    const unsigned int numberOfLayers);


template<class TSegmenter>
81
void UpdateNeighborsOfNoneDuplicatedNodes(std::unordered_map<std::size_t,
remicres's avatar
remicres committed
82
83
84
85
86
    std::vector<typename TSegmenter::NodePointerType> >& borderPixelMap,
    const unsigned int imageWidth,
    const unsigned int imageHeight);

template<class TSegmenter>
87
void RemoveDuplicatedNodes(std::unordered_map<std::size_t,
remicres's avatar
remicres committed
88
89
90
91
92
93
94
95
96
97
98
    std::vector<typename TSegmenter::NodePointerType> >& borderPixelMap,
    typename TSegmenter::GraphType& graph,
    const unsigned int imageWidth);

template<class TSegmenter>
void BuildBorderPixelMap(typename TSegmenter::GraphType& graph,
    ProcessingTile& tile,
    const unsigned int rowTile,
    const unsigned int colTile,
    const unsigned int nbTilesX,
    const unsigned int nbTilesY,
99
    std::unordered_map<std::size_t,
remicres's avatar
remicres committed
100
101
102
    std::vector<typename TSegmenter::NodePointerType> >& borderPixelMap,
    const unsigned int imageWidth);

103
104
105
106
template<class TSegmenter>
void InsertNodesFromTile(typename TSegmenter::GraphType& graph,
    ProcessingTile& tile, bool margin = true);

remicres's avatar
remicres committed
107
108
template<class TSegmenter>
void AddStabilityMargin(typename TSegmenter::GraphType& graph,
109
    std::vector<ProcessingTile>& tiles,
remicres's avatar
remicres committed
110
111
112
    const unsigned int row,
    const unsigned int col,
    const unsigned int nbTilesX,
remicres's avatar
remicres committed
113
    const unsigned int nbTilesY);
remicres's avatar
remicres committed
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139

template<class TSegmenter>
void WriteStabilityMargin(std::unordered_map<
    typename TSegmenter::NodePointerType,
    unsigned int>& stabilityMargin,
    const std::string& nodesPath,
    const std::string& edgesPath);

template<class TSegmenter>
void ExtractStabilityMargin(std::unordered_map<typename TSegmenter::NodePointerType, unsigned int>& nodeMap,
    const unsigned int pmax);

template<class TSegmenter>
void ExploreDFS(typename TSegmenter::NodePointerType s,
    const unsigned int p,
    std::unordered_map<typename TSegmenter::NodePointerType, unsigned int>& Cb,
    const unsigned int pmax);

template<class TSegmenter>
void DetectBorderNodes(typename TSegmenter::GraphType& graph,
    ProcessingTile& tile,
    std::unordered_map<typename TSegmenter::NodePointerType, unsigned int>& borderNodeMaps,
    const unsigned int imageWidth,
    const unsigned int imageHeight);

template<class TSegmenter>
140
void ReadGraph(TSegmenter& segmenter,
remicres's avatar
remicres committed
141
142
143
144
    const std::string& nodesPath,
    const std::string& edgesPath);

template<class TSegmenter>
145
146
147
void ReadGraph(typename TSegmenter::GraphType& graph,
    const std::string& nodesPath,
    const std::string& edgesPath);
remicres's avatar
remicres committed
148
149

template<class TSegmenter>
150
151
152
void WriteGraph(typename TSegmenter::GraphType& graph,
    const std::string& nodesFile,
    const std::string& edgesFile);
remicres's avatar
remicres committed
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169

template<class TSegmenter>
void RemoveUnstableSegments(typename TSegmenter::GraphType& graph,
    ProcessingTile& tile,
    const unsigned int imageWidth);

template<class TSegmenter>
void RemoveEdgeToUnstableNode(typename TSegmenter::NodePointerType nodePtr);

template<class TSegmenter>
void RescaleGraph(typename TSegmenter::GraphType& graph,
    ProcessingTile& tile,
    const unsigned int rowTile,
    const unsigned int colTile,
    const unsigned int tileWidth,
    const unsigned int tileHeight,
    const unsigned int imageWidth);
170
171
172
173
}

#include "lsgrmGraphOperations.txx"
#endif