Commit 273d9b6a authored by remi cresson's avatar remi cresson

ENH: raffale patch for no-data

parent 70a3f75e
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include <otbImageFileReader.h> #include <otbImageFileReader.h>
#include <itkImageRegionIterator.h> #include <itkImageRegionIterator.h>
#include "grmBaatzSegmenter.h" #include "grmBaatzSegmenter.h"
#include "otbNoDataHelper.h"
namespace grm namespace grm
{ {
...@@ -33,22 +34,32 @@ namespace grm ...@@ -33,22 +34,32 @@ namespace grm
this->m_ImageWidth = this->m_InputImage->GetLargestPossibleRegion().GetSize()[0]; this->m_ImageWidth = this->m_InputImage->GetLargestPossibleRegion().GetSize()[0];
this->m_ImageHeight =this->m_InputImage->GetLargestPossibleRegion().GetSize()[1]; this->m_ImageHeight =this->m_InputImage->GetLargestPossibleRegion().GetSize()[1];
this->m_NumberOfComponentsPerPixel = this->m_InputImage->GetNumberOfComponentsPerPixel(); this->m_NumberOfComponentsPerPixel = this->m_InputImage->GetNumberOfComponentsPerPixel();
std::vector<bool> noDataFlags;
std::vector<double> noDataValues;
bool noDataPresent = otb::ReadNoDataFlags(this->m_InputImage->GetMetaDataDictionary(),noDataFlags,noDataValues);
std::size_t idx = 0; std::size_t idx = 0;
ImageIterator it(this->m_InputImage, this->m_InputImage->GetLargestPossibleRegion()); ImageIterator it(this->m_InputImage, this->m_InputImage->GetLargestPossibleRegion());
for(it.GoToBegin(); !it.IsAtEnd(); ++it) for(it.GoToBegin(); !it.IsAtEnd(); ++it)
{ {
this->m_Graph.m_Nodes[idx]->m_Means.reserve(this->m_NumberOfComponentsPerPixel);
this->m_Graph.m_Nodes[idx]->m_SquareMeans.reserve(this->m_NumberOfComponentsPerPixel); if (noDataPresent && otb::IsNoData<double>(it.Get(),noDataFlags,noDataValues)) {
this->m_Graph.m_Nodes[idx]->m_SpectralSum.reserve(this->m_NumberOfComponentsPerPixel); this->m_Graph.m_Nodes[idx]->m_Expired = true;
this->m_Graph.m_Nodes[idx]->m_Std.assign(this->m_NumberOfComponentsPerPixel, 0.0f); } else {
for(std::size_t b = 0; b < this->m_NumberOfComponentsPerPixel; ++b) this->m_Graph.m_Nodes[idx]->m_Means.reserve(this->m_NumberOfComponentsPerPixel);
{ this->m_Graph.m_Nodes[idx]->m_SquareMeans.reserve(this->m_NumberOfComponentsPerPixel);
this->m_Graph.m_Nodes[idx]->m_Means.push_back(it.Get()[b]); this->m_Graph.m_Nodes[idx]->m_SpectralSum.reserve(this->m_NumberOfComponentsPerPixel);
this->m_Graph.m_Nodes[idx]->m_SquareMeans.push_back((it.Get()[b])*(it.Get()[b])); this->m_Graph.m_Nodes[idx]->m_Std.assign(this->m_NumberOfComponentsPerPixel, 0.0f);
this->m_Graph.m_Nodes[idx]->m_SpectralSum.push_back(it.Get()[b]);
} for(std::size_t b = 0; b < this->m_NumberOfComponentsPerPixel; ++b)
{
this->m_Graph.m_Nodes[idx]->m_Means.push_back(it.Get()[b]);
this->m_Graph.m_Nodes[idx]->m_SquareMeans.push_back((it.Get()[b])*(it.Get()[b]));
this->m_Graph.m_Nodes[idx]->m_SpectralSum.push_back(it.Get()[b]);
}
}
++idx; ++idx;
} }
} }
......
...@@ -62,6 +62,8 @@ namespace grm ...@@ -62,6 +62,8 @@ namespace grm
seg.m_Graph.m_Nodes.push_back(n); seg.m_Graph.m_Nodes.push_back(n);
} }
seg.InitFromImage();
if(mask == FOUR) if(mask == FOUR)
{ {
...@@ -71,7 +73,7 @@ namespace grm ...@@ -71,7 +73,7 @@ namespace grm
FOURNeighborhood(neighborhood, r->m_Id, width, height); FOURNeighborhood(neighborhood, r->m_Id, width, height);
for(short j = 0; j < 4; ++j) for(short j = 0; j < 4; ++j)
{ {
if(neighborhood[j] > -1) if(neighborhood[j] > -1 && !seg.m_Graph.m_Nodes[neighborhood[j]]->m_Expired)
r->m_Edges.push_back(EdgeType( seg.m_Graph.m_Nodes[neighborhood[j]], 0, 1)); r->m_Edges.push_back(EdgeType( seg.m_Graph.m_Nodes[neighborhood[j]], 0, 1));
} }
} }
...@@ -84,7 +86,7 @@ namespace grm ...@@ -84,7 +86,7 @@ namespace grm
EIGHTNeighborhood(neighborhood, r->m_Id, width, height); EIGHTNeighborhood(neighborhood, r->m_Id, width, height);
for(short j = 0; j < 8; ++j) for(short j = 0; j < 8; ++j)
{ {
if(neighborhood[j] > -1) if(neighborhood[j] > -1 && !seg.m_Graph.m_Nodes[neighborhood[j]]->m_Expired)
{ {
if(j % 2 > 0) if(j % 2 > 0)
r->m_Edges.push_back(EdgeType( seg.m_Graph.m_Nodes[neighborhood[j]], 0, 0)); r->m_Edges.push_back(EdgeType( seg.m_Graph.m_Nodes[neighborhood[j]], 0, 0));
...@@ -94,7 +96,9 @@ namespace grm ...@@ -94,7 +96,9 @@ namespace grm
} }
} }
} }
seg.InitFromImage();
RemoveExpiredNodes(seg.m_Graph);
} }
template<class TSegmenter> template<class TSegmenter>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment