2017-05-26 24 views
0

私の原画は、以下である、Houghによって検出された行を削除するにはどうすればよいですか?

enter image description here

これは私のハフコード、

function [hough_lines, H, T, R, P] = get_hough_lines(input_image , peaks) 
    binary_image = edge(input_image,'canny'); 
    [H,T,R] = hough(binary_image); 
    P = houghpeaks(H, peaks, 'threshold', ceil(0.3*max(H(:)))); 
    hough_lines = houghlines(binary_image,T,R,P,'FillGap',500,'MinLength',7); 
end 

私のライン検出画像は、以下で使用

input_image = imread('7.png');  
max_peaks = 3; 
discard_pixels = 10;  
[hough_lines, H, T, R, P] = get_hough_lines(input_image, max_peaks);   
draw_hough_lines(input_image, hough_lines); 

ご覧のとおり、私のHoughソースコードは、最も顕著な行のうち3行を検出します。

私は一番下の行を破棄したいと思います。

だから、私は

function [output_image] = discard_image_area(input_image, pixel_count) 
    output_image = input_image;  
    [height, width] = size(input_image);   
    % discard top 
    output_image(1:pixel_count, :) = 125; 
    % discard bottom 
    output_image((height-pixel_count):height, :) = 125;  
    % discard left 
    output_image(:,1:pixel_count) = 125; 
    % discard right 
    output_image(:,(width-pixel_count):width) = 125; 
end 

使用

input_image = imread('7.png');  
max_peaks = 3; 
discard_pixels = 10;  
[hough_lines, H, T, R, P] = get_hough_lines(discard_image_area(input_image, 
    discard_pixels), max_peaks);  
draw_hough_lines(input_image, hough_lines); 

しかし、結果は悪くなり、

enter image description here、画像から一部の領域を破棄し、次のコードを書かれています

関連するソースコード、

function draw_hough_lines(rotI, lines) 
    imshow(rotI), hold on 
    max_len = 0; 

    for k = 1:length(lines) 
     xy = [lines(k).point1; lines(k).point2]; 
     plot(xy(:,1),xy(:,2),'LineWidth',2,'Color','green'); 

     % Plot beginnings and ends of lines 
     plot(xy(1,1),xy(1,2),'x','LineWidth',2,'Color','yellow'); 
     plot(xy(2,1),xy(2,2),'x','LineWidth',2,'Color','red'); 

     % Determine the endpoints of the longest line segment 
     len = norm(lines(k).point1 - lines(k).point2); 
     if (len > max_len) 
      max_len = len; 
      xy_long = xy; 
     end 
    end 
end 

答えて

0

私はこの問題を解決しました。

125の代わりに0を使用しました。

function [output_image] = discard_image_area(input_image, pixel_count) 
    output_image = input_image; 

    [height, width] = size(input_image); 

    % discard top 
    output_image(1:pixel_count, :) = 0; 
    % discard bottom 
    h = height - pixel_count; 
    output_image(h:height, :) = 0;  
    % discard left 
    output_image(:,1:pixel_count) = 0; 
    % discard right 
    output_image(:,(width-pixel_count):width) = 0; 
end 
関連する問題