获取图像内矢量的所有像素坐标 [英] Getting all pixel coordinates of a vector inside a image

查看:936
本文介绍了获取图像内矢量的所有像素坐标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have an intensity/greyscale image, and I have chosen a pixel inside this image. I want to send vectors starting from this pixel in all directions/angles, and I want to sum all the intensities of the pixels touching one vector, for all vectors.

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

After this step I would like to plot a histogram with the intensities on one axis and the angle on the other axis. I think I can do this last step on my own, but I don't know how to create these vectors inside my greyscale image and how to get the coordinates of the pixels a vector touches.

我之前在C ++中做过这个,需要很多代码。我相信这可以在MATLAB中用更少的工作完成,但我对MATLAB很新,所以任何帮助都会受到赞赏,因为我没有在文档中找到任何有用的东西。

I previously did this in C++, which required a lot of code. I am sure this can be done with less effort in MATLAB, but I am quite new to MATLAB, so any help would be appreciated, since I haven't found anything helpful in the documentation.

推荐答案

这可能不是解决问题的最佳方法,但你可以用一些代数来做,这是怎么回事。 ..

我们知道 Point-Slope公式通过角度θ的点(a,b)的线是:

It might not be the best way to solve it, but you can do it using a bit of algebra, heres how...
We know the Point-Slope formula of a line passing through point (a,b) with angle theta is:

y = tan(theta) * (x-a) + b

因此,一个简单的想法是为所有const计算此行与y = const的交集,并且读取交叉点的强度值。你会在所有角度重复这个...

一个示例代码来说明这个概念:

Therefore a simple idea is to compute the intersection of this line with y=const for all const, and read the intensity values at the intersection. You would repeat this for all angles...
A sample code to illustrate the concept:

%% 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

这篇关于获取图像内矢量的所有像素坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆