0

I want to speed up image processing using the hough circle detection.

   // 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;

As the VCL Bitmap is not thread safe I guess I can only do parallel processing of the inner Theta Loop ? What is the best Approach to Speed up this code .

user1769184
  • 1,571
  • 1
  • 19
  • 44
  • 1
    Have you considered some image processing library like OpenCV, if your concern is practical? – MBo Nov 17 '15 at 10:15
  • yes, we also somethime use matlab for Image processing. THis time we want to use out own algorithm with DELPHI – user1769184 Nov 17 '15 at 10:28
  • Agreed with @MBo - unless this is an academic exercise, why reinvent the wheel? If performance matters I would probably skip multithreading altogether and go straight for OpenCV's [`gpu::HoughCircles`](http://docs.opencv.org/2.4/modules/gpu/doc/image_processing.html#gpu-houghcircles). – J... Nov 17 '15 at 11:02

1 Answers1

0

Yes, it is enough to parallelize the inner cycle only. Don't forget to organize right sharing of aHoughResult, for example - with critical section.

In the newest Delphi versions you can use both OTL and inbuilt System.Threading.TParallel possibilites.

The most important speedup (I think) - fill the table with round(r*cos(theta*PI/max_theta)) values and use it inside the cycles.

MBo
  • 77,366
  • 5
  • 53
  • 86