lsgrmBaatzSegmenter.txx 2.06 KB
Newer Older
1
2
3
4
5
#ifndef __LSRM_BAATZ_SEGMENTER_TXX
#define __LSRM_BAATZ_SEGMENTER_TXX
#include <otbImageFileReader.h>
#include <itkImageRegionIterator.h>

remicres's avatar
remicres committed
6
namespace lsgrm
7
8
{

remicres's avatar
remicres committed
9
10
11
12
13
14
15
16
template<class TImage>
void
BaatzSegmenter<TImage>::WriteSpecificAttributes(NodePointerType node, FILE * nodeStream)
{
  std::size_t bands = node->m_Means.size();
  fwrite(&(bands), sizeof(bands), 1, nodeStream);

  for(unsigned int b = 0; b < node->m_Means.size(); b++)
17
    {
remicres's avatar
remicres committed
18
19
20
21
    fwrite(&(node->m_Means[b]), sizeof(node->m_Means[b]), 1, nodeStream);
    fwrite(&(node->m_SquareMeans[b]), sizeof(node->m_SquareMeans[b]), 1, nodeStream);
    fwrite(&(node->m_SpectralSum[b]), sizeof(node->m_SpectralSum[b]), 1, nodeStream);
    fwrite(&(node->m_Std[b]), sizeof(node->m_Std[b]), 1, nodeStream);
22
    }
remicres's avatar
remicres committed
23
}
24

remicres's avatar
remicres committed
25
26
27
28
29
30
31
32
33
34
35
36
template<class TImage>
void
BaatzSegmenter<TImage>::ReadSpecificAttributes(NodePointerType node, FILE * nodeStream)
{
  std::size_t bands;
  fread(&(bands), sizeof(bands), 1, nodeStream);
  node->m_Means.assign(bands, 0);
  node->m_SquareMeans.assign(bands, 0);
  node->m_SpectralSum.assign(bands, 0);
  node->m_Std.assign(bands, 0);

  for(unsigned int b = 0; b < bands; b++)
37
    {
remicres's avatar
remicres committed
38
39
40
41
42
43
    fread(&(node->m_Means[b]), sizeof(node->m_Means[b]), 1, nodeStream);
    fread(&(node->m_SquareMeans[b]), sizeof(node->m_SquareMeans[b]), 1, nodeStream);
    fread(&(node->m_SpectralSum[b]), sizeof(node->m_SpectralSum[b]), 1, nodeStream);
    fread(&(node->m_Std[b]), sizeof(node->m_Std[b]), 1, nodeStream);
    }
}
44

remicres's avatar
remicres committed
45
46
47
48
template<class TImage>
long long unsigned int
BaatzSegmenter<TImage>::GetNodeMemory(NodePointerType &node)
{
49

remicres's avatar
remicres committed
50
51
52
53
54
55
56
57
58
  unsigned int nBands = node->m_Means.size(); //this->m_InputImage->GetNumberOfComponentsPerPixel();

  long long unsigned int memory = 0;
  memory += sizeof(NodePointerType);    // size of the node pointer
  memory += sizeof(NodeType);           // size of the node (actually, size of the base node)
  memory += 4 * nBands * sizeof(float); // size of the 4 attributes, multiplied by the nb. of bands
  memory += node->m_Edges.size() * sizeof(EdgeType);  // size of the edges
  return memory;
}
59
60
61
62
63
64
65
66
67
68
} // end of namespace lsrm

#endif