Procedure 1 Whole Image Correlation Analysis
1: functionCORRELATION(testimage,angrange,brange,sigma)
2: imgsize = size(testimage);
3:
4: if length(imgsize)>2 then
5: testimage = rgb2gray(testimage);
6: end if
7:
8: xsize = imgsize(2);
9: ysize = imgsize(1);
10: subimage = single(testimage);
11:
12: medianint = median(testimage(testimage>0));
13: angles = angrange(1):angrange(2):angrange(3);
14: trans = brange(1):brange(2):brange(3);
15: corrmap = zeros(length(angles), length(trans));
16:
17: for thetaind = 1:length(angles) do
   18: for 19:
20:
21:
for bind = 1:length(trans) do
theta = angles(thetaind);
b = trans(bind);
refline = REFERENCE_Line_Gen(xsize,ysize,theta,b,sigma); temp = refline .∗subimage;
temp2 = sum(temp(:));
temp3 = temp2/medianint; corrmap(thetaind, bind) = temp3;
22: 23: 24: 25:
26: end for
27: end for
28:
29: return corrmap 30:
31: endfunction
◃ Test if the image is a RGB image
 32
 Procedure 2 Reference Line Generation
1: functionREFERENCE_LINE_GEN(xsize,ysize,θ,b,σ)
2: [Xmesh, Ymesh] = meshgrid(1:xsize, 1:ysize) ◃ Create empty template image
3: Xmesh = Xmesh - single(xsize) / 2 ◃ Single means value to single precision
4: Ymesh = Ymesh - single(ysize) / 2
5:
6: angle=(θ*pi)/180
7: dist = single(b - (Xmesh*sin(angle)) - (Ymesh*cos(angle)))
8: distance = single (((dist).2) / (sigma2))
9: result = exp(-distance)
 10:
11: return result
12: endfunction
Procedure 3 Peak Extraction Algorithm
1: functionMAX_INTENSITY_FINDING(correlation_map,dist_input)
2: if (nargin == 2) then
3: distance_threshold = dist_input;
4: else
5: distance_threshold = 10;
6: end if
7: size_corr = size(correlation_map);
8: label_map = zeros(size_corr);
9: [xgrid,ygrid] = meshgrid(1:size_corr(2), 1:size_corr(1));
10:
11: for indx = 1:size_corr(2) do
◃ default value
   12: for 13:
14:
15:
indy = 1:size_corr(1) do
dist = sqrt((xgrid-indx)2 + (ygrid-indy)2);
pixuseful = dist < distance_threshold;
if (correlation_map(indy,indx) >= max(correlation_map(pixuseful))) then
◃ Filter out false peaks
label_map(indy,indx) = 1;
16: 17:
18: end for
19: end for
20:
21: label_map(correlation_map == 0) = 0;
22: endfunction
end if
 33

 Procedure 4 Peak Extraction Algorithm
1: functionSUB_WINDOW_ANALYSIS(correlation_map,dist_input)
2: imgsize = size(testimage);
3: sgimgsize = single(imgsize);
4: sgsubimgsz = single(subimgsz);
5: sgtestimage = single(testimage);
6: sigma = single(sigma);
7:
8: if (length(imgsize)>2) then
9: testimage = rgb2gray(testimage);
10: end if
11:
12: if (rem(imgsize(1),subimgsz(1)) || rem(imgsize(1),subimgsz(1))) then
13: display(’the subimage size does not match the whole image size’);
14: return
15: end if
16:
17: angles = angrange(1):angrange(2):angrange(3);
18: trans = brange(1):brange(2):brange(3);
19: corr = zeros(length(angles), length(trans),imgsize(1) / subimgsz(1), ...
20: imgsize(2) / subimgsz(2));
21:
22: xsize = sgimgsize(2);
23: ysize = sgimgsize(1);
24: [Xmesh, Ymesh] = meshgrid(0:(xsize-1), 0:(ysize-1));
25: Xmesh = mod(Xmesh,subimgsz(2));
26: Ymesh = mod(Ymesh,subimgsz(1));
27:
28: Xmesh = Xmesh - sgsubimgsz(2)/2;
29: Ymesh = Ymesh - sgsubimgsz(1)/2;
30: for thetaind = 1:length(angles) do
 31: for 32:
33:
34:
bind = 1:length(trans) do
theta = angles(thetaind);
b = single(trans(bind));
angle = single((theta* pi) / 180);
dist = b - (Xmesh*sin(angle)) - (Ymesh*cos(angle)); distpw = (dist2 )/ (sigma2 );
refline = exp(-distpw);
temp = refline*sgtestimage;
temp2 = reshape(temp,[subimgsz(1),imgsize(1)/subimgsz(1),... subimgsz(2),imgsize(2)/subimgsz(2)]);
temp3 = sum(temp2,1);
temp4 = squeeze(sum(temp3,3));
corr(thetaind, bind, :, :) = temp4;
35: 36: 37: 38: 39: 40: 41: 42: 43:
44: end for
45: end for
46: corrsz = size(corr);
47: spcorr = reshape(permute(corr,[1,3,2,4]),corrsz(1)*corrsz(3),corrsz(2)*corrsz(4));
48: colsubimgs = reshape(sgtestimage,...
49: [subimgsz(1),imgsize(1)/subimgsz(1), subimgsz(2),imgsize(2)/subimgsz(2)]);
50: endfunction

Переведи это на ЯП python, объсни, что делает каждая строчка, из библиотек можно использовать только numpy