使用omnithread-lib的并行hough算法



我想使用hough圆检测来加快图像处理。

   // For all rows in image:
   for y:=0 to AnalysisBitmap.Height-1 do
   begin
   // For all pixel in one row :
   for x:=0 to AnalysisBitmap.Width-1 do
   begin
      // Is there a point  ?
      if IsPixel(x,y, AnalysisBitmap, 128 ) then
      begin
           for theta:=0 to max_theta do
           begin
                TestPoint.x := round ( x -  r  *  cos(theta*PI/max_theta) );
                TestPoint.y := round ( y -  r  *  sin(theta*PI/max_theta));
               if ((testPoint.x < ImageWidth) and  (testPoint.x > 0 )  and
                  (testPoint.y < ImageHeight ) and  (testPoint.y > 0 ) )   then Inc(aHoughResult[TestPoint.x,TestPoint.y]);
           end;
      end;
   end;
  end;

由于VCL位图不是线程安全的,我想我只能对内部Theta循环进行并行处理?加速此代码的最佳方法是什么。

是的,只并行化内部循环就足够了。不要忘记组织aHoughResult的正确共享,例如,与关键部分。

在最新的Delphi版本中,您可以同时使用OTL和内置的System.Threading.TParallel选项。

最重要的加速(我认为)-用round(r*cos(theta*PI/max_theta))值填充表,并在循环中使用它。

最新更新