18 #ifndef __otbLineDetectorImageFilterBase_txx
19 #define __otbLineDetectorImageFilterBase_txx
42 template <
class TInputImage,
class TOutputImage,
class TOutputImageDirection,
class InterpolatorType>
46 this->SetNumberOfOutputs(2);
47 this->SetNumberOfRequiredOutputs(1);
52 m_NumberOfDirections = 4;
59 template <
class TInputImage,
class TOutputImage,
class TOutputImageDirection,
class InterpolatorType>
65 Superclass::GenerateInputRequestedRegion();
71 if (!inputPtr || !outputPtr)
78 typename TInputImage::RegionType inputRequestedRegion;
79 inputRequestedRegion = inputPtr->GetRequestedRegion();
82 m_Radius[1] =
static_cast<unsigned int>(3 * (2 * m_WidthLine + 1) + 2);
83 m_Radius[0] = 2 * m_LengthLine + 1;
87 static_cast<unsigned int>(vcl_sqrt(static_cast<double>(
88 (m_Radius[0] * m_Radius[0]) + (m_Radius[1] * m_Radius[1]))) + 1);
89 m_FaceList[1] = m_FaceList[0];
91 otbMsgDevMacro(<<
"Radius : " << m_Radius[0] <<
" " << m_Radius[1]);
92 otbMsgDevMacro(<<
"-> FaceList : " << m_FaceList[0] <<
" " << m_FaceList[1]);
95 inputRequestedRegion.PadByRadius(m_FaceList);
98 if (inputRequestedRegion.Crop(inputPtr->GetLargestPossibleRegion()))
100 inputPtr->SetRequestedRegion(inputRequestedRegion);
109 inputPtr->SetRequestedRegion(inputRequestedRegion);
113 std::ostringstream msg;
114 msg << static_cast<const char *>(this->GetNameOfClass())
115 <<
"::GenerateInputRequestedRegion()";
117 e.
SetDescription(
"Requested region is (at least partially) outside the largest possible region.");
128 template <
class TInputImage,
class TOutputImage,
class TOutputImageDirection,
class InterpolatorType>
133 typename OutputImageType::Pointer output = this->GetOutput();
134 output->FillBuffer(0);
135 typename OutputImageType::Pointer outputDirection = this->GetOutputDirection();
136 outputDirection->FillBuffer(0);
139 template <
class TInputImage,
class TOutputImage,
class TOutputImageDirection,
class InterpolatorType>
148 typename InputImageType::ConstPointer input = this->GetInput();
151 interpolator2->SetInputImage(input);
162 typename OutputImageType::Pointer output = this->GetOutput();
163 typename OutputImageType::Pointer outputDir = this->GetOutputDirection();
170 faceList = bC(input, outputRegionForThread, m_FaceList);
175 typename TInputImage::IndexType bitIndex;
176 typename InterpolatorType::ContinuousIndexType Index;
181 const unsigned int NB_DIR = this->GetNumberOfDirections();
183 const int NB_ZONE = 3;
187 double* Theta =
new double[NB_DIR];
190 for (
unsigned int i = 0; i < NB_DIR; ++i)
192 Theta[i] = (
CONST_PI * (i / double(NB_DIR)));
206 double Direction = 0.;
221 otbMsgDevMacro(<<
"Theta : " << Theta[0] <<
" " << Theta[1] <<
" " << Theta[2] <<
" " << Theta[3]);
226 bool interiorFace =
true;
228 for (fit = faceList.begin(); fit != faceList.end(); ++fit)
241 otbMsgDevMacro(<<
" ------------------- FaceList --------------------------");
256 interpolator->SetInputImage(input);
262 typename InputImageType::RegionType tempRegion;
263 typename InputImageType::SizeType tempSize;
264 tempSize[0] = 2 * m_FaceList[0] + 1;
265 tempSize[1] = 2 * m_FaceList[1] + 1;
268 tempIndex[0] = off[0] - m_FaceList[0];
269 tempIndex[1] = off[1] - m_FaceList[1];
270 tempRegion.SetIndex(cit.
GetIndex(tempIndex));
271 typename InputImageType::Pointer tempImage = InputImageType::New();
272 tempImage->SetRegions(tempRegion);
273 tempImage->Allocate();
275 for (
unsigned int p = 0; p <= 2 * m_FaceList[0]; ++p)
277 for (
unsigned int q = 0; q <= 2 * m_FaceList[1]; q++)
280 index[0] = p - m_FaceList[0];
281 index[1] = q - m_FaceList[1];
285 interpolator->SetInputImage(tempImage);
289 Yc12 = Yc - m_WidthLine - 1;
292 Yc13 = Yc + m_WidthLine + 1;
297 std::vector<double>** PixelValues =
NULL;
298 PixelValues =
new std::vector<double>*[NB_DIR];
299 for (
unsigned int i = 0; i < NB_DIR; ++i)
301 PixelValues[i] =
NULL;
302 PixelValues[i] =
new std::vector<double>[NB_ZONE];
306 for (
unsigned int i = 0; i < m_Radius[0]; ++i)
307 for (
unsigned int j = 0; j < m_Radius[1]; ++j)
310 off[0] = i - m_Radius[0] / 2;
311 off[1] = j - m_Radius[1] / 2;
318 if (Y < Yc12) zone = 1;
319 else if ((Yc12 < Y) && (Y < Yc13)) zone = 0;
320 else if (Y > Yc13) zone = 2;
324 for (
unsigned int dir = 0; dir < NB_DIR; ++dir)
328 xout = (X - Xc) * vcl_cos(Theta[dir]) - (Y - Yc) * vcl_sin(Theta[dir]);
329 yout = (X - Xc) * vcl_sin(Theta[dir]) + (Y - Yc) * vcl_cos(Theta[dir]);
334 PixelValues[dir][zone].push_back(static_cast<double>(interpolator->EvaluateAtContinuousIndex(Index)));
343 for (
unsigned int dir = 0; dir < NB_DIR; ++dir)
346 double Rtemp = this->ComputeMeasure(&PixelValues[dir][0], &PixelValues[dir][1], &PixelValues[dir][2]);
351 Direction = Theta[dir];
357 if (R >= this->GetThreshold())
361 it.Set(static_cast<OutputPixelType>(R));
364 itdir.
Set(static_cast<OutputPixelType>(Direction));
369 it.Set(itk::NumericTraits<OutputPixelType>::Zero);
371 itdir.
Set(static_cast<OutputPixelType>(0));
377 interiorFace =
false;
378 progress.CompletedPixel();
381 for (
unsigned int i = 0; i < NB_DIR; ++i)
383 delete[] PixelValues[i];
384 PixelValues[i] =
NULL;
386 delete[] PixelValues;
394 template <
class TInputImage,
class TOutputImage,
class TOutputImageDirection,
class InterpolatorType>
397 ::ComputeMeasure(std::vector<double>* m1, std::vector<double>* m2, std::vector<double>* m3)
405 template <
class TInputImage,
class TOutputImage,
class TOutputImageDirection,
class InterpolatorType>
410 Superclass::PrintSelf(os, indent);
411 os << indent <<
"Length: " << m_LengthLine << std::endl;
412 os << indent <<
"Width: " << m_WidthLine << std::endl;