You are on page 1of 2

//ImageJ macro for writing a stream file for FEI Nova Nanolab 200 system

//Kevin Lim
//Oct 2014
WARNINGS = 1; //prompt the user with warning messages when appropriate
W = getWidth();
H = getHeight();
if (WARNINGS==1) {
waitForUser("WARNING: input image will be automatically resized to fit i
nto a write field of 4096 by 4096 pixels.");
}
if (W != 4096 || H != 4096) {
run("Size...", "width=4096 height=4096 constrain average interpolation=B
ilinear");
if (WARNINGS==1) {
waitForUser("WARNING: pattern-writing may be less accurate outside the y
-range of 280-3816, due to limitations of the 12-bit pattern generator in FEI No
va Nanolab 200 system. Click OK when done, or hit Esc to abort the macro.");
}

getStatistics(area, mean);
if (mean >= 128 && WARNINGS==1) {
waitForUser("WARNING: the code runs very slowly if the image is predomin
antly black on a white background (check the pixel values). \n You may wish to i
nvert the image colours before clicking OK to continue. Alternatively, press the
Esc key to abort the macro.");
}

//set maximum dose (dwell time) in units of 0.1 us


Dmax = getNumber("Please enter the maximum spot dwell time in microseconds (us)"
, 100) / 0.1;
//set proximity corrected dose level (dwell time)
Ddim = 0.5 * Dmax;
//set pixel value range to 0-255
run("8-bit");
//set threshold for pixels to be written
t0 = 1;
//set threshold for bright/dim pixels
t1 = 128;

//create stream file


title=getTitle();
if (File.exists(title+".txt") && WARNINGS==1) {
waitForUser("WARNING: a file with filename corresponding to the title of
the image already exists. \n Do you want to proceed? Click OK to continue or pr
ess the Esc key to cancel.");
}

File.saveString("", title+".txt");
f = File.open(title+".txt");

//start writing to stream file


print(f, "s");
//set number of passes to make
print(f, "1"); //choose 1 to avoid undesired streaking between patterns
//initialise counter for pixels that will be written
count = 0;
//count pixels that will be written
W = getWidth();
H = getHeight();
for (j=0;j<H;j++) {
for (i=0;i<W;i++) {
p = getPixel(i,j);
if (p >= t0) { //if pixel is above threshold to be written
count++;
}
}
}
//specify the number of pixels that will be written
print(f, count);

//scan through the image and convert to pixels in stream file


for (j=0;j<H;j++) {
for (i=0;i<W;i++) {
p = getPixel(i,j);
if (p >= t0) { //if pixel is on
if (p >= t1) { //bright pixel
print(f, Dmax+"\t"+i+"\t"+j+"\n");
} else { //dim pixel
print(f, Ddim+"\t"+i+"\t"+j+"\n");
}
}
}
}

//save the stream file


File.close(f);
waitForUser("Converted and saved " + title + ".txt");

You might also like