The procedures below are the detailed implementation of the blocks presented in the…
- User
The procedures below are the detailed implementation of the blocks presented in the flowchart in the Method section. The code is in Pseudo-code form and should give the reader a good idea of how to implement our novel algorithm. 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 - (Xmeshsin(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
реализуй этот алгоритм на python, из библиотек можно использовать только numpy, код должен детектировать прямые, образующие треугольник на черно-белом изображении
- Assistant