我的问题与此链接stackoverflow ques
有关本质上重复绘制的图形。我在图像中有一个中心点(x,y),我必须在其周围绘制4个1-4单位半径的圆,其间有8个角。
在这个图中有12个角度箱,但我有8个。那里有一个代码解决方案,但它用于绘制上图。
我想计算每个楔子的4个区域中每个区域的最大强度点。 matlab中有内置函数吗?我看了rose
,但是能不能理解它是否对我有用......
如果有人能帮助我如何在matlab中计算它,我将不胜感激....
由于
答案 0 :(得分: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,逆时针移动,或者某物像这样。你必须设计自己的惯例来跟踪垃圾箱。
答案 1 :(得分:2)
一个迟到的答案,但我相信一个更简单的解决方案就是使用(r = sqrt(x.^2 + y.^2), theta = atan(y,x))
将数据从(x,y)坐标转换为(r,theta),然后使用hist3函数(r ,theta)数据集以获得径向直方图。
因此解决方案如下:
% 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);
即使你已经解决了这个问题,我希望这能帮助其他想要创建径向/角度直方图的人!