Saturday, October 8, 2011

Drawing a chessboard using ImageJ array



My chessboard series continues with a new script based on arrays and how we can use them in ImageJ.



In this algorithm , a stack of 64 slices is created and then displayed as a montage of 8 rows and 8 columns with the function makeMontage (in Image > Stacks > Make Montage).
Each slice of the stack (corresponding to a cell of the chessboard) must be colored in black or white. The colors are stored in an array created with the built-in function newArray(...). Instead of storing the colors (0 and 255), I use 0 for black and 1 for white color (lines 10-19 of the following script).
The main algorithm consists of a loop for scanning the whole cells array. The value is multiplied by 255 and used by the setColor(...) function. Finally, a black (or white) rectangle is drawn (fillRect(...) function ) in the ith slice (setSlice(index+1) ).

+++ IJ snippet +++ end of IJ snippet

No comments:

Post a Comment