Borrar filtros
Borrar filtros

Creating a smooth meshgrid

5 visualizaciones (últimos 30 días)
Maheen Siddiqui
Maheen Siddiqui el 4 de Ag. de 2017
Editada: John D'Errico el 4 de Ag. de 2017
I'm using the Matlab function checkerboard to create a checkerboard and then display it as a circle rather than a square or rectangle. I have written the code below to do this but because my meshgrid seems to be so coarse, when I do imshow(checks) you can see that the edges of the circle are jagged and not at all smooth. Could anyone tell me how to overcome this problem?
Alternatively, the reason why I have had to set such a small meshgrid is that I need the K matrix generated from checkerboard to be really small as I want there to display less of the checkerboard to make it appear as though the squares have a bigger distance. If anybody knows of a way of doing this without creating a meshgrid, that will also work.
This is part of my script that uses Psychtoolbox so I'm a little bit restricted in what I can do. Once I have created checks I use it to generate a texture to draw up to the screen while scaling it up to make it bigger.
Can anyone help?
Code:
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);

Respuestas (1)

John D'Errico
John D'Errico el 4 de Ag. de 2017
Editada: John D'Errico el 4 de Ag. de 2017
Um, seriously, what do you expect? You have created a square lattice with 27 nodes in each dimension. Had you used more points, you would have a finer grid, requiring more time and memory to generate and work with. With a truly fine enough lattice, you might not notice the jaggies. After all, pictures have curves that can look smooth, but only because they have really small pixels. But what do you expect with only 27 nodes?
You are working with what is essentially an image. Pixels are square. There is no such thing as a pixel with a curved edge.
By the way, use linspace instead!
x= -1.25:0.0932:1.25
x =
Columns 1 through 13
-1.25 -1.1568 -1.0636 -0.9704 -0.8772 -0.784 -0.6908 -0.5976 -0.5044 -0.4112 -0.318 -0.2248 -0.1316
Columns 14 through 26
-0.0384 0.0548 0.148 0.2412 0.3344 0.4276 0.5208 0.614 0.7072 0.8004 0.8936 0.9868 1.08
Column 27
1.1732
As you can see, the last point is NOT 1.25. It is 1.1732. Even if you had used a more accurate stride than 0.0932, it still would not give you the correct last point. USE LINSPACE!

Categorías

Más información sobre Image display and manipulation en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by