gpt4 book ai didi

matlab - 氡变换线检测

转载 作者:行者123 更新时间:2023-12-05 06:42:56 25 4
gpt4 key购买 nike

我正在尝试检测灰度图像中的线条。为此,我在 MATLAB 中使用 Radon 变换。我的 m 文件的示例如下所示。我可以使用此代码检测多行。我还使用线条的移位和旋转属性绘制线条。但是,我不明白如何在获取 rhotheta 值后获取检测线的起点和终点。

霍夫变换很容易,因为有一个名为 houghlines() 的函数可以返回给定峰的直线列表。是否有任何函数可用于 Radon 变换,类似于此函数?

    % Radon transform line detection algorithm
clear all; close all;

% Determine the path of the input image
str_inputimg = '3_lines.png' ;

% Read input image
I = imread(str_inputimg) ;

% If the input image is RGB or indexed color, convert it to grayscale
img_colortype = getfield(imfinfo(str_inputimg), 'ColorType') ;
switch img_colortype
case 'truecolor'
I = rgb2gray(I) ;
case 'indexedcolor'
I = ind2gray(I) ;
end

figure;
subplot(2,2,1) ;
imshow(I) ;
title('Original Image') ;

% Convert image to black white
%BW = edge(I,'Sobel');
BW=im2bw(I,0.25) ;
subplot(2,2,2) ;
imshow(BW);
title('BW Image') ;

% Radon transform
% Angle projections
theta = [0:179]' ;
[R, rho] = radon(BW, theta) ;
subplot(2,2,3) ;
imshow(R, [], 'XData', theta, 'YData', rho, 'InitialMagnification', 'fit');
xlabel('\theta'), ylabel('\rho');
axis on, axis normal, hold on;

% Detect the peaks of transform output
% Threshold value for peak detection
threshold_val = ceil(0.3*max(R(:))) ;
% Maximum nof peaks to identify in the image
max_nofpeaks = 5 ;
max_indexes = find(R(:)>threshold_val) ;
max_values = R(max_indexes) ;
[sorted_max, temp_indexes] = sort(max_values, 'descend') ;
sorted_indexes = max_indexes(temp_indexes) ;

% Get the first highest peaks for the sorted array
if (length(sorted_max) <= max_nofpeaks)
peak_values = sorted_max(1:end) ;
peak_indexes = sorted_indexes(1:end) ;
else
peak_values = sorted_max(1:max_nofpeaks) ;
peak_indexes = sorted_indexes(1:max_nofpeaks) ;
end
[y, x] = ind2sub(size(R), peak_indexes ) ;
peaks = [rho(y) theta(x)] ;
plot(peaks(:,2), peaks(:,1), 's', 'color','white');
title('Radon Transform & Peaks') ;

% Detected lines on the image
subplot(2,2,4), imshow(I), title('Detected lines'), hold on

x_center = floor(size(I, 2)/2) ;
y_center = floor(size(I, 1)/2) ;
for p=1:length(peaks)

x_1 = [-x_center, x_center] ;
y_1 = [0, 0] ;

% Shift at first
x_1_shifted = x_1 ;
y_1_shifted = [y_1(1)-peaks(p,1), y_1(2)-peaks(p,1)] ;

% Rotate
peaks(p,2) = 90 - peaks(p,2) ;
t=peaks(p,2)*pi/180;
rotation_mat = [ cos(t) -sin(t) ; sin(t) cos(t) ] ;
x_y_rotated = rotation_mat*[x_1_shifted; y_1_shifted] ;
x_rotated = x_y_rotated(1,:) ;
y_rotated = x_y_rotated(2,:) ;
plot( x_rotated+x_center, y_rotated+y_center, 'b', 'linewidth', 2 );
end
hold off;

最佳答案

math.SE 有建议这可能有帮助。然后是一篇看起来相当复杂的研究论文"Sharp endpoint estimates for the X-ray transform and the Radontransform in finite fields" ,这似乎只是为了显示估计精度的某些界限。

从浏览其他论文来看,这似乎是一个不平凡的问题。我怀疑使用 Sobel-operation 的一些改编可能更简单(如果不太准确)沿着发现的线识别高梯度点,并将这些点声明为端点。

关于matlab - 氡变换线检测,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35412573/

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