0

我正在使用 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);
4

1 回答 1

1

(迟到的答案,但也许有人会觉得它有帮助。)

在我看来,要获得没有锯齿状边缘的纹理,您只需要在应用圆形光圈之前重新调整棋盘图案即可。您可以使用repelemmatlab 中的函数轻松完成此操作:

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);

结果: 在此处输入图像描述

于 2017-12-17T11:17:54.783 回答