MATLAB: How to create black and white checkerboards with different number of squares

checkerboard

How can I create black and white checkerboard with different number of squares, for example, 2 squares, 4, 8, 16,32….
with the inbuilt checkerboard function, there is grey squares, which is undesirable

Best Answer

The output of checkerboard() contains normalized values where 0 represents black, 1 represents white, and values between represent shades of gray. Just replace the values greater than 0 with 1.
I = checkerboard(20);
I(I>0) = 1;
imshow(I)
Related Question