Вопрос

I have 1024 X 256 polar data (rows - radius, columns angle) that I need to plot as an image. There is an m-file I got from the file-exchange that can do this (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

Другие советы

The approach of the M-file is correct. 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:

  1. Generate a cartesian grid (meshgrid) over the area you'd like to draw, one entry per destination pixel.
  2. Convert your x/y cartesian variables to polar
  3. Scale your polar coordinates to indices into your polar image (this takes into account matrix sizes and imaging depth)
  4. Use the polar indices to interpolate values out of the polar image, using interp2 (this is what makes a slow process fast)
  5. The resulting image is a cartesian image with pixel locations at your original x/y meshgrid points

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 с атрибуция
Не связан с StackOverflow
scroll top