Commit 45a3be1c authored by remi cresson's avatar remi cresson

REFAC: refactorisation segmenter

parent 273d9b6a
...@@ -43,6 +43,7 @@ namespace grm ...@@ -43,6 +43,7 @@ namespace grm
/* Some convenient typedefs */ /* Some convenient typedefs */
typedef Segmenter<TImage, BaatzNode, BaatzParam> Superclass; typedef Segmenter<TImage, BaatzNode, BaatzParam> Superclass;
typedef TImage ImageType; typedef TImage ImageType;
typedef typename ImageType::PixelType PixelType;
typedef BaatzParam ParameterType; typedef BaatzParam ParameterType;
typedef typename Superclass::GraphType GraphType; typedef typename Superclass::GraphType GraphType;
typedef BaatzNode NodeType; typedef BaatzNode NodeType;
...@@ -53,8 +54,8 @@ namespace grm ...@@ -53,8 +54,8 @@ namespace grm
float ComputeMergingCost(NodePointerType n1, NodePointerType n2); float ComputeMergingCost(NodePointerType n1, NodePointerType n2);
void UpdateSpecificAttributes(NodePointerType n1, NodePointerType n2); void UpdateSpecificAttributes(NodePointerType n1, NodePointerType n2);
void InitFromImage(); void UpdateSpecificAttributes(NodePointerType n, PixelType p);
}; };
} // end of namespace grm } // end of namespace grm
#include "grmBaatzSegmenter.txx" #include "grmBaatzSegmenter.txx"
#endif #endif
\ No newline at end of file
...@@ -17,52 +17,28 @@ ...@@ -17,52 +17,28 @@
=========================================================================*/ =========================================================================*/
#ifndef GRM_BAATZ_SEGMENTER_TXX #ifndef GRM_BAATZ_SEGMENTER_TXX
#define GRM_BAATZ_SEGMENTER_TXX #define GRM_BAATZ_SEGMENTER_TXX
#include <otbImageFileReader.h>
#include <itkImageRegionIterator.h>
#include "grmBaatzSegmenter.h" #include "grmBaatzSegmenter.h"
#include "otbNoDataHelper.h"
namespace grm namespace grm
{ {
template<class TImage> template<class TImage>
void void
BaatzSegmenter<TImage>::InitFromImage() BaatzSegmenter<TImage>::UpdateSpecificAttributes(NodePointerType n, PixelType p)
{ {
typedef itk::ImageRegionIterator<TImage> ImageIterator;
n->m_Means.reserve(p.GetSize());
this->m_ImageWidth = this->m_InputImage->GetLargestPossibleRegion().GetSize()[0]; n->m_SquareMeans.reserve(p.GetSize());
this->m_ImageHeight =this->m_InputImage->GetLargestPossibleRegion().GetSize()[1]; n->m_SpectralSum.reserve(p.GetSize());
this->m_NumberOfComponentsPerPixel = this->m_InputImage->GetNumberOfComponentsPerPixel(); n->m_Std.assign(p.GetSize(), 0.0f);
std::vector<bool> noDataFlags; for(std::size_t b = 0; b < p.GetSize(); ++b)
std::vector<double> noDataValues; {
bool noDataPresent = otb::ReadNoDataFlags(this->m_InputImage->GetMetaDataDictionary(),noDataFlags,noDataValues); n->m_Means.push_back(p[b]);
n->m_SquareMeans.push_back((p[b])*(p[b]));
std::size_t idx = 0; n->m_SpectralSum.push_back(p[b]);
ImageIterator it(this->m_InputImage, this->m_InputImage->GetLargestPossibleRegion()); }
for(it.GoToBegin(); !it.IsAtEnd(); ++it) }
{
if (noDataPresent && otb::IsNoData<double>(it.Get(),noDataFlags,noDataValues)) {
this->m_Graph.m_Nodes[idx]->m_Expired = true;
} else {
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_SpectralSum.reserve(this->m_NumberOfComponentsPerPixel);
this->m_Graph.m_Nodes[idx]->m_Std.assign(this->m_NumberOfComponentsPerPixel, 0.0f);
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;
}
}
template<class TImage> template<class TImage>
float float
...@@ -128,4 +104,4 @@ namespace grm ...@@ -128,4 +104,4 @@ namespace grm
} }
} // end of namespace grm } // end of namespace grm
#endif #endif
\ No newline at end of file
...@@ -35,6 +35,8 @@ namespace grm ...@@ -35,6 +35,8 @@ namespace grm
/* Some convenient typedefs */ /* Some convenient typedefs */
typedef Segmenter<TImage, FLSNode, FLSParam> Superclass; typedef Segmenter<TImage, FLSNode, FLSParam> Superclass;
typedef TImage ImageType; typedef TImage ImageType;
typedef typename ImageType::PixelType PixelType;
typedef typename Superclass::GraphType GraphType; typedef typename Superclass::GraphType GraphType;
typedef typename Superclass::NodePointerType NodePointerType; typedef typename Superclass::NodePointerType NodePointerType;
typedef typename Superclass::GraphOperatorType GraphOperatorType; typedef typename Superclass::GraphOperatorType GraphOperatorType;
...@@ -42,8 +44,8 @@ namespace grm ...@@ -42,8 +44,8 @@ namespace grm
float ComputeMergingCost(NodePointerType n1, NodePointerType n2); float ComputeMergingCost(NodePointerType n1, NodePointerType n2);
void UpdateSpecificAttributes(NodePointerType n1, NodePointerType n2); void UpdateSpecificAttributes(NodePointerType n1, NodePointerType n2);
void InitFromImage(); void UpdateSpecificAttributes(NodePointerType n, PixelType p);
}; };
} // end of namespace grm } // end of namespace grm
#include "grmFullLambdaScheduleSegmenter.txx" #include "grmFullLambdaScheduleSegmenter.txx"
#endif #endif
\ No newline at end of file
...@@ -22,29 +22,19 @@ ...@@ -22,29 +22,19 @@
namespace grm namespace grm
{ {
template<class TImage> template<class TImage>
void void
FullLambdaScheduleSegmenter<TImage>::InitFromImage() FullLambdaScheduleSegmenter<TImage>::UpdateSpecificAttributes(NodePointerType n, PixelType p)
{ {
typedef itk::ImageRegionIterator<TImage> ImageIterator;
this->m_ImageWidth = this->m_InputImage->GetLargestPossibleRegion().GetSize()[0]; n->m_Means.reserve(p.GetSize());
this->m_ImageHeight =this->m_InputImage->GetLargestPossibleRegion().GetSize()[1];
this->m_NumberOfComponentsPerPixel = this->m_InputImage->GetNumberOfComponentsPerPixel();
std::size_t idx = 0; for(std::size_t b = 0; b < p.GetSize(); ++b)
ImageIterator it(this->m_InputImage, this->m_InputImage->GetLargestPossibleRegion()); {
for(it.GoToBegin(); !it.IsAtEnd(); ++it) n->m_Means.push_back(p[b]);
{ }
this->m_Graph.m_Nodes[idx]->m_Means.reserve(this->m_NumberOfComponentsPerPixel);
for(std::size_t b = 0; b < this->m_NumberOfComponentsPerPixel; ++b) }
{
this->m_Graph.m_Nodes[idx]->m_Means.push_back(it.Get()[b]);
}
++idx;
}
}
template<class TImage> template<class TImage>
float float
......
...@@ -20,6 +20,9 @@ ...@@ -20,6 +20,9 @@
#include "grmMacroGenerator.h" #include "grmMacroGenerator.h"
#include "grmGraphOperations.h" #include "grmGraphOperations.h"
#include "grmGraphToOtbImage.h" #include "grmGraphToOtbImage.h"
#include <otbImageFileReader.h>
#include <itkImageRegionIterator.h>
#include "otbNoDataHelper.h"
namespace grm namespace grm
{ {
...@@ -32,6 +35,7 @@ namespace grm ...@@ -32,6 +35,7 @@ namespace grm
typedef Segmenter<TImage, TNode, TParam> Self; typedef Segmenter<TImage, TNode, TParam> Self;
typedef TImage ImageType; typedef TImage ImageType;
typedef typename ImageType::PixelType PixelType;
typedef TNode NodeType; typedef TNode NodeType;
typedef TParam ParamType; typedef TParam ParamType;
typedef Graph<NodeType> GraphType; typedef Graph<NodeType> GraphType;
...@@ -97,14 +101,51 @@ namespace grm ...@@ -97,14 +101,51 @@ namespace grm
*/ */
virtual void UpdateSpecificAttributes(NodePointerType n1, NodePointerType n2) = 0; virtual void UpdateSpecificAttributes(NodePointerType n1, NodePointerType n2) = 0;
/*
* Given 1 smart adjacent node pointer (boost::shared_ptr), this
* method updates the customized attributes of the node according
* to the given pixel.
*
* @params
* NodePointerType n : Smart pointer to node
* PixelType p: pixel used for attributes computation
*
*/
virtual void UpdateSpecificAttributes(NodePointerType n, PixelType p) = 0;
/* /*
* Given the input image, this method initializes the * Given the input image, this method initializes the
* internal and specific attributes of the graph. * internal and specific attributes of the graph.
* *
* @params
* const std::string& inputFileName : input image path
*/ */
virtual void InitFromImage() = 0; virtual void InitFromImage()
{
typedef itk::ImageRegionIterator<ImageType> 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::vector<bool> noDataFlags;
std::vector<double> noDataValues;
bool noDataPresent = otb::ReadNoDataFlags(this->m_InputImage->GetMetaDataDictionary(),noDataFlags,noDataValues);
std::size_t idx = 0;
ImageIterator it(this->m_InputImage, this->m_InputImage->GetLargestPossibleRegion());
for(it.GoToBegin(); !it.IsAtEnd(); ++it)
{
if (noDataPresent && otb::IsNoData<double>(it.Get(),noDataFlags,noDataValues))
{
this->m_Graph.m_Nodes[idx]->m_Expired = true;
}
else
{
UpdateSpecificAttributes(this->m_Graph.m_Nodes[idx], it.Get());
}
++idx;
}
}
/* Return the label image */ /* Return the label image */
inline typename LabelImageType::Pointer GetLabeledClusteredOutput() inline typename LabelImageType::Pointer GetLabeledClusteredOutput()
...@@ -170,4 +211,4 @@ namespace grm ...@@ -170,4 +211,4 @@ namespace grm
}; };
} // end of namespace grm } // end of namespace grm
#endif #endif
\ No newline at end of file
...@@ -35,6 +35,8 @@ namespace grm ...@@ -35,6 +35,8 @@ namespace grm
/* Some convenient typedefs */ /* Some convenient typedefs */
typedef Segmenter<TImage, SpringNode, SpringParam> Superclass; typedef Segmenter<TImage, SpringNode, SpringParam> Superclass;
typedef TImage ImageType; typedef TImage ImageType;
typedef typename ImageType::PixelType PixelType;
typedef typename Superclass::GraphType GraphType; typedef typename Superclass::GraphType GraphType;
typedef typename Superclass::NodePointerType NodePointerType; typedef typename Superclass::NodePointerType NodePointerType;
typedef typename Superclass::GraphOperatorType GraphOperatorType; typedef typename Superclass::GraphOperatorType GraphOperatorType;
...@@ -42,7 +44,7 @@ namespace grm ...@@ -42,7 +44,7 @@ namespace grm
float ComputeMergingCost(NodePointerType n1, NodePointerType n2); float ComputeMergingCost(NodePointerType n1, NodePointerType n2);
void UpdateSpecificAttributes(NodePointerType n1, NodePointerType n2); void UpdateSpecificAttributes(NodePointerType n1, NodePointerType n2);
void InitFromImage(); void UpdateSpecificAttributes(NodePointerType n, PixelType p);
}; };
} // end of namespace grm } // end of namespace grm
#include "grmSpringSegmenter.txx" #include "grmSpringSegmenter.txx"
......
...@@ -26,26 +26,14 @@ namespace grm ...@@ -26,26 +26,14 @@ namespace grm
template<class TImage> template<class TImage>
void void
SpringSegmenter<TImage>::InitFromImage() SpringSegmenter<TImage>::UpdateSpecificAttributes(NodePointerType n, PixelType p)
{ {
typedef itk::ImageRegionIterator<TImage> ImageIterator; n->m_Means.reserve(p.GetSize());
this->m_ImageWidth = this->m_InputImage->GetLargestPossibleRegion().GetSize()[0]; for(std::size_t b = 0; b < p.GetSize(); ++b)
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)
{
this->m_Graph.m_Nodes[idx]->m_Means.reserve(this->m_NumberOfComponentsPerPixel);
for(std::size_t b = 0; b < this->m_NumberOfComponentsPerPixel; ++b)
{ {
this->m_Graph.m_Nodes[idx]->m_Means.push_back(it.Get()[b]); n->m_Means.push_back(p[b]);
} }
++idx;
}
} }
template<class TImage> template<class TImage>
......
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