MATLAB:倾斜边缘上的平滑曲线 - 边缘检测(Polyfit 或 fitPolynomialRANSAC?)

MATLAB: Smooth curves on tilted edges - Edge Detection (Polyfit or fitPolynomialRANSAC?)

我有带有条带的图像。条带并不总是 100% 直的,也不总是 100% 水平的。它们可以倾斜和弯曲。每个带具有恒定的宽度。 我需要图像上每个波段的宽度,并尽可能平滑地显示每个波段的边缘: Example_edge_detection.png Example_straight.png Example_tilted.png

我已经有了 100% 水平直线条带的解决方案。但我不知道如何用倾斜的带子来做。也许需要 Polyfit 或 houghlines?请帮我。谢谢!

这里是直线水平带的工作代码!

clc;    
close all;  
clear;  
workspace;  
format long g;
format compact;
fontSize = 20;

folder = pwd;
baseFileName = 'Example_straight.png';
grayImage = imread(baseFileName);
[rows, columns, numberOfColorChannels] = size(grayImage);

if numberOfColorChannels > 1
    grayImage = min(grayImage, [], 3);
end

hFig = gcf;
hFig.WindowState = 'maximized';
grayImage = adapthisteq(grayImage);
verticalProfile = mean(grayImage, 2);
threshold = 118;

binaryImage = imfill(grayImage < threshold, 'holes');
% Take the 3 largest blobs
binaryImage = bwareafilt(binaryImage, 3);
% Snip off small tendrils using imopen()
binaryImage = imopen(binaryImage, true(1, 3));
% Take the 3 largest blobs
binaryImage = bwareafilt(binaryImage, 3);
subplot(1, 1, 1);
imshow(baseFileName);
hFig = gcf;
hFig.WindowState = 'maximized'; % 
axis('on', 'image');
title('Edge Detection', 'FontSize', fontSize, 'Interpreter', 'None');

binaryProfile = (verticalProfile > threshold)';
bandStarts  = strfind(binaryProfile, [0, 1]);
bandStops = strfind(binaryProfile, [1, 0]);
for k = 1 : length(bandStarts)
    yline(bandStarts(k), 'Color', 'r', 'LineWidth', 1);
    yline(bandStops(k), 'Color', 'r', 'LineWidth', 1);
end

看起来您的算法目前只是执行一个简单的阈值来查找水平线,其中阈值应用于两个相邻行之间的平均水平像素值的差异。如果这足以完成工作,那对我来说就足够了。

至于非横线,或许你可以尝试像this这样的套路,先简单地拉直图像。