Пример #1
0
void Blob::ComputeLabels(IImage& Source, ImageBuffer& Labels, int ConnectType)
{
   if (ConnectType != 4 && ConnectType != 8)
      throw cl::Error(CL_INVALID_VALUE, "Wrong connect type in Blob::ComputeLabels");

   if (Labels.Depth() != 32 || Labels.IsFloat())
      throw cl::Error(CL_INVALID_VALUE, "Wrong Labels image type in Blob::ComputeLabels - Labels must be 32 bit integer");

   if (m_TempBuffer == nullptr)
      PrepareFor(Source);

   CheckSameSize(Source, Labels);
   CheckCompatibility(Labels, *m_TempBuffer);

   m_BlobInfo.Init(ConnectType);

   m_InfoBuffer.Send();

   // Initialize the label image
   Kernel(init_label, Source, Out(Labels, *m_TempBuffer), Labels.Step(), m_TempBuffer->Step(), m_InfoBuffer);

   // These two labeling steps need to be executed at least twice each
   int i = 0;
   while (i <= m_BlobInfo.LastUsefulIteration)
   {
      i++;

      Kernel(label_step1, Labels, *m_TempBuffer, Labels.Step(), m_TempBuffer->Step(), m_InfoBuffer, i);
      Kernel(label_step2, Labels, *m_TempBuffer, Labels.Step(), m_TempBuffer->Step(), m_InfoBuffer, i);

      if (i >= 2)
         m_InfoBuffer.Read(true);
   }

}
Пример #2
0
void FiltersVector::Smooth(ImageBuffer& Source, ImageBuffer& Dest, int Width)
{
   CheckCompatibility(Source, Dest);

   if (Width < 3 || (Width & 1) == 0)
      throw cl::Error(CL_INVALID_ARG_VALUE, "Invalid width used in Smooth");

   Kernel(smooth, In(Source), Out(Dest), Source.Step(), Dest.Step(), Source.Height(), Width);
}
Пример #3
0
void FiltersVector::Sharpen(ImageBuffer& Source, ImageBuffer& Dest, int Width)
{
   CheckCompatibility(Source, Dest);

   if (Width != 3)
      throw cl::Error(CL_INVALID_ARG_VALUE, "Invalid width used in Sharpen - allowed : 3");

   Kernel(sharpen3, In(Source), Out(Dest), Source.Step(), Dest.Step(), Source.Height());
}
Пример #4
0
void FiltersVector::Scharr(ImageBuffer& Source, ImageBuffer& Dest, int Width)
{
   CheckCompatibility(Source, Dest);

   if (Width == 3)
   {
      Kernel(scharr3, Source, Dest, Source.Step(), Dest.Step(), Source.Height());
      return;
   }

   throw cl::Error(CL_INVALID_ARG_VALUE, "Invalid width used in Scharr - allowed : 3");
}
Пример #5
0
void FiltersVector::Gauss(ImageBuffer& Source, ImageBuffer& Dest, int Width)
{
   CheckCompatibility(Source, Dest);

   if (Width == 3)
   {
      Kernel(gaussian3, Source, Dest, Source.Step(), Dest.Step(), Source.Height());
      return;
   }

   if (Width == 5)
   {
      Kernel(gaussian5, Source, Dest, Source.Step(), Dest.Step(), Source.Height());
      return;
   }

   throw cl::Error(CL_INVALID_ARG_VALUE, "Invalid width used in Gauss - allowed : 3, 5");
}
Пример #6
0
void FiltersVector::Median(ImageBuffer& Source, ImageBuffer& Dest, int Width)
{
   CheckCompatibility(Source, Dest);

   Source.SendIfNeeded();

   if (Width != 3 && Width != 5)
      throw cl::Error(CL_INVALID_ARG_VALUE, "Invalid width used in Median - allowed : 3 or 5");

   if (Width == 3)
   {
      /*if (RangeFit(Source, 16, 16))  // The cached version is slower on my GTX 680
      {
         Kernel_(*m_CL, SelectProgram(Source), median3_cached, cl::NDRange(16, 16, 1), Source, Dest, Source.Step(), Dest.Step(), Source.Height());
         return;
      }*/

      Kernel(median3, Source, Dest, Source.Step(), Dest.Step(), Source.Height());
      return;
   }

   Kernel(median5, Source, Dest, Source.Step(), Dest.Step(), Source.Height());
}
Пример #7
0
void FiltersVector::GaussianBlur(ImageBuffer& Source, ImageBuffer& Dest, float Sigma)
{
   CheckCompatibility(Source, Dest);

   // Prepare mask
   int MaskSize = int(ceil(3 * Sigma));

   if (Sigma <= 0 || MaskSize > 31)
      throw cl::Error(CL_INVALID_ARG_VALUE, "Invalid sigma used with GaussianBlur - allowed : 0.01-10");

   uint NbElements = (MaskSize * 2 + 1 ) * (MaskSize * 2 + 1 );

   std::vector<float> Mask(NbElements);

   GenerateBlurMask(Mask, Sigma, MaskSize);
   // NOTE : Maybe we should generate the mask in the device to prevent having to send that buffer


   // Send mask to device
   ReadBuffer MaskBuffer(*m_CL, Mask.data(), NbElements);

   // Execute kernel
   Kernel(gaussian_blur, In(Source), Out(Dest), Source.Step(), Dest.Step(), Source.Height(), MaskBuffer, MaskSize);
}
Пример #8
0
void Blob::RenameLabels(ImageBuffer& Labels)
{
   if (Labels.Depth() != 32 || Labels.IsFloat())
      throw cl::Error(CL_INVALID_VALUE, "Wrong Labels image type in Blob::RenameLabels - Labels must be 32 bit integer");

   if (m_TempBuffer == nullptr)
      throw cl::Error(CL_INVALID_MEM_OBJECT, "Wrong Labels image type in Blob::RenameLabels - Labels must be 32 bit integer");

   CheckCompatibility(Labels, *m_TempBuffer);

   // Rename the labels
   Kernel(reorder_labels1, Labels, *m_TempBuffer, Labels.Step(), m_TempBuffer->Step(), m_InfoBuffer);
   Kernel(reorder_labels2, Labels, *m_TempBuffer, Labels.Step(), m_TempBuffer->Step(), m_InfoBuffer);

   m_InfoBuffer.Read(true);
}