计算围绕点+ Matlab的圆形箱 [英] Calculate circular bins around a point + matlab

查看:94
本文介绍了计算围绕点+ Matlab的圆形箱的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题与此链接 stackoverflow问题

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

在此图中,有12个角仓,但我有8个.这里有一个代码解决方案,但用于绘制上图.

我想计算每个楔形的4个区域中每个区域的最大强度点. Matlab中有任何内置函数吗?我看着rose,但不知道这是否对我有帮助....

如果有人能帮助我如何在Matlab中进行计算,我将不胜感激.

谢谢

解决方案

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

% 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,逆时针移动或类似的东西像这样.您必须设计自己的约定来跟踪垃圾箱.

My question is related to this link stackoverflow ques

In essence repeating the figure drawn there .. I have a central point ( x , y ) in an image around which I have to draw 4 circles of 1-4 unit radius with 8 angles between them.

In this diagram there are 12 angle bins but I have 8. There is a code solution there but it is for plotting the above figure.

I want to calculate the maximum intensity point in each of the 4 regions of each wedge. Is there any inbuilt function in matlab ? I looked at rose but could'nt understand if it would help me....

I would greatly appreciate if someone could help me how to calculate it in matlab....

Thanks

解决方案

I put some code below that should be the basic skeleton of what you want to do. But I left an important function unimplemented because I think you will be able to do it and it will help you understand this process better.

% 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

You will now have to make the function get_bin_number() which takes as its input the angle and radius of the data point away from the center point. It should return just an index between 1 and total_num_bins, because you will be keeping the max intensities in a linear array. So, for example, index number 1 might correspond to the first 1/4 piece of the closest radial cell in the upper right quadrant, index 2 might correspond to the next 1/4 of that same cell, moving counter-clockwise, or something like this. You have to devise your own convention for keeping track of the bins.

这篇关于计算围绕点+ Matlab的圆形箱的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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