Creating a Checkerboard Image
QUESTION: It is sometimes useful to have a checkerboard image for various image processing and image masking tasks. Is there an easy way to create such an image in IDL? I've written such a function, but I'm embarrassed to show it to anyone. I'm pretty sure its not written in the “IDL Way.”
ANSWER: Who else but JD Smith provided us with an example of how to do this in the IDL Way.
nx = 300 ny = 200 nrects = 10 xside = nx/nrects yside = ny/nrects board = lindgen(nx,ny) board = (board mod (xside*2) lt xside) XOR (board/nx mod (yside*2) ge yside)
You can see the result in the figure below.
IDL> TVScale, board, /NOINTERP
The checkerboard image created the IDL Way. |
There are a couple of other caveats to worry about with this. For example, the number of squares you want should always be an even number. With these in mind, I have written a function named Checkerboard that allows you to create a checkerboard image of any size with a specified number of boxes. By default, the function defaults to the eight boxes on a side for a real checkerboard.
Copyright © 2007 David W. Fanning
Last Updated 26 September 2007