0

我的问题与此链接有关stackoverflow ques

本质上重复在那里绘制的图形.. 我在图像中有一个中心点( x , y ),我必须围绕它绘制 4 个 1-4 单位半径的圆,它们之间有 8 个角度。

在此图中,有 12 个角度箱,但我有 8 个。那里有一个代码解决方案,但它用于绘制上图。

记录极地箱

我想计算每个楔形的 4 个区域中的每个区域的最大强度点。matlab 有内置函数吗?我看了看,rose但不明白它是否对我有帮助......

如果有人可以帮助我如何在matlab中计算它,我将不胜感激......

谢谢

4

2 回答 2

2

我在下面放了一些代码,这些代码应该是您想要做的基本框架。但是我留下了一个未实现的重要功能,因为我认为您将能够做到,它将帮助您更好地理解这个过程。

% I assume that data_points is an M-by-2 array, where each row corresponds 
% to an (x,y) coordinate pair, and M is the number of data points.
data_points = ... ;

% I assume this array stores the intensities at each data point.
intensities = ... ;

% I assume that this stores the total number of gridded polar regions you want
% to find the max intensity in (i.e. 4*(number of cells) in your picture above).
total_num_bins = ... ;

% This will store the max intensities. For places that have no nearby 
% data points, the max intensity will remain zero.
max_intensities = zeros(total_num_bins);

% I assume these store the values of the center point.
x = ... ; y = ... ;

% The number of different data points.
num_data_points = length(intensities); % also equals size(data_points,1)

% Now, loop through the data points, decide which polar bin they fall in, and
% update the max intensity of that area if needed.
for ii = 1:num_data_points

    % Grab the current point coordinates.
    cur_x = data_points[ii,1];
    cur_y = data_points[ii,2];

    % Convert the current data point to polar coordinates,
    % keeping in mind that we are treating (x,y) like the center.
    cur_radius = sqrt( (cur_x - x)^2 + (cur_y - y)^2 );
    cur_angle = atan2(cur_y - y, cur_x - x)


    % You have to write this yourself, but it
    % will return an index for the bin that this
    % data point falls into, i.e. which of the 4 segments
    % of one of the radial cells it falls into.
    cur_bin = get_bin_number(cur_radius, cur_angle);

    % Check if this data point intensity is larger than
    % the current max value for its bin.
    if ( intensities(ii) >= max_intensities(cur_bin))
        max_intensities(cur_bin) = intensities(ii);
    end
end

您现在必须创建将get_bin_number()数据点远离中心点的角度和半径作为其输入的函数。1它应该只返回和之间的索引total_num_bins,因为您会将最大强度保持在线性数组中。因此,例如,索引号 1 可能对应于右上象限中最近的径向单元的前 1/4 块,索引 2 可能对应于同一单元的下一个 1/4,逆时针移动,或其他像这样。您必须设计自己的约定来跟踪垃圾箱。

于 2012-04-11T22:52:50.857 回答
2

一个较晚的答案,但我相信一个更简单的解决方案就是将数据从 (x,y) 坐标转换为 (r,theta),(r = sqrt(x.^2 + y.^2), theta = atan(y,x))然后使用 (r,theta) 数据集上的 hist3 函数来获得径向直方图。

因此解决方案如下:

% I assume you have some M-by-2 matrix X that's in the form (x,y)
% Convert (x,y) to (r,theta)
xVect = X(:,1);
yVect = X(:,2);
X = [sqrt(xVect.^2 + yVect.^2), ...%formula for r
    atan(yVect,xVect)]; %formula for theta

% 5 is the number of wedges along 'r', your radial axis
% 12 is the number of wedges along 'theta', your theta 'axis'
dist = hist3(X,5,12);

即使您已经解决了这个问题,我希望这可以帮助任何想要创建径向/角度直方图的人!

于 2013-06-21T03:05:51.877 回答