圆形彩色图中的插值着色

时间:2017-09-08 15:54:57

标签: matlab colors interpolation

我正在绘制相位图并使用像hsv这样的圆形颜色图。我遇到的问题是pi / -pi角度接口,插值(MATLAB中的着色interp命令)给出0,这导致结果图中的奇怪线条(见下图,下图是4切线arctan函数) )。有没有办法摆脱这些文物?我喜欢插值着色的平滑度而不是平面着色,但是平面着色可以避免这些伪影。

enter image description here

以下是生成上述图片的代码:

[x_grid,y_grid] = meshgrid(-31:32,-31:32);
phase = atan2(y_grid,x_grid);
surf(x_grid,y_grid,phase);
view(0,90);
shading interp
colorbar
axis([-31 32 -31 32])
colormap hsv

1 个答案:

答案 0 :(得分:2)

问题在于,使用N×N组网格点总是会在pi / -pi接口处产生不连续性,它将尝试进行插值。您可以创建一个2×N的坐标条带,它围绕原点并在pi / -pi界面处断开连接。以下说明了不连续性如何寻找两种方法:

% N-by-N grid:
[x_grid, y_grid] = meshgrid(-31:32, -31:32);
phase = atan2(y_grid, x_grid);
subplot(1, 2, 1);
surf(x_grid, y_grid, phase);
title('N-by-N grid');

% 2-by-N strip:
X = [-31.*ones(1, 33) -30:31 32.*ones(1, 64) 31:-1:-30 -31.*ones(1, 32); ...
     zeros(1, 253)];
Y = [0:32 32.*ones(1, 62) 32:-1:-31 -31.*ones(1, 62) -31:0; ...
     zeros(1, 253)];
phase = atan2(Y([1 1], :), X([1 1], :));
phase(:, end) = -pi;
subplot(1, 2, 2);
surf(X, Y, phase);
title('2-by-N strip');

enter image description here

以下是最终二维视图的外观(使用更高分辨率的色彩映射):

X = [-31.*ones(1, 33) -30:31 32.*ones(1, 64) 31:-1:-30 -31.*ones(1, 32); ...
     zeros(1, 253)];
Y = [0:32 32.*ones(1, 62) 32:-1:-31 -31.*ones(1, 62) -31:0; ...
     zeros(1, 253)];
phase = atan2(Y([1 1], :), X([1 1], :));
phase(:, end) = -pi;
surf(X, Y, phase);
view(0, 90);
shading interp;
colorbar;
axis([-31 32 -31 32]);
colormap(hsv(256));

enter image description here