2017-05-09 8 views
-8

Quelqu'un peut-il me dire ce qui se passe dans le for -loop?MATLAB Code explication

%find slopes of each line 
    m1 = diff(line1_start_end_points(:,2))/ diff(line1_start_end_points(:,1))+0.1/(2*pi); 
    m2 = diff(line2_start_end_points(:,2))/ diff(line2_start_end_points(:,1))+0.1/(2*pi); 
    m3 = diff(line3_start_end_points(:,2))/ diff(line3_start_end_points(:,1))+0.1/(2*pi); 

    %====================find longest scratch on each line========================== 
    if (line1_flag==0) 
     x = line1_start_end_points(1,1); 
     y = line1_start_end_points(1,2); 
     % iterate through the height of the image 
     for i=1:COLS        
      final_line1(:,i)=[y + m1*(i-x)   i]'; 
      gray_image_copy1(floor(y+m1*(i-x)), i) = 255; 
      hough_in_new1(:,i)=0; 
      hough_in_new1(floor(y+m1*(i-x)),i)=1; 
     end 
    end 

.... .... .... 
.... .... .... 

Répondre

1

semble comme dessiner une ligne droite, pixel par pixel, sur une image en niveaux de gris et sur un tableau de zéros:

if (line1_flag==0) 
    % x coordinate of line start 
    x = line1_start_end_points(1,1); 
    % y coordinate of line start 
    y = line1_start_end_points(1,2); 
    % iterate through the height of the image 
    for i=1:COLS % iterate on image columns (x's), i is like variable x 
     % compute the y value for this column using y = mx + b, where 
     % (i) is the x coordinte, and j=(y + m1*(i-x)) is the y coord. 
     j = y + m1*(i-x); 
     final_line1(:,i)=[j i]'; 
     % draw this x-y pixel in white on the image, floor j to nearest 
     % integer - results in 255's where the line is 
     gray_image_copy1(floor(j), i) = 255; 
     % reset all hough array i'th column 
     hough_in_new1(:,i)=0; 
     % set only the j,i element to 1 - results in 1's where the line 
     % is 
     hough_in_new1(floor(j),i)=1; 
    end 
end 
+0

Je l'ai écrit: tracer une ligne droite, pixel par pixel, sur une tableau de zéros – user2999345