[英]Plotting polar images in MATLAB
I have 1024 X 256 polar data (rows - radius, columns angle) that I need to plot as an image. 我有1024 X 256极数据(行 - 半径,列角度),我需要绘制为图像。 There is an m-file I got from the file-exchange that can do this (clickhere) . 我从文件交换中获得了一个可以执行此操作的m文件(clickhere) 。 However, it is really slow for large images. 但是,对于大图像来说真的很慢。 I believe there is a fast way to do this using the surf function that I am struggling with. 我相信使用我正在努力解决的冲浪功能有一种快速的方法。 (See code below) (见下面的代码)
data = data; % load any polar data
depth = 4.5; %imaging depth in mm
offset = 0.5;
theta = [(0:2*pi/size(data,2):2*pi-1/size(data,2))]*180/pi;
rho = [0:(depth-offset)/size(data,1):(depth-offset)-1/size(data,1)] + offset;
[THETA,RR] = meshgrid(theta,rho);
[A,B] = pol2cart(THETA,RR);
figure
surf(A,B,data,'edgecolor','none'),
view(0,90)
xlabel('x [mm]')
ylabel('y [mm]')
axis tight
The result appears to be incorrect. 结果似乎不正确。
Any idea what I am doing wrong? 知道我做错了什么吗? Thanks! 谢谢!
Yep, your problem is simple: 是的,你的问题很简单:
pol2cart Transform polar to Cartesian coordinates.
[X,Y] = pol2cart(TH,R) transforms corresponding elements of data
stored in polar coordinates (angle TH, radius R) to Cartesian
coordinates X,Y. The arrays TH and R must the same size (or
either can be scalar). ***TH must be in radians***.
Solution: Remove the 180/pi 解决方案: 删除180 / pi
The approach of the M-file is correct. M文件的方法是正确的。 But you're right, it's implemented very slowly. 但你是对的,它实施得非常慢。 The piece you're missing is the transformation of the data itself from polar to rectangular, which is the hard part. 您缺少的部分是数据本身从极性到矩形的转换,这是困难的部分。 Currently, you're transforming the coordinates you want to plot at, but are then plotting your polar data AS IF it were cartesian (imposing your cartesian coordinates on the data). 目前,您正在转换要绘制的坐标,但是如果它是笛卡尔坐标(在数据上强加笛卡尔坐标),则绘制极坐标数据。
The approach you should take to get correct AND fast is this: 你应该采取正确和快速的方法是这样的:
Does that process make sense? 这个过程有意义吗? In image processing, it's normal to start in destination space (that's where you need whole pixels) and move backward to fractional pixel offsets in your source image, then interpolate. 在图像处理中,从目标空间(您需要整个像素的位置)开始并向后移动到源图像中的小数像素偏移是正常的,然后进行插值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.