在Matlab中创建一个平滑的网格

问题描述 投票:0回答:1

我正在使用Matlab函数checkerboard创建一个棋盘,然后将其显示为圆形而不是方形或矩形。我已经编写了下面的代码来做这个,但因为我的网格看起来很粗糙,当我做imshow(checks)你可以看到圆的边缘是锯齿状的,而且根本没有光滑。谁能告诉我如何克服这个问题?

或者,我必须设置这样一个小网格的原因是我需要从K生成的checkerboard矩阵非常小,因为我希望在那里显示较少的棋盘以使其看起来好像方块有更大的距离。如果有人知道如何在不创建网格网格的情况下执行此操作,那也可以。

这是我使用Psychtoolbox的脚本的一部分所以我对我能做的事情有点限制。一旦我创建了checks,我就用它生成一个texture来绘制屏幕,​​同时将其缩放以使其更大。

有人可以帮忙吗?

码:

  K=checkerboard(9); % using Matlab checkerboard function to create a checkerboard
  K=K(1:27,1:27); % using a small part of the checkerboard as I want to have a wide distances between the lines
  cmap = [0.48 0.48 0.48; 0.54 0.54 0.54]; % colour map to make the colour grey
  bw1 = ind2rgb(uint8(K), cmap);
  white = 1;
  grey = white/2;
  rcycles = 8;

   % Now we make our checkerboard pattern
   xylim = 1;
   [x,y] = meshgrid(-1.25:0.0932:1.25,-1.25:0.0932:1.25);

  checks = bw1;
  circle = x.^2 + y.^2 <= xylim^2;
  checks = circle .* checks + grey * ~circle;

  imshow(checks);
matlab resize mesh psychtoolbox
1个回答
1
投票

(迟到的答案,但也许有人可能会发现它有用。)

在我看来,为了获得没有锯齿状边缘的纹理,您只需要在应用圆形孔径之前重新缩放棋盘图案。您可以使用matlab中的repelem函数轻松完成此操作:

K=checkerboard(9); % using Matlab checkerboard function to create a checkerboard
K=K(1:27,1:27); % using a small part of the checkerboard as I want to have a wide distances between the lines
cmap = [0.48 0.48 0.48; 0.54 0.54 0.54]; % colour map to make the colour grey
bw1 = ind2rgb(uint8(K), cmap);

% this scale factor indicate by how much the checkerboard size is increased
scale_factor = 23;

bw1 = repelem(bw1,scale_factor,scale_factor);

white = 1;
grey = white/2;
rcycles = 8;

% Now we make our checkerboard pattern
xylim = 1;
[x,y] = meshgrid(linspace(-1.25,1.25, 27*scale_factor),linspace(-1.25,1.25, 27*scale_factor));

checks = bw1;
circle = x.^2 + y.^2 <= xylim^2;

checks = repmat(circle,1,1,3) .* checks + grey * ~repmat(circle,1,1,3);
imshow(checks);

结果:enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.