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

REFAC: refactorisation segmenter

parent 273d9b6a
......@@ -43,6 +43,7 @@ namespace grm
/* Some convenient typedefs */
typedef Segmenter<TImage, BaatzNode, BaatzParam> Superclass;
typedef TImage ImageType;
typedef typename ImageType::PixelType PixelType;
typedef BaatzParam ParameterType;
typedef typename Superclass::GraphType GraphType;
typedef BaatzNode NodeType;
......@@ -53,8 +54,8 @@ namespace grm
float ComputeMergingCost(NodePointerType n1, NodePointerType n2);
void UpdateSpecificAttributes(NodePointerType n1, NodePointerType n2);
void InitFromImage();
void UpdateSpecificAttributes(NodePointerType n, PixelType p);
};
} // end of namespace grm
#include "grmBaatzSegmenter.txx"
#endif
\ No newline at end of file
#endif
......@@ -17,52 +17,28 @@
=========================================================================*/
#ifndef GRM_BAATZ_SEGMENTER_TXX
#define GRM_BAATZ_SEGMENTER_TXX
#include <otbImageFileReader.h>
#include <itkImageRegionIterator.h>
#include "grmBaatzSegmenter.h"
#include "otbNoDataHelper.h"
namespace grm
{
template<class TImage>
void
BaatzSegmenter<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::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 {
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>
void
BaatzSegmenter<TImage>::UpdateSpecificAttributes(NodePointerType n, PixelType p)
{
n->m_Means.reserve(p.GetSize());
n->m_SquareMeans.reserve(p.GetSize());
n->m_SpectralSum.reserve(p.GetSize());
n->m_Std.assign(p.GetSize(), 0.0f);
for(std::size_t b = 0; b < p.GetSize(); ++b)
{
n->m_Means.push_back(p[b]);
n->m_SquareMeans.push_back((p[b])*(p[b]));
n->m_SpectralSum.push_back(p[b]);
}
}
template<class TImage>
float
......@@ -128,4 +104,4 @@ namespace grm
}
} // end of namespace grm
#endif
\ No newline at end of file
#endif
......@@ -35,6 +35,8 @@ namespace grm
/* Some convenient typedefs */
typedef Segmenter<TImage, FLSNode, FLSParam> Superclass;
typedef TImage ImageType;
typedef typename ImageType::PixelType PixelType;
typedef typename Superclass::GraphType GraphType;
typedef typename Superclass::NodePointerType NodePointerType;
typedef typename Superclass::GraphOperatorType GraphOperatorType;
......@@ -42,8 +44,8 @@ namespace grm
float ComputeMergingCost(NodePointerType n1, NodePointerType n2);
void UpdateSpecificAttributes(NodePointerType n1, NodePointerType n2);
void InitFromImage();
void UpdateSpecificAttributes(NodePointerType n, PixelType p);
};
} // end of namespace grm
#include "grmFullLambdaScheduleSegmenter.txx"
#endif
\ No newline at end of file
#endif
......@@ -22,29 +22,19 @@
namespace grm
{
template<class TImage>
void
FullLambdaScheduleSegmenter<TImage>::InitFromImage()
{
typedef itk::ImageRegionIterator<TImage> ImageIterator;
template<class TImage>
void
FullLambdaScheduleSegmenter<TImage>::UpdateSpecificAttributes(NodePointerType n, PixelType p)
{
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();
n->m_Means.reserve(p.GetSize());
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 < p.GetSize(); ++b)
{
n->m_Means.push_back(p[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]);
}
++idx;
}
}
}
template<class TImage>
float
......
......@@ -20,6 +20,9 @@
#include "grmMacroGenerator.h"
#include "grmGraphOperations.h"
#include "grmGraphToOtbImage.h"
#include <otbImageFileReader.h>
#include <itkImageRegionIterator.h>
#include "otbNoDataHelper.h"
namespace grm
{
......@@ -32,6 +35,7 @@ namespace grm
typedef Segmenter<TImage, TNode, TParam> Self;
typedef TImage ImageType;
typedef typename ImageType::PixelType PixelType;
typedef TNode NodeType;
typedef TParam ParamType;
typedef Graph<NodeType> GraphType;
......@@ -97,14 +101,51 @@ namespace grm
*/
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
* 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 */
inline typename LabelImageType::Pointer GetLabeledClusteredOutput()
......@@ -170,4 +211,4 @@ namespace grm
};
} // end of namespace grm
#endif
\ No newline at end of file
#endif
......@@ -35,6 +35,8 @@ namespace grm
/* Some convenient typedefs */
typedef Segmenter<TImage, SpringNode, SpringParam> Superclass;
typedef TImage ImageType;
typedef typename ImageType::PixelType PixelType;
typedef typename Superclass::GraphType GraphType;
typedef typename Superclass::NodePointerType NodePointerType;
typedef typename Superclass::GraphOperatorType GraphOperatorType;
......@@ -42,7 +44,7 @@ namespace grm
float ComputeMergingCost(NodePointerType n1, NodePointerType n2);
void UpdateSpecificAttributes(NodePointerType n1, NodePointerType n2);
void InitFromImage();
void UpdateSpecificAttributes(NodePointerType n, PixelType p);
};
} // end of namespace grm
#include "grmSpringSegmenter.txx"
......
......@@ -26,26 +26,14 @@ namespace grm
template<class TImage>
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];
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)
for(std::size_t b = 0; b < p.GetSize(); ++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>
......
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