1
+ /**
2
+ * Projection Methods
3
+ * ----------------------------------------------
4
+ *
5
+ * In this short macro we showcase how to call ImageJ's Z Projector with a Macro
6
+ * And show an example use case with background subtraction
7
+ *
8
+ * Due to the simple nature of this code, no copyright is applicable
9
+ *
10
+ * Code created for Image Processing and Analysis For Life Scientists MOOC on EdX
11
+ * https://www.edx.org/course/image-processing-and-analysis-for-life-scientists
12
+ *
13
+ * 2018 - Olivier Burri, EPFL - SV - BIOP
14
+ * https://biop.epfl.ch
15
+ */
16
+
17
+ // This variable defines whether the user sees all the comments appearing as the macro runs.
18
+ var show_comments = false;
19
+
20
+ // Check that the "Trajectories.tif" image is open
21
+ if( !isOpen("Trajectories.tif") ) {
22
+ waitForUser("Please Open Trajectories.tif, then press OK.\nThis macro works with any image stack however, results may vary.");
23
+ } else {
24
+ selectImage("Trajectories.tif");
25
+ }
26
+
27
+
28
+ image_name = getTitle();
29
+
30
+ // Cleaup
31
+ close("\\Others");
32
+
33
+
34
+ // ==== Show multiple projection methods ====
35
+
36
+ // showComment is a custom function defined at the end of the script
37
+ showComment("We are going to showcase how to perform different projection methods");
38
+
39
+ // projectImage is a custom function defined ad the end of the script
40
+ projectImage(image_name, "Max Intensity");
41
+
42
+ // Keep the title, for use later in the code
43
+ max_projected_original = getTitle();
44
+
45
+ showComment("Max Intensity Projection or MIP\nIs very often used and yields dense information with fluorescence data");
46
+
47
+ projectImage(image_name, "Average Intensity");
48
+ showComment("Average Intensity Projection\nYields a 32-bit image with the mean of each x,y pixel along time/depth");
49
+
50
+ projectImage(image_name, "Sum Slices");
51
+ showComment("Sum Slices Projection\nYields a 32-bit image with the sum value of each x,y pixel along time/depth");
52
+
53
+
54
+ // ==== Using a median projection to remove uneven background in a fluorescence image ====
55
+ showComment("Let us use the median projection to remove the uneven background");
56
+
57
+ projectImage(image_name, "Median");
58
+ median_image = getTitle();
59
+
60
+ imageCalculator("Subtract create stack", image_name, median_image);
61
+ rename("Median Projection-Subtracted "+image_name);
62
+ showComment("You can observe the use of the median filter to clean the background of the image\nWe can compare the result by performing a MIP of the original and subtracted images");
63
+ projectImage("Median Projection-Subtracted "+image_name, "Max Intensity");
64
+ max_projected_corrected = getTitle();
65
+
66
+ selectImage(max_projected_original);
67
+ showComment("Compare "+max_projected_corrected+"\nand "+max_projected_original);
68
+
69
+
70
+ // ==== Custom functions used above ====
71
+
72
+ // Convenience function to show comments if the user wishes so, based on the value
73
+ // of the global variable "show_comments" (at the top of this script)
74
+ function showComment(comment) {
75
+ if(show_comments) {
76
+ waitForUser(comment);
77
+ }
78
+ }
79
+
80
+ // Shortcut to perform the projection on the desired image and rename it accordingly
81
+ function projectImage( image, method ) {
82
+ selectImage( image );
83
+ run("Z Project...", "projection=["+method+"]");
84
+ rename(method + " - " + image);
85
+ }
0 commit comments