-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathGRMSegmenterTemplate.txx
97 lines (78 loc) · 3.67 KB
/
GRMSegmenterTemplate.txx
1
2
3
4
5
6
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
34
35
36
37
38
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*=========================================================================
Program: Generic Region Merging Library
Language: C++
author: Lassalle Pierre
contact: lassallepierre34@gmail.com
Copyright (c) Centre National d'Etudes Spatiales. All rights reserved
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
Template Model to help the developper to add a new criterion
This file as well as his corresponding txx file has to be added
src folder.
=========================================================================*/
#ifndef __GRM_MYSEGMENTER_TXX
#define __GRM_MYSEGMENTER_TXX
#include <otbImageFileReader.h>
#include <itkImageRegionIterator.h>
/*
Important to read:
The graph of segments can be accessed like this: this->m_Graph
The number of segments in the graph: this->m_Graph.size()
To access to the segment pointer at the position idx: this->m_Graph.m_Nodes[idx]
For each segment pointer you can used the following attributes:
this->m_Graph.m_Nodes[idx]->m_Perimeter // Perimeter of the segment.
this->m_Graph.m_Nodes[idx]->m_Area // Number of pixels contained in the segment.
this->m_Graph.m_Nodes[idx]->m_Bbox // Bounding box of the segment:
this->m_Graph.m_Nodes[idx]->m_Bbox.m_UX : upper left x coordinate
this->m_Graph.m_Nodes[idx]->m_Bbox.m_UY : upper left y coordinate
this->m_Graph.m_Nodes[idx]->m_Bbox.m_W : width
this->m_Graph.m_Nodes[idx]->m_Bbox.m_UX : height
this->m_Graph.m_Nodes[idx]->m_Contour: moves along the contour of the segment:
To generate the set of the coordinates of the border pixels:
lp::CellLists borderPixels; // (std::unordered_set<long unsigned int>)
lp::ContourOperations::GenerateBorderCells(borderPixels, this->m_Graph.m_Nodes[idx]->m_Contour, this->m_Graph.m_Nodes[idx]->m_Id, this->m_ImageWidth);
this->m_Graph.m_Nodes[idx]->m_Edges // std::vector<EdgeType> containing edges to adjacent segment
Given an edge e:
e.GetRegion() : access to the adjacent segment pointer.
e.m_Boundary : lenght of the border between the current segment and the adjacent segment.
e.m_Cost: merging cost between the current segment and the adjacent segment.
*/
namespace grm
{
template<class TImage>
void
MySegmenter<TImage>::InitFromImage()
{
typedef itk::ImageRegionIterator<TImage> ImageIterator;
this->m_ImageWidth = this->m_InputImage->GetLargestPossibleRegion().GetSize()[0];
this->m_ImageHeight =this->m_InputImage->GetLargestPossibleRegion().GetSize()[1];
this->m_NumberOfComponentsPerPixel = this->m_InputImage->GetNumberOfComponentsPerPixel();
std::size_t idx = 0;
ImageIterator it(this->m_InputImage, this->m_InputImage->GetLargestPossibleRegion());
for(it.GoToBegin(); !it.IsAtEnd(); ++it)
{
// Initialize your specific attributes for each pixel of the image.
for(std::size_t b = 0; b < this->m_NumberOfComponentsPerPixel; ++b)
{
// Initialize your specific attributes if they depend on spectral values of pixels.
}
++idx;
}
}
template<class TImage>
float
MySegmenter<TImage>::ComputeMergingCost(NodePointerType n1, NodePointerType n2)
{
// Determine how to compute the merging cost between the two adjacent segments.
}
template<class TImage>
void
MySegmenter<TImage>::UpdateSpecificAttributes(NodePointerType n1, NodePointerType n2)
{
// Determine how to update your specif attributes when segment n2 is merged into segment n1.
// This means that you have to update the specific attributes of segment n1 according to
// the specific attributes of segments n1 and n2.
}
} // end of namespace grm
#endif