获取图像内向量的所有像素坐标

zhe*_*nic 4 matlab image-processing

我有一个强度/灰度图像,并且在该图像中选择了一个像素。我想从所有方向/角度从该像素开始发送矢量,并且我想对所有矢量求和触摸一个矢量的像素的所有强度的总和。

在此步骤之后,我想绘制一个直方图,其中一个轴上的强度,另一个轴上的角度。我想我可以自己完成最后一步,但是我不知道如何在我的灰度图像中创建这些矢量以及如何获取矢量接触的像素的坐标。

我以前是用C ++做到的,这需要很多代码。我确信这可以在MATLAB中花费更少的精力来完成,但是我对MATLAB还是很陌生,因此将不胜感激,因为我在文档中没有发现任何帮助。

Amr*_*mro 5

它可能不是解决问题的最佳方法,但是您可以使用一些代数来实现,这是如何做的...
我们知道以角theta穿过点(a,b)的线的点斜率公式为:

y = tan(theta) * (x-a) + b
Run Code Online (Sandbox Code Playgroud)

因此,一个简单的想法是为所有const计算该线与y = const的交点,并读取该交点处的强度值。您将对所有角度重复此操作...
示例代码说明了这一概念:

%% input
point = [128 128];               % pixel location
I = imread('cameraman.tif');     % sample grayscale image

%% calculations
[r c] = size(I);
angles = linspace(0, 2*pi, 4) + rand;
angles(end) = [];
clr = lines( length(angles) );   % get some colors

figure(1), imshow(I), hold on
figure(2), hold on

for i=1:length(angles)
    % line equation
    f = @(x) tan(angles(i))*(x-point(1)) + point(2);

    % get intensities along line
    x = 1:c;
    y = round(f(x));
    idx = ( y<1 | y>r );        % indices of outside intersections
    vals = diag(I(x(~idx), y(~idx)));

    figure(1), plot(x, y, 'Color', clr(i,:))    % plot line
    figure(2), plot(vals, 'Color', clr(i,:))    % plot profile
end
hold off
Run Code Online (Sandbox Code Playgroud)