Commit fd1ab505 authored by Cresson Remi's avatar Cresson Remi

ADD: Sampling utils

parent 9c09cc1b
/*
* otbTensorflowSamplingUtils.cxx
*
* Created on: 12 déc. 2018
* Author: remi
*/
#include "otbTensorflowSamplingUtils.h"
namespace otb
{
namespace tf
{
//
// Update the distribution of the patch located at the specified location
//
template<class TImage, class TDistribution>
bool UpdateDistributionFromPatch(const typename TImage::Pointer inPtr,
typename TImage::PointType point, typename TImage::SizeType patchSize,
TDistribution & dist)
{
typename TImage::IndexType index, outIndex;
bool canTransform = inPtr->TransformPhysicalPointToIndex(point, index);
if (canTransform)
{
index[0] -= patchSize[0] / 2;
index[1] -= patchSize[1] / 2;
typename TImage::RegionType inPatchRegion(index, patchSize);
if (inPtr->GetLargestPossibleRegion().IsInside(inPatchRegion))
{
// Fill patch
PropagateRequestedRegion<TImage>(inPtr, inPatchRegion);
typename itk::ImageRegionConstIterator<TImage> inIt (inPtr, inPatchRegion);
for (inIt.GoToBegin(); !inIt.IsAtEnd(); ++inIt)
{
dist.Update(inIt.Get());
}
return true;
}
}
return false;
}
} // namespace tf
} // namespace otb
/*
* otbTensorflowSamplingUtils.h
*
* Created on: 12 déc. 2018
* Author: remi
*/
#ifndef MODULES_REMOTE_OTBTF_INCLUDE_OTBTENSORFLOWSAMPLINGUTILS_H_
#define MODULES_REMOTE_OTBTF_INCLUDE_OTBTENSORFLOWSAMPLINGUTILS_H_
#include "otbTensorflowCommon.h"
#include "otbTensorflowCopyUtils.h"
#include "vnl/vnl_vector.h"
namespace otb
{
namespace tf
{
template<class TImage>
class Distribution
{
public:
typedef typename TImage::PixelValueType ValueType;
typedef typename vnl_vector<unsigned int> CountsType;
Distribution(unsigned int nClasses)
{
m_NbOfClasses = nClasses;
m_Dist = CountsType(nClasses, 0);
}
~Distribution(){}
void Update(const typename TImage::PixelType & pixel)
{
m_Dist[pixel]++;
}
CountsType Get()
{
return m_Dist;
}
private:
unsigned int m_NbOfClasses;
CountsType m_Dist;
};
// Update the distribution of the patch located at the specified location
template<class TImage, class TDistribution>
bool UpdateDistributionFromPatch(const typename TImage::Pointer inPtr,
typename TImage::PointType point, typename TImage::SizeType patchSize,
TDistribution & dist);
} // namesapce tf
} // namespace otb
#endif /* MODULES_REMOTE_OTBTF_INCLUDE_OTBTENSORFLOWSAMPLINGUTILS_H_ */
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