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 .
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.