查看单个帖子
旧 2019-12-10, 16:49   #1
poster
高级会员
 
注册日期: 2019-11-21
帖子: 3,006
声望力: 66
poster 正向着好的方向发展
帖子 获取图像内向量的所有像素坐标

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

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

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


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

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

%% input point = [128 128]; % pixel location I = imread('cameraman.tif'); % sample grayscale image %% calculations [rc] = 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 = ( yr ); % 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

更多&回答...
poster 当前离线   回复时引用此帖