Commit 273d9b6aaac1e30b27e8abfbbdfb9c665cd166b5

Authored by Rémi Cresson (IRSTEA)
1 parent 70a3f75e
Exists in master

ENH: raffale patch for no-data

include/grmBaatzSegmenter.txx
... ... @@ -20,6 +20,7 @@
20 20 #include <otbImageFileReader.h>
21 21 #include <itkImageRegionIterator.h>
22 22 #include "grmBaatzSegmenter.h"
  23 +#include "otbNoDataHelper.h"
23 24  
24 25 namespace grm
25 26 {
... ... @@ -33,22 +34,32 @@ namespace grm
33 34 this->m_ImageWidth = this->m_InputImage->GetLargestPossibleRegion().GetSize()[0];
34 35 this->m_ImageHeight =this->m_InputImage->GetLargestPossibleRegion().GetSize()[1];
35 36 this->m_NumberOfComponentsPerPixel = this->m_InputImage->GetNumberOfComponentsPerPixel();
  37 +
  38 + std::vector<bool> noDataFlags;
  39 + std::vector<double> noDataValues;
  40 + bool noDataPresent = otb::ReadNoDataFlags(this->m_InputImage->GetMetaDataDictionary(),noDataFlags,noDataValues);
36 41  
37 42 std::size_t idx = 0;
38 43 ImageIterator it(this->m_InputImage, this->m_InputImage->GetLargestPossibleRegion());
39 44 for(it.GoToBegin(); !it.IsAtEnd(); ++it)
40 45 {
41   - this->m_Graph.m_Nodes[idx]->m_Means.reserve(this->m_NumberOfComponentsPerPixel);
42   - this->m_Graph.m_Nodes[idx]->m_SquareMeans.reserve(this->m_NumberOfComponentsPerPixel);
43   - this->m_Graph.m_Nodes[idx]->m_SpectralSum.reserve(this->m_NumberOfComponentsPerPixel);
44   - this->m_Graph.m_Nodes[idx]->m_Std.assign(this->m_NumberOfComponentsPerPixel, 0.0f);
45   -
46   - for(std::size_t b = 0; b < this->m_NumberOfComponentsPerPixel; ++b)
47   - {
48   - this->m_Graph.m_Nodes[idx]->m_Means.push_back(it.Get()[b]);
49   - this->m_Graph.m_Nodes[idx]->m_SquareMeans.push_back((it.Get()[b])*(it.Get()[b]));
50   - this->m_Graph.m_Nodes[idx]->m_SpectralSum.push_back(it.Get()[b]);
51   - }
  46 +
  47 + if (noDataPresent && otb::IsNoData<double>(it.Get(),noDataFlags,noDataValues)) {
  48 + this->m_Graph.m_Nodes[idx]->m_Expired = true;
  49 + } else {
  50 +
  51 + this->m_Graph.m_Nodes[idx]->m_Means.reserve(this->m_NumberOfComponentsPerPixel);
  52 + this->m_Graph.m_Nodes[idx]->m_SquareMeans.reserve(this->m_NumberOfComponentsPerPixel);
  53 + this->m_Graph.m_Nodes[idx]->m_SpectralSum.reserve(this->m_NumberOfComponentsPerPixel);
  54 + this->m_Graph.m_Nodes[idx]->m_Std.assign(this->m_NumberOfComponentsPerPixel, 0.0f);
  55 +
  56 + for(std::size_t b = 0; b < this->m_NumberOfComponentsPerPixel; ++b)
  57 + {
  58 + this->m_Graph.m_Nodes[idx]->m_Means.push_back(it.Get()[b]);
  59 + this->m_Graph.m_Nodes[idx]->m_SquareMeans.push_back((it.Get()[b])*(it.Get()[b]));
  60 + this->m_Graph.m_Nodes[idx]->m_SpectralSum.push_back(it.Get()[b]);
  61 + }
  62 + }
52 63 ++idx;
53 64 }
54 65 }
... ...
include/grmGraphOperations.txx
... ... @@ -62,6 +62,8 @@ namespace grm
62 62  
63 63 seg.m_Graph.m_Nodes.push_back(n);
64 64 }
  65 +
  66 + seg.InitFromImage();
65 67  
66 68 if(mask == FOUR)
67 69 {
... ... @@ -71,7 +73,7 @@ namespace grm
71 73 FOURNeighborhood(neighborhood, r->m_Id, width, height);
72 74 for(short j = 0; j < 4; ++j)
73 75 {
74   - if(neighborhood[j] > -1)
  76 + if(neighborhood[j] > -1 && !seg.m_Graph.m_Nodes[neighborhood[j]]->m_Expired)
75 77 r->m_Edges.push_back(EdgeType( seg.m_Graph.m_Nodes[neighborhood[j]], 0, 1));
76 78 }
77 79 }
... ... @@ -84,7 +86,7 @@ namespace grm
84 86 EIGHTNeighborhood(neighborhood, r->m_Id, width, height);
85 87 for(short j = 0; j < 8; ++j)
86 88 {
87   - if(neighborhood[j] > -1)
  89 + if(neighborhood[j] > -1 && !seg.m_Graph.m_Nodes[neighborhood[j]]->m_Expired)
88 90 {
89 91 if(j % 2 > 0)
90 92 r->m_Edges.push_back(EdgeType( seg.m_Graph.m_Nodes[neighborhood[j]], 0, 0));
... ... @@ -94,7 +96,9 @@ namespace grm
94 96 }
95 97 }
96 98 }
97   - seg.InitFromImage();
  99 +
  100 + RemoveExpiredNodes(seg.m_Graph);
  101 +
98 102 }
99 103  
100 104 template<class TSegmenter>
... ...