if/else conditional statements enable the control of a program based on a yes/no question.
There are several typical queries:
E.g.
print("one is greater than two")}
else{
print("One is not greater than two");
}if (1>2){
a=d2s(random*10,0);
will produce a random number between 0 and 10.
Write a statement to print the word "Big" if a
is greater than 5, and "small" if it is less than or equal to 5. Arrays are lists of values.
These could include values from the column of a table, a list of file names, or anything you like.
It is often helpful to store data in this form so it can be iterated through or used to make a table.
Values in a list can be called using their index position (which begins at 0).
E.g.
print(a[0]);//Prints the first value in the array i.e. 2a=newArray(2,4,6,8);
2
It is possible to perform a range of functions upon arrays, including concatenation (sticking arrays together) with Array.concat(array1,array2);
Table.showArrays
function"For Loops" enable iteration through data.
Below is an example of an array of numbers being looped through, and their values printed out in a string:
for (i = 0; i < a.length; i++) {//a.length defines the number of iterations as the number of values in "a"
value=a[i];//i will range from 0-3, to get the values of a at each position must be extracted
print("Number "+value);//prints the value in a string
}a=newArray(1,3,5,9);//a new array of four numbers
Next we're going to write a script to loop through a set of images, segment the nuclei (channel 1) and quantify the nuclear area. For assistance, see solution here.
It can be useful to experiment with small chunks of code separately, then gradually assemble into a bigger script.
getDirectory("Choose Directory")
command to select the "Image Batch" directory in the downloaded course material.
Set the output of this to a variable e.g. dir1
. getFileList(dir1)
to make a list of the files. Set a variable to save this file list to.open(path)
run("Stack to Images");
rename("Original");
Each of your images will have different names, but if they're renamed at the start then they can share code to
find and manipulate them. Table.getColumn(columnName)
, where your "columnname" is whatever it
appears as in the tableareas_array=newArray()
at the start of your script to which
you can concatenate the values for each image, so it can ultimately be added to a table of total resultsareas_array
arrayclose("*");
close("Label-Morphometry")
. NB. The title of this table may vary depending on your method usedTable.showArrays
command. Look up associated infor for assistance.