ImageJ Cheat Sheet: Commands and User Interfaces, Cheat Sheet of Computer Applications

This ImageJ cheat sheet provides the main commands and user interfaces

Typology: Cheat Sheet

2019/2020

Uploaded on 11/27/2020

beatryx
beatryx 🇺🇸

4.6

(16)

289 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Robert'Haase (Myers'lab,'MPI-CBG);'Benoit'Lombardot,'Noreen'Walker'and'Gayathri'Nadar (Scientifi c'Computing'Facility,'MPI-CBG);'Jens'Eh rig (CMCB,'TU'Dresden)
Cheat&sheet
ImageJ&macro&commands&and&user&interfaces
Operator
Description
Example&
all&yield&a&=&9
=
Assignment
a
=9;
+
Addition
a
=3+6;
-
Subtraction
a
=11 -2;
*
Multiplication
a'
=2*4.5;
/
Division
a'
=27'/3;
++
Increment'by'1
a'
=8;''''''a++;
--
Decrement'by'1
a'
=10;''''a--;
+=
Addition'assignment
a
=3;''''''a += 6;
-
=
Subtraction'assignment
a
=11;''''a'-= 2;
*=
Multiplication
assignment
a'
=2;''''''a'*= 4.5;
/=
Division'assignment
a'
=27;''''a'/= 3;
Math&command
Description
Example
all&yield&a&=&9
pow
(x, y)
x'to'the'power
of'y
a
=pow(3, 2);
sqrt
(x)
square'root'of'x
a
=sqrt(81);
abs
(x)
absolute'value' of'x
a
=abs(-9);
round
(x)
rounding'of'x
a
=round(9.4);
floor
(x)
rounding'down
of'x
a
=floor(9.8);
String&manipulation&commands
output
=replace(input, pattern, subst);
replace'any
occurrence'of'pattern'in'input by'rsubst
outputArray
=split(input, separator);
cut'a'string'into'a'list'of
strings'(array)'according'to'the'separator'position(s)
length
=lengthOf(string);
returns'
number'of'characters'of'the'string (see'below'for'“lengthOf(array)”)
result
=startsWith(input, pattern);
returns'true,'if'input
starts'with'given'pattern
result
=endsWith(input, pattern);
returns'true,'if'input
end'with'pattern
// comments for code documentation
numericVariable =5;
stringVariable ="text value";
builtInCommand();
Macro&language&elements
a =5;
if (a == 5) {
print("a is five!");
} else {
print("a is not five!");
}
print("Bye!");
Conditional&programming&(if statement)
// define a custom function
function customFunction (param) {
return param * 2;
}
a =customFunction(3);// call the function
Custom&functions
Operator
Example
for&a&= 2;&b&=&3;
<
,<=
than,'smaller'or'equal'to
c'
=(a'<b);'''''//
c'is'1'(“true”)
>
,>=
than,'greater'or'equal'to
c'
=(a'>b);''''//
c'is'0'(“false”)
==
to
c
=(a==b);''''//
c'is'0'(“false”)
!=
1
c
=(a!= 1);'''//
c'is'1'(“true”)
Conditions&and&logical&operators
while (condition) {
// do sth at each loop iteration
// until condition is false
}
Iterative&programming&(while loop)
a b
AND”:'a &&
b
(corresp.'to'a*b)
OR”:'a || b
(~corresp.'to a+b)
NOT”:'!a
(corresp.'to'1-a)
0 0 0 0 1
1 0 0 1 0
0 1 0 1
1 1 1 1
true || true && false à1 +1 *0 =1
(
true || true)&& false à(1+1)*0=0
// create arrays
v =newArray(3, -4, 0);
// arrays can also hold strings
animals =newArray("Dog","Cat","Mouse");
// access individual array elements
v[0]=3;
// NOTE: the first element has index 0!
// output arrays
Array.print(v);
// create an empty array of given size
v =newArray(3);
Array.print(v);
// combine arrays
mixed =Array.concat(v, animals);
// determine size of an array
numberOfElements =lengthOf(v);
Vectors&/&arrays
1
Iterative&programming&(for loop)
for(i = 0; i < 3; i++ ) {
print("i is " +i);
}start with'this
before each'loop:'check'&'only'continue'if'this'is'true
after each'loop:'do'this
1
1
2
2
3
3
pf2

Partial preview of the text

Download ImageJ Cheat Sheet: Commands and User Interfaces and more Cheat Sheet Computer Applications in PDF only on Docsity!

Robert Haase (Myers lab, MPI-CBG); Benoit Lombardot, Noreen Walker and Gayathri Nadar (Scientific Computing Facility, MPI-CBG); Jens Ehrig (CMCB, TU Dresden)

Cheat sheet

ImageJ macro commands and user interfaces

Operator Description Example all yield a = 9

= Assignment a = 9 ;

+ Addition a = 3 + 6 ;

  • Subtraction a = 11 - 2 ;

* Multiplication a = 2 * 4.5;

/ Division a = 27 / 3 ;

++ Increment by 1 a = 8 ; a++;

-- Decrement by 1 a = 10 ; a--;

+= Addition assignment a = 3 ; a += 6 ;

  • = Subtraction assignment a = 11 ; a - = 2 ;

*= Multiplication assignment a = 2 ; a *= 4.5;

/= Division assignment a = 27 ; a /= 3 ;

Math command Description Example all yield a = 9

pow(x, y) x to the power^ of y^ a = pow( 3 , 2 );

sqrt(x) square root of x^ a = sqrt( 81 );

abs(x) absolute value of x^ a = abs(- 9 );

round(x) rounding of x^ a = round(9.4);

floor(x) rounding down^ of x^ a = floor(9.8);

String manipulation commands

output = replace(input, pattern, subst);

replace any occurrence of pattern in input by rsubst

outputArray = split(input, separator);

cut a string into a list of strings (array) according to the separator position(s)

length = lengthOf(string);

returns number of characters of the string (see below for “lengthOf(array)”)

result = startsWith(input, pattern);

returns true, if input starts with given pattern

result = endsWith(input, pattern);

returns true, if input end with pattern

// comments for code documentation

numericVariable = 5 ;

stringVariable = "text value";

builtInCommand();

Macro language elements

a = 5 ;

if (a == 5 ) {

print("a is five!");

} else {

print("a is not five!");

print("Bye!");

Conditional programming (if statement)

// define a custom function

function customFunction (param) {

return param * 2 ;

a = customFunction( 3 ); // call the function

Custom functions

Operator Description Example for a = 2; b = 3;

<, <= smaller than, smaller or equal to c = (a < b); // c is 1 (“true”)

, >= greater than, greater or equal to c = (a > b); // c is 0 (“false”) == equal to c = (a==b); // c is 0 (“false”) != not equal to^1 c = (a != 1 ); // c is 1 (“true”)

Conditions and logical operators

while (condition) {

// do sth at each loop iteration

// until condition is false

Iterative programming (while loop)

a b

“ AND ”: a && b

(corresp. to a*b)

“ OR ”: a || b

(~corresp. to a+b)

“ NOT ”: !a

(corresp. to 1-a)

true || true && false à 1 + 1 * 0 = 1

(true || true) && false à ( 1 + 1 ) * 0 = 0

// create arrays

v = newArray( 3 , - 4 , 0 );

// arrays can also hold strings

animals = newArray("Dog","Cat","Mouse");

// access individual array elements

v[ 0 ] = 3 ;

// NOTE: the first element has index 0!

// output arrays

Array.print(v);

// create an empty array of given size

v = newArray( 3 );

Array.print(v);

// combine arrays

mixed = Array.concat(v, animals);

// determine size of an array

numberOfElements = lengthOf(v);

Vectors / arrays

1

Iterative programming (for loop)

for (i = 0 ; i < 3 ; i++ ) {

print("i is " + i);

} start with this

before each loop: check & only continue if this is true after each loop: do this

Robert Haase (Myers lab, MPI-CBG); Benoit Lombardot, Noreen Walker and Gayathri Nadar (Scientific Computing Facility, MPI-CBG); Jens Ehrig (CMCB, TU Dresden)

Cheat sheet

ImageJ macro commands and user interfaces

Navigation in image stacks

Stack.getDimensions(width, height, channels, slices, frames); Stack.setSlice(slice); Stack.setChannel(channel); Stack.setFrame(frame); Stack.setDisplayMode("color"); Stack.setDisplayMode("composite"); Stack.setDisplayMode("grayscale");

Handle image files and folders

open(folder+imageFilename); close(); fileList = getFileList(folder); numFiles = lengthOf(fileList); for (i= 0 ;i<lengthOf(fileList);i++){ file = fileList[i]; open(file); // actual image processing... close(); }

Switch between image windows

titleOfCurrentImage = getTitle(); selectWindow(titleOfAnyImage);

Calling any ImageJ/FIJI menu

run("Enhance Contrast...", "saturated=0.3 normalize")

Best practices in developing software

Divide and rule

  • Split complex issues into smaller,

accessible issues

  • If a function solves several issues, split it

in separate functions.

Don’t repeat yourself (DRY)

  • Don’t copy code if similar things are done

twice, because you may copy

programming errors.

  • Program a loop or custom function

instead. Maintenance is easier then.

Keep it short and simple (KISS)

  • develop code so that others can read,

understand and maintain it.

Variable and function names

  • name functions after what they do,

(verb + object). e.g.: analyzeImage()

  • name variables after what they contain,

e.g.: ("A" versus "area")

  • assign parameter values at the beginning

of the script, so you do not have to search

for them once you want to change them

Result tables

run("Set Measurements...", "area mean standard min centroid"); corresp. to this: run("Analyze Particles...", "add clear display"); roiManager("Measure"); rowCount = nResults(); value = getResult("column title", rowNumber); setResult("column title", rowNumber, newValue); saveAs("Results","myResults.xls"); run("Clear results");

Ask for user action

waitForUser("headline", "prompt");

Useful links

ImageJ macro reference https://imagej.nih.gov/ij/developer/macro/macros.html https://imagej.nih.gov/ij/developer/macro/functions.html ImageJ / Fiji plugins https://imagej.net/Category:Plugins Forum http://forum.imagej.net/ Macro code auto formatter http://jsbeautifier.org/

Basic image statistics

getStatistics(area, mean, min, max, standard_deviation);

ROI manager

roiManager("add"); roiManager("split"); roiManager("delete"); roiManager("reset"); roiManager("measure"); roiManager("count"); roiManager("open", filename); roiManager("save", filename); roiManager("save selected", filename); roiManager("select", index); roiManager("select", newArray(index1, index2, ...)); roiManager("deselect"); roiManager("show all"); roiManager("show all with labels"); roiManager("show none"); roiManager("and");

Reading image calibration roiManager("combine");

getPixelSize(unit, pWidth, pHeight); getVoxelSize(vWidth, vHeight, vDepth, unit);

Generate user interfaces with #@Parameter

Syntax: #@ ()

#@ String(label="Your Text") userText #@ String(value="Some useful hints...", visibility="MESSAGE") hints #@ String(label="Analyst name", description="Your name") analystName #@ String(choices={"A", "B"}, style="radioButtonHorizontal") ROI #@ String(label="Exp. Group", choices={"Mutant", "Control"}, style="list") expGroup #@ Integer(label="Ratio 1") r #@ Integer(label="Ratio 2", value= 25 , min= 0 , max= 100 , style="slider") r #@ Double(value=0.7, min= 0 , max= 1 , label="A real number") realNumber #@ File(style="open") inputFile #@ File(style="save") outputFile #@ File(style="directory") imageFolder #@ ColorRGB(value="red") color #@ Boolean(label="Show Preview?") preview