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 +++
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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"); |
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