2017-08-04 61 views
0

我正在使用Matlab函數checkerboard創建棋盤格,然後將其顯示爲圓形而不是正方形或矩形。我已經寫了下面的代碼來做到這一點,但因爲我的meshgrid看起來很粗糙,當我做imshow(checks)時,你可以看到圓的邊緣是鋸齒狀的,而且一點都不光滑。誰能告訴我如何克服這個問題?在Matlab中創建平滑的網格網格

或者,爲什麼我不得不設置這樣的小meshgrid的原因是,我需要從checkerboard產生的K矩陣是非常小的,因爲我想有顯示較少的棋盤,使其看起來好像平方有更大的距離。如果有人知道如何在不創建網格的情況下做到這一點,那也是可行的。

這是我的腳本的一部分,它使用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); 
+0

在我看來,這將是隻有當你從字面上採取之間'[-1.25每一個實數完美流暢,1.25]'這顯然是不可能的。如果你使用類似'K = checkerboard(40); K = K(1:269,1:269);'和網格間隔爲'-1.25:0.00932:1.25'。順便說一句,它給你這個:https://i.stack.imgur.com/uqdhP.jpg它看起來很順利,但如果你放大它,你會看到同樣的問題,因爲你不能考慮'[-1.25 ,1.25]' –

回答

1

(晚的答案,但也許有人會發現它有用。)

在我看來,要實現無鋸齒狀邊緣的紋理,你只需要重新調整棋盤圖案在應用圓孔之前。你可以用repelem功能做到這一點很容易在MATLAB:

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