-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScript
More file actions
159 lines (139 loc) · 7.07 KB
/
Copy pathScript
File metadata and controls
159 lines (139 loc) · 7.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
// This is an ImageJ macro for semi-automated quantification of immunofluorescent images with two color channels (default: %area, cell number)
// First you have the option to manually correct the background and select the area of interest
// Then the markers get segmented with an *automated* threshold. Please don't do this step manually to avoid observer bias!
// Choose the respective thresholding method with care, this is the most crucial step of the evaluation pipeline!
// You have the option to check the thresholding with userVerficiation() for each individual image. Or you can comment this step out with a "//"
// Finally, measurements are done on the segmented images and the results are saved. The specific measurements are defined in line 47
// Happy image evaluation :-)
// Copyright 2020, Theresa Suckert, OncoRay/DKTK Dresden
// email: t.suckert@dkfz-heidelberg.de
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// 3. Neither the name of the copyright holder nor the names of its contributors
// may be used to endorse or promote products derived from this software without
// specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
// IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
// NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//####################################################################################
// Configuration
//clean up before we start
//Check if the summary window is closed
run("Close All");
run("Clear Results");
//define the settings for later evaluation, depending on what you want to measure:
run("Set Measurements...", "area_fraction redirect=None decimal=2");
Composite = "Composite";
var savename = 0;
//Executed:
processImage();
exit();
//Here you can find the called subfunctions, see below for details
function processImage(){
opening();
preprocessing();
thresholding();
userVerification();
evaluation();
saving();
};
function opening(){
//This part of the skript was written to work with the BioFormats import function!
//[if you have bioformats import,] choose the file you want to process and use the following settings:
//Autoscale, Color mode=Composite, all the others unchecked --> OK, then series with highest resolution
file = File.openDialog('select file');
open(file);
path= getDirectory("image");
rename(Composite);
name = File.nameWithoutExtension();
savename = path + name;
return savename;
};
function preprocessing(){
//the channels are going to be processed seperately. For this, we need to split the channels.
//Single channel images get duplicated and the following steps performed on the duplicated image. They get renamed according to their marker
//For later confirmability, the original channel images are kept and optimized
//Comment: Artefacts are e.g. dust specs, non-relevant tissue relicts, or black edges at the corners due to tile aquisition
selectWindow("Composite");
run("Split Channels");
//selectWindow("C2-Composite");
run("Window/Level...");
run("Enhance Contrast", "saturated=0.35");
waitForUser("Background correction", "Artefacts in the background can screw up your thresholding. \nChoose the color picker and click on representative background. \nUse Flood fill tool and paint tool to get an even backround. \nYou can also remove tissue you want to exclude from evaluation. \nClick ok to proceed.");
run("Duplicate...", "title=mask-tumor");
waitForUser("Mask area of interest", "Use Freehand selections. Hold shift to mark several areas. Hold Alt to remove areas. Click ok when done.");
selectWindow("C2-Composite");
run("Duplicate...", "title=dapi-mask");
selectWindow("C1-Composite");
run("Window/Level...");
run("Enhance Contrast", "saturated=0.35");
run("Close");
waitForUser("Background correction", "Artefacts in the background can screw up your thresholding. \nChoose the color picker and click on representative background. \nUse Flood fill tool and paint tool to get an even backround. \nYou can also remove tissue you want to exclude from evaluation. \nClick ok to proceed.");
run("Duplicate...", "title=marker-mask");
};
function thresholding(){
//now we mask the picture by thresholding. The thresholding method may have to be adjusted to your images
selectWindow("marker-mask");
setAutoThreshold("Triangle dark");
run("Make Binary");
run("Close-");
selectWindow("dapi-mask");
setAutoThreshold("Triangle dark");
run("Make Binary");
run("Watershed");
};
function userVerification(){
//This is a verification step, so that the user can check if the thresholding yields reasonable results
//If the answer is no, abort and rerun the programm with a different thresholding method!
waitForUser("Verification of Thresholding", "Click ok if applied threshold is suitable, kill if not");
//in a second step you can manually exclude image artefacts (e.g. PapPen or bubbles) by painting them black
//This means they get assigned the value 0
waitForUser("Remove artefacts", "Use painting tools to eliminate background artefacts, then click ok");
};
function evaluation(){
selectWindow("mask-tumor");
selectWindow("marker-mask");
run("Restore Selection");
run("Analyze Particles...", "summarize slice size=0-Infinity summarize");
selectWindow("mask-tumor");
selectWindow("dapi-mask");
run("Restore Selection");
run("Analyze Particles...", "summarize slice size=0-Infinity summarize");
};
function saving(){
//Finally, save the images in a stack for later verification. RGB is needed otherwise all pics will get the same LUT
//Save the summary in a .csv file
//Remember to choose the right seperators in your Excel settings when further processing the data
selectWindow("mask-tumor");
run("Flatten");
run("RGB Color");
selectWindow("mask-tumor");
run("Close");
selectWindow("C1-Composite");
run("RGB Color");
run("Images to Stack", "title=[] use");
savenameImage = savename + "_evaluation";
saveAs(".Tiff", savenameImage);
savenameSummary = savename + "_results.csv";
selectWindow("Summary");
saveAs("Results", savenameSummary);
run("Close");
run("Close All");
};