gpt4 book ai didi

algorithm - 如何从 Matlab 图像中去除直线?

转载 作者:塔克拉玛干 更新时间:2023-11-03 02:55:30 24 4
gpt4 key购买 nike

我有一个来自名为 Two_dim 的矩阵的 matlab 图像如下图所示。

我想从图像中删除所有 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

最佳答案

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

% 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

关于algorithm - 如何从 Matlab 图像中去除直线?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44995495/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com