예제 #1
0
void ImageProximityFFT::PrepareFor(ImageBase& Source, Image& Template)
{
   SSize size;

   size.Width = Source.Width();
   size.Height = Source.Height();

   if (m_image_sqsums == nullptr || m_image_sqsums->Width() < size.Width || m_image_sqsums->Height() < size.Height)
      m_image_sqsums = std::make_shared<TempImage>(*m_CL, size, SImage::F32, Source.NbChannels());


   // Size of the FFT input and output
   size.Width = Source.Width() + Template.Width() / 2;
   size.Height = Source.Height() + Template.Height() / 2;

   // Search for a size supported by clFFT
   while (!m_fft.IsSupportedLength(size.Width))
      size.Width++;

   while (!m_fft.IsSupportedLength(size.Height))
      size.Height++;

   if (m_bigger_source == nullptr || m_bigger_source->Width() != size.Width || m_bigger_source->Height() != size.Height)
      m_bigger_source = std::make_shared<TempImage>(*m_CL, size, SImage::F32, 1);

   if (m_bigger_template == nullptr || m_bigger_template->Width() < size.Width || m_bigger_template->Height() < size.Height)
      m_bigger_template = std::make_shared<TempImage>(*m_CL, size, SImage::F32, 1);



   // Size of the spectral images
   size.Width = size.Width / 2 + 1;

   if (m_templ_spect == nullptr || m_templ_spect->Width() < size.Width || m_templ_spect->Height() < size.Height)
      m_templ_spect = std::make_shared<TempImage>(*m_CL, size, SImage::F32, 2);

   if (m_source_spect == nullptr || m_source_spect->Width() != size.Width || m_source_spect->Height() != size.Height)
      m_source_spect = std::make_shared<TempImage>(*m_CL, size, SImage::F32, 2);

   if (m_result_spect == nullptr || m_result_spect->Width() < size.Width || m_result_spect->Height() < size.Height)
      m_result_spect = std::make_shared<TempImage>(*m_CL, size, SImage::F32, 2);

   m_integral.PrepareFor(Source);
   m_statistics.PrepareFor(Template);
   m_transform.PrepareFor(Source);
   m_fft.PrepareFor(*m_bigger_source, *m_source_spect);
   SelectProgram(Source).Build();
   SelectProgram(*m_source_spect).Build();
}
예제 #2
0
void Integral::PrepareFor(ImageBase& Source)
{
   ImageProgram::PrepareFor(Source);

   // Also build float program as we will need it
   GetProgram(Float).Build();

   SSize VerticalImgSize = {GetNbGroupsW(Source) - 1, Source.Height()};
   SSize HorizontalImgSize = {Source.Width(), GetNbGroupsH(Source) - 1};

   if (VerticalImgSize.Width == 0)
      VerticalImgSize.Width = 1;

   if (HorizontalImgSize.Height == 0)
      HorizontalImgSize.Height = 1;

   // Check validity of current temp buffers
   if (m_VerticalJunctions != nullptr && 
      uint(VerticalImgSize.Width) <= m_VerticalJunctions->Width() &&
      uint(VerticalImgSize.Height) <= m_VerticalJunctions->Height() &&
      uint(HorizontalImgSize.Width) <= m_HorizontalJunctions->Width() &&
      uint(HorizontalImgSize.Height) <= m_HorizontalJunctions->Height() &&
      Source.IsFloat() == m_VerticalJunctions->IsFloat())
   {
      // Buffers are good
      return;
   }

   // Create buffers for temporary results
   m_VerticalJunctions = std::make_shared<TempImage>(*m_CL, VerticalImgSize, SImage::F32);
   m_HorizontalJunctions = std::make_shared<TempImage>(*m_CL, HorizontalImgSize, SImage::F32);
}
예제 #3
0
cl::NDRange VectorProgram::GetRange(EProgramVersions Version, const ImageBase& Img1)
{
   switch (Version)
   {
   case Fast:
      // The fast version uses a 1D range
      return cl::NDRange(Img1.Width() * Img1.Height() * Img1.NbChannels() / GetVectorWidth(Img1.DataType()), 1, 1);

   case Standard:
   case Unaligned:
      // The other versions use a 2D range
      return Img1.VectorRange(GetVectorWidth(Img1.DataType()));

   case NbVersions:
   default:
      throw cl::Error(CL_INVALID_PROGRAM, "Invalid program version in VectorProgram");
   }

}
예제 #4
0
void CheckSameSize(const ImageBase& Img1, const ImageBase& Img2)
{
   if (Img1.Width() != Img2.Width() || Img1.Height() != Img2.Height())
      throw cl::Error(CL_INVALID_IMAGE_SIZE, "Different image sizes used");
}
예제 #5
0
void Blob::PrepareFor(ImageBase& Source)
{
   if (m_TempBuffer == nullptr || Source.Width() > m_TempBuffer->Width() || Source.Height() > m_TempBuffer->Height())
      m_TempBuffer = std::make_shared<TempImageBuffer>(*m_CL, Source.Size(), SImage::U32);
}