Friday, September 2, 2011

Drawing a chessboard v2.0



Another version in my series Drawing a chessboard. This is a little bit simpler than the previous one...

It is easier to work on a 8x8 image and then to scale it to the desired size. The fillRect(x,y,w,h) is replaced by a setPixel(x,y,255). The value '255' corresponds to the white color in a 8-bit image. Thus, the script becomes:

+++ IJ snippet: chessboard_v2_imagej.ijm +++
//
// chessboard version 2.0
// Jean-Christophe Taveau
//
chessSize=512;
newImage("chess", "8-bit Black", 8, 8, 1);
for (y=0;y<8;y++)
{
for (x=0;x<8;x++)
{
if ((x+y)%2==0) {
setPixel(x,y,255);
}
}
}
// Scale the 8x8 image to build the final chessboard
run("Size...", "width="+chessSize+" height="+chessSize+" constrain average interpolation=None");
view raw gistfile1.js hosted with ❤ by GitHub
+++ End of IJ snippet +++

In ImageJ, the fastest and the most concise way I found is described in another post  'Drawing a chessboard: new version'.

No comments:

Post a Comment