Commit ffe9eefb authored by rhaase's avatar rhaase

added lesson 04

parent 95fcbbac
// Define two arrays with 5 elements
x_values = newArray(5);
y_values = newArray(5);
// put some numbers in these 2x5 array elements
x_values[0] = 10;
y_values[0] = 1;
x_values[1] = 20;
y_values[1] = 1.2;
x_values[2] = 30;
y_values[2] = 1.3;
x_values[3] = 40;
y_values[3] = 1.3;
x_values[4] = 50;
y_values[4] = 1.1;
Plot.create("Title", "X-axis Label", "Y-axis Label", x_values, y_values);
Plot.show();
// numeric arrays
v = newArray(3, -4, 0);
Array.print(v);
// create an array with three elements containing zeros
v = newArray(3);
Array.print(v);
// manipulate arrays
v[0] = 3.5
Array.print(v);
// access array elements
print( v[2] );
// string arrayss
animals = newArray("dog", "cat", "mouse");
// combining arrays
mixed = Array.concat(v, animals);
Array.print(mixed);
// get length of an array
numberOfElements = lengthOf(v);
print("v has " + numberOfElements + " elements");
array = newArray(5);
Array.print(array);
berry = array;
berry[3] = "Wow!";
Array.print(array);
// working with variables
print("Variables:");
a = 0;
print(a);
b = a;
b = 5;
print(a);
// working with arrays
print("Arrays:");
array = newArray(5);
Array.print(array);
berry = array;
berry[3] = "Wow!";
Array.print(array);
name = "firstname lastname";
experiment_number = "0";
Dialog.create("Experiment analysis");
Dialog.addMessage("This message serves explaining you this window.");
Dialog.addString("Your name", name);
Dialog.addNumber("Experiment number", experiment_number);
// this will show the dialog on screen
Dialog.show();
// Code execution will continue after the user clicked ok
name = Dialog.getString();
experiment_number = Dialog.getNumber();
// show what has been entered
print(name + " is analysing experiment number " + experiment_number);
// initialize some variables
a = 3;
b = 5;
// do computation with a custom function
c = sum(a, b);
// print out result
print(c);
// we now call an addtional function for getting the
// mean intensity of the image
mean_intensity = get_mean_intensity_of_image();
print("mean_intensity: " + mean_intensity);
// this function determines the mean intensity of the image
// and returns it
function get_mean_intensity_of_image() {
getStatistics(area, mean, min, max, std, histogram);
return mean;
print("Hello world!");
}
// This functions computes the sum of two numbers
function sum(summand1, summand2) {
the_sum = summand1 + summand2;
return the_sum;
}
run("Close All");
// Draw filled elipses
newImage("Overlays", "8-bit black", 200, 200, 1);
makeOval(11, 12, 59, 58);
Roi.setFillColor(220, 200, 4);
Overlay.addSelection();
// Draw outline elipses
makeOval(40, 92, 46, 41);
Roi.setStrokeColor("Green");
Overlay.addSelection();
// Draw filled elipses, with outline
makeOval(100, 55, 36, 61);
Overlay.addSelection("", 0, "blue");
makeOval(100, 55, 36, 61);
Overlay.addSelection("Cyan", 3);
run("Select None");
\ No newline at end of file
directory = getDirectory("Choose a Directory");
filelist = getFileList(directory)
for (i = 0; i < lengthOf(filelist); i++) {
if (endsWith(filelist[i], ".tif")) {
print(directory + File.separator + filelist[i]);
}
}
run("Close All");
// Draw rectangles
newImage("Rectangles", "8-bit black", 200, 200, 1);
makeRectangle(11, 12, 59, 58);
Roi.setFillColor(220, 200, 4);
// Draw elipses
newImage("Ovals", "8-bit black", 200, 200, 1);
makeOval(40, 92, 46, 41);
Roi.setStrokeColor("Green");
Roi.setStrokeWidth(3);
// Draw Text
newImage("Text", "8-bit black", 200, 200, 1);
makeText("Hello", 20, 20);
// get the number of ROIs in the ROI manager
number_of_rois = roiManager("count")
// loop over all regions of interest in the ROI manager
for (i = 0; i < number_of_rois; i++) {
// select an entry in the ROI manager
roiManager("select", i);
// change its color
Roi.setStrokeColor("yellow");
// store it in the overlay
Overlay.addSelection();
}
// unselect any ROI
run("Select None");
// turn the image into an RGB image which can be opened
// in other programs still containing the ROIs
run("Flatten");
// clean up the ROI manager
if (roiManager("count") > 0) {
roiManager("Deselect");
roiManager("Delete");
}
// close all images
run("Close All");
// empty results table
run("Clear Results");
// open input data
run("Blobs (25K)");
// set a threshold
setAutoThreshold("Default");
// do connected components analysis
// -> Save measurements to the table
// -> Save ROIs to the ROIManager
run("Analyze Particles...", "display add");
// reset the threshold to make the image look normal again
resetThreshold();
// visualise nothing
roiManager("Show None");
number_of_rois = roiManager("count");
for (i = 0; i < number_of_rois; i += 1) {
// select an ROI
roiManager("select", i);
area = getResult("Area", i);
// give it a color
if (area > 250) {
Roi.setStrokeColor("green");
} else {
Roi.setStrokeColor("magenta");
}
// store it in the Overlay
Overlay.addSelection();
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment