代码之家  ›  专栏  ›  技术社区  ›  Sack11

如何从Matlab图像中删除直线?

  •  5
  • Sack11  · 技术社区  · 8 年前

    Two_dim 如下图所示。

    我想删除所有3个 底部直线水平线 从图像中。我查阅了Stackoverflow以使用 regionprops

    rp = regionprops(Two_dim, 'PixelIdxList', 'Eccentricity', 'Orientation');
    rp = rp([rp.Eccentricity]>0.95 & (abs([rp.Orientation])<2 | abs([rp.Orientation])>89));
    Two_dim(vertcat(rp.PixelIdxList)) = false;
    

    Noisy Image

    3 回复  |  直到 8 年前
        1
  •  5
  •   EBH    8 年前

    下面是使用霍夫变换方法的答案。稍后,我将为下面的代码添加更多解释:

    % I crop only the intresting part for illustration:
    BW = edge(Two_dim(1:1000,:),'canny');
    subplot 131
    imagesc(Two_dim(1:1000,:))
    title('Original image')
    axis xy
    [H,theta,rho] = hough(BW); % preform Hough transform
    subplot 132
    P = houghpeaks(H,10,'NHoodSize',[1 1]); % find the peaks in the transformation
    lines_found = houghlines(BW,theta,rho,P,...
        'FillGap',50,'MinLength',1); % convert the peaks to line objects
    imagesc(Two_dim(1:1000,:)), hold on
    result = Two_dim(1:1000,:);
    for k = 1:length(lines_found)
       % extract one line:
       xy = [lines_found(k).point1; lines_found(k).point2];
       % Plot the detected lines:
       plot(xy(:,1),xy(:,2),'LineWidth',1,'Color','green');
       % remove the lines from the image:
       % note that I take a buffer of 3 to the 'width' of the line
       result(xy(1,2):xy(1,2)+3,xy(1,1):xy(2,1)) = 0;
    end
    title('Detected lines')
    axis xy
    subplot 133
    imagesc(result)
    title('Corrected image')
    axis xy
    

    find a line

        2
  •  3
  •   Tapio    8 年前

    你可以看看行强度和。只要这些线保持水平,它们就会脱颖而出。

    grayI = rgb2gray(I);
    
    rowSums = sum(grayI,2);
    
    plot(rowSums);
    

    Plot of row sums

    filterRows = rowSums > 1*10^5
    
    I(filterRows,:,:) = 255;
    

    enter image description here

        3
  •  0
  •   LUB    8 年前

    regionprops

    你可以这样做。

    Two_dim(Two_dim<0.5) = 0;
    Two_dim(Two_dim>=0.5) = 1; # the actual value doesn't matter
    

    Two_dim = logical(Two_dim);