【问题标题】:Calculate circular bins around a point + matlab计算一个点周围的圆形箱+ matlab
【发布时间】:2013-06-21 11:34:37
【问题描述】:

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

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

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

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

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

谢谢

【问题讨论】:

    标签: matlab


    【解决方案1】:

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

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

    【讨论】:

    • 嘿,非常感谢您的回答...您能告诉我这是否适合get_bin_number( rad , angle ) ....counter = floor(rad) ....@987654327 @ 和 bin 编号将是 counter * 8 + index
    【解决方案2】:

    一个迟到的答案,但我相信一个更简单的解决方案就是使用 (r = sqrt(x.^2 + y.^2), theta = atan(y,x)) 将数据从 (x,y) 坐标转换为 (r,theta),然后在 (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);
    

    即使您已经解决了这个问题,我希望这对其他想要创建径向/角度直方图的人有所帮助!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-15
      • 2015-12-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多