Skip to content

Commit 9905168

Browse files
author
Olivier Burri
committed
updated week 3 macro code
1 parent 6f8115a commit 9905168

4 files changed

+46
-47
lines changed

Week-03/Image Math - Global Operations.ijm

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ for(i=0; i<operations.length; i++) {
4242

4343
// Convert to 32-bit to perform proper image math
4444
run("32-bit");
45+
// Set the zoom to make the image a bit larger
4546
run("In [+]");
4647

4748
// Running the actual mathematical operation

Week-03/Image_Resizing.ijm

+6-5
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,20 @@ modifiedBy10 = downUpScale (ori_blobs_ID , 10) ;
3030
run("Tile");
3131
waitForUser("From the 'blobs' image we created 'degraded' versions by downscaling and upscaling without interpolation.");
3232

33-
// make a stak from the different images
33+
// make a stack from the different images
3434
run("Images to Stack", "method=[Copy (top-left)] name=Stack title=[] use");
35+
waitForUser("The images are now re-arranged as a Stack.\nDue to downscaling and upscaling, the images have different widths and heights.\nThis is why the bottom and right edges have pixels at 0 in some slices");
3536
// as an alternative you can use method=[Copy (Center)].
36-
// due to downscaling and upscaling the images have different width and height
37+
//
3738
// the results would then be different
3839

39-
// here we make a line. by defining the point
40+
// here we make a line. by defining the start and end points
4041
makeLine(75, 100, 90, 130);
41-
waitForUser("The images are now re-arranged as a Stack.\nWe also made a line on the image, not let's plot it.")
42+
waitForUser("We also made a line on the image,\nand we will plot the intentities along that line.")
4243

4344
// and here we ask for the plot.
4445
run("Plot Profile");
45-
waitForUser("In the 'Plot' window, click on 'Live'.\nNow, move in the stack using the slider to compare the profiles.\nYou can also move the line by selecting points");
46+
waitForUser("In the 'Plot' window, click on 'Live'.\nNow, move in the stack using the slider to compare the profiles.\nYou can also move or modify the line by click-dragging its anchor points");
4647

4748
// To continue you can have a look to the CurveFittingDemo : https://imagej.net/ij/macros/examples/CurveFittingDemo.txt
4849
// that makes use of Fit functions : https://imagej.net/ij/developer/macro/functions.html#Fit

Week-03/Ratio Demo Analysis Macro.ijm

+2-3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* 2018 - Olivier Burri, EPFL - SV - BIOP
1414
* https://biop.epfl.ch
1515
*/
16+
1617
run("Close All");
1718
waitForUser("Please Open 'Ratio Demo Image_Cleaned.tif'\nand press OK.");
1819
// Use Batch Mode to avoid showing intermediate steps
@@ -62,9 +63,7 @@ setLocation(200, 200);
6263
// Create a Scale Bar to Go With the Image
6364
newImage("Scale 0 to 5.0", "32-bit ramp", 256, 20, 1);
6465
run("6 shades");
65-
66-
67-
// Make it Vertical
66+
// and make it Vertical
6867
run("Rotate 90 Degrees Left");
6968

7069
// The Ramp 32 bit image goes from 0 to 1 so we multiply it by 5 so it matches our image scale

Week-03/Stack Illumination Correction Demo.ijm

+37-39
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,44 @@
1313
* https://biop.epfl.ch
1414
*/
1515

16-
run("Close All");
17-
waitForUser("Please open the file Worm-Bad-Illumination.tif\nThen press OK");
16+
17+
18+
if(!isOpen("worm-bad-illumination.tif") ) {
19+
run("Close All");
20+
// Ask for file using dialog to open it
21+
image = File.openDialog("Please Select the file 'worm-bad-illumination.tif'");
22+
open(image);
23+
24+
}
25+
26+
// Make sure the right image is selected
27+
selectImage("worm-bad-illumination.tif");
28+
29+
// Build a dialog to ask for the normalization method
30+
methods = newArray("Min-Max", "Mean");
31+
32+
Dialog.create("Normalization Methods");
33+
Dialog.addChoice("Method to apply", methods, methods[0]);
34+
Dialog.addNumber("Provide the new mean value that will be given to each slice of the stack", 10000);
35+
Dialog.show();
36+
37+
the_method = Dialog.getChoice();
38+
new_mean = Dialog.getNumber();
1839

1940
// Getting the imasge title helps us rename the image neatly later on in the code
2041
imageName = getTitle();
2142

22-
newMean = getNumber("Provide the new mean value that will be given to each slice of the stack", 10000);
23-
2443
// Get the siye of the stack through getDimensions()
2544
getDimensions(x,y,c,z,t);
2645

2746
// Before performing any operation, we duplicate the image in order to avoid losing the original
2847
// We also rename it, so we know what was done to it
29-
run("Duplicate...", "duplicate title=["+imageName+"-Corrected]");
48+
run("Duplicate...", "duplicate title=["+imageName+"-Corrected "+the_method+"]");
3049

3150
// Conversion to 32-bits is very important when performing mathematical operations
3251
run("32-bit");
3352

53+
3454
// We will now go through each timepoint and
3555
for(i=1; i<t+1;i++) {
3656

@@ -42,44 +62,22 @@ for(i=1; i<t+1;i++) {
4262

4363
// This print to the log window is not necessary, but shows the user something is happening
4464
print(area, mean, min, max);
45-
46-
// Formula: each pixel has a new value
47-
// newVal = (val - min) / (max - min) * newMean
48-
49-
run("Subtract...", "value="+min+" slice");
50-
run("Divide...", "value="+(max-min)+" slice");
51-
run("Multiply...", "value="+newMean+" slice");
65+
if (the_method == "Min-Max") {
66+
// Formula: each pixel has a new value
67+
// newVal = (val - min) / (max - min) * newMean
68+
69+
run("Subtract...", "value="+min+" slice");
70+
run("Divide...", "value="+(max-min)+" slice");
71+
run("Multiply...", "value="+new_mean+" slice");
72+
} else {
73+
run("Divide...", "value="+(mean)+" slice");
74+
run("Multiply...", "value="+new_mean+" slice");
75+
}
5276
}
5377

5478
// we ensure that the image is viewable
55-
setMinAndMax(0, newMean*2);
79+
setMinAndMax(0, new_mean*2);
5680

57-
// Second Method using only the mean of each slice
58-
selectImage(imageName);
59-
// We also rename it, so we know what was done to it
60-
run("Duplicate...", "duplicate title=["+imageName+"-Corrected v2]");
61-
62-
// Conversion to 32-bits is very important when performing mathematical operations
63-
run("32-bit");
64-
65-
// We will now go through each timepoint and
66-
for(i=1; i<t+1;i++) {
67-
68-
69-
Stack.setFrame(i);
70-
71-
getStatistics(area, mean, min, max);
72-
73-
// This print to the log window is not necessary, but shows the user something is happening
74-
print(area, mean, min, max);
75-
76-
// Formula: each pixel has a new value
77-
// newVal = Val / mean * newMean
78-
79-
run("Divide...", "value="+(mean)+" slice");
80-
run("Multiply...", "value="+newMean+" slice");
81-
}
82-
setMinAndMax(0, newMean*2);
8381
run("Tile");
8482

8583
waitForUser("Observe the original and modified images and interpret what you see");

0 commit comments

Comments
 (0)