-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJazy_whatever_map.ijm
executable file
·318 lines (250 loc) · 8.89 KB
/
Jazy_whatever_map.ijm
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
//Version 0.0.14a
//-----------------------------------------------------------------------------------------
//-----------------------------------Map-particle-porperties-to-image----------------------
//---------------------------------------------ImageJ--------------------------------------
// todo : holes will not be filled, however, maybe one could ask the user if this is desired
macro "invert inverted LUT [z]"{
run("Invert LUT");
run("Invert");
}
macro "invert image [i]"{
run("Invert");
}
macro "whatevera map [a]"
{
//function calc_filcol(fval,user_max_val,user_min_val)
// shoudl calculate a color within the range
// maxC-minC, e.g. 1-255 or 0-254
// from values fval within the user supplied (or measured)
// range user_min_val, user_max_val
function calc_filcol(fval,user_max_val,user_min_val,maxC,minC) {
return (((fval-user_min_val)/(user_max_val-user_min_val))*(maxC-minC))+minC
}
//adapted from ROI color coder
function getLutList() {
luts= getFileList(getDirectory("luts"));
for (i=0, count=0; i<luts.length; i++)
if (endsWith(luts[i], ".lut"))
count++;
list= newArray(count+3);
list[0]= "Fire"; list[1]= "Ice"; list[2]= "Spectrum";
for (i=0, j=3; i<luts.length; i++)
if (endsWith(luts[i], ".lut"))
list[j++]= substring(luts[i], 0, lengthOf(luts[i])-4);
return list;
}
// global minC maxC values (range of in LUT) - might be overwritten locally
minC=1;
maxC=254;
if(is("binary") == 1){
autoUpdate(false);
setBatchMode(true);
print("\\Clear");
roiManager("reset");
run("Select None");
otit = getTitle;
//--------------------------------create-info-dialog-------------------------------------------------
Dialog.create("Info");
Dialog.addMessage("Use WHITE particles on BLACK background \n and do NOT use an inverted LUT.");
Dialog.show();
//--------------------------------create-info-dialog-------------------------------------------------
Dialog.create("More Info");
Dialog.addMessage("This macro will set 'Process->Binary->Options...' \n to BLACK background. If you rely on white background, \n make sure to reset it afterwards.");
Dialog.show();
//--------------------------------1st measurement -------------------------------------------------
// interesting option to set to make it work...form binary meanu
run("Options...", "iterations=1 count=1 black do=Nothing");
setThreshold(255,255);
// run this to get rid of particles touching edge ------------------------------------------------
run("Set Measurements...", "area redirect=None decimal=1");
run("Analyze Particles...", "size=0-Infinity circularity=0.00-1.00 show=Masks exclude clear");
run("Invert LUT");
run("Select None");
run("Remove Overlay");
rename(otit +"map_of_");
//selectWindow("Log");
//run("Close");
//selectWindow("ROI Manager");
//run("Close");
//run("Make Binary");
//--------------------------------create-map-type-dialog-------------------------------------------------
Dialog.create("Select map type");
items = newArray("Area", "Diameter", "DiameterCorr", "Aspect ratio", "Axial ratio" , "Angle" , "Circularity" , "Solidity" , "ElliLength" ,"ShapeFactor1");
Dialog.addRadioButtonGroup("Maptype", items, 9, 1, "Area");
Dialog.show;
maptype = Dialog.getRadioButton;
//--------------------------------create-LUT-dialog-------------------------------------------------
Dialog.create("Choose LUT ");
luts= getLutList();
Dialog.addChoice("LUT:", luts, luts[1]);
Dialog.show;
luttype = Dialog.getChoice;
//print(luttype);
//--------------------------------measure-something---------------------------------------------------
run("Clear Results");
run("Set Measurements...", "area center perimeter fit shape redirect=None decimal=5");
run("Analyze Particles...", "size=0-Infinity circularity=0.00-1.00 show=Nothing exclude clear record add");
// starting coordinates of each particle - later used for filling
n=roiManager("count");
xstart = newArray(n);
ystart = newArray(n);
for (i=0; i<roiManager("count"); i++){
xstart[i] = getResult("XStart",i);
ystart[i] = getResult("YStart",i);
}
if (maptype =="Area"){ //----------------------------AREA[0 - ++]---------------------------------------------------
qtype = "Area";
maxval = 0;
minval = getWidth * getHeight;
}
if (maptype =="Diameter"){ //----------------------------Diameter--[0 - ++]-------------------------------------------------
qtype = "Area";
maxval = 0;
minval = 2 * sqrt((getWidth * getHeight)/PI);
}
if (maptype =="DiameterCorr"){ //----------------------------DiameterCorr--[0 - ++]-------------------------------------------------
qtype = "Area";
maxval = 0;
minval = 2 * sqrt((getWidth * getHeight)/PI);
}
if (maptype =="Aspect ratio"){ //----------------------------Aspect ratio--[1 - ++]-------------------------------------------------
qtype = "AR";
maxval = 0;
minval = sqrt((getHeight * getHeight)+(getWidth * getWidth));
}
if (maptype =="Axial ratio"){ //----------------------------Axial ratio--[0 - 1]------------------------------------------------
qtype = "Round";
maxval = 0;
minval =1;
}
if (maptype =="Angle"){ //----------------------------Angle-[0 - 180]--------------------------------------------------
qtype = "Angle";
//luttype = "Spectrum";
maxval = 0;
minval = 180;
}
if (maptype =="Circularity"){ //----------------------------Circularity--[0 - 1]----------------------------------------------
qtype = "Circ.";
maxval = 0;
minval = 1;
}
if (maptype =="Solidity"){ //----------------------------Solidity---[0 - 1]------------------------------------------------
qtype = "Solidity";
maxval = 0;
minval = 1;
}
if (maptype =="ElliLength"){ //----------------------------ElliLength---[0 - ++1]------------------------------------------------
qtype = "Major";
maxval = 0;
minval = getWidth * getHeight;
}
if (maptype =="ShapeFactor1"){ //----------------------------ShapeFactor1---[1 - ++]------------------------------------------------
qtype = "Nan";
maxval = 0;
minval = 100;
}
//---------------------------get-max-min--------------------------------------------------------
// get results
n=nResults;
// initialize arrays
val=newArray(n);
// in case of adding diameter with perimeter,
// rescale to pixels
getPixelSize(un, ppx, ppy); // ppx/ppy is units/pixel
if (maptype =="DiameterCorr"){
for (i=0;i<n; i++){
val[i] = getResult("Area",i) / pow(ppx,2) + getResult("Perim.",i)/ppx;
}
}else if (maptype =="ShapeFactor1"){
for (i=0;i<n; i++){
val[i] = getResult("Perim.",i) / (2 * PI * sqrt(getResult("Area",i) / PI));
print(val[i]);
}
}else {
for (i=0;i<n; i++){
val[i] = getResult(qtype,i);
}
}
Array.getStatistics(val, min, max, mean, stdDev);
// special case for radius
if (maptype =="Diameter"){
max=2 * sqrt(max/PI);
min=2 * sqrt(min/PI);
}
if (maptype =="DiameterCorr"){
max=2 * sqrt(max/PI) * ppx;
min=2 * sqrt(min/PI) * ppx;
}
//------------------------ask-what-limits-to-use--------------------------------------------------------
// query for user input of maxval
Dialog.create("max" +maptype+"");
Dialog.addMessage("Maximal "+maptype+"");
Dialog.addNumber("user_max_val:", max);
Dialog.show();
user_max_val = Dialog.getNumber();
// query for user input of minval
Dialog.create("min" +maptype+"");
Dialog.addMessage("Minimal "+maptype+"");
Dialog.addNumber("user_min_val:", min);
Dialog.show();
user_min_val = Dialog.getNumber();
//timer
t1=getTime();
//------------------------calculate-color-----------------------------------------------------------
for (i=0; i<roiManager("count"); i++){
roiManager("select",i);
run("Measure", "show=Nothing");
fval = getResult(qtype);
if (maptype =="Diameter"){
fval = 2* sqrt(fval/PI);
}
if (maptype =="DiameterCorr"){
fval = 2 * sqrt(val[i]/PI) * ppx;
}
if (maptype =="ShapeFactor1"){
fval = val[i];
}
filcol = calc_filcol(fval,user_max_val,user_min_val,maxC,minC);
//print(filcol);
setForegroundColor(filcol, filcol, filcol);
//floodFill(xstart[i],ystart[i]);
roiManager("Fill");
// write out results
setResult(maptype,i,fval);
}
updateResults();
}
run(luttype);
getLut(reds, greens, blues);
reds[0]=255;
greens[0]=255;
blues[0]=255;
setLut(reds, greens, blues);
rename(getTitle +maptype);
//set label
setMetadata("Label", maptype);
//run("Invert");
run("Remove Overlay");
//print(minC);
//print(maxC);
//print(user_min_val);
//print(user_max_val);
if (minC > 0){
minC= minC;
}
if (maxC < 255){
maxC= maxC;
}
run("Calibrate...", "function=[Straight Line] unit=[Unit] text1=["+minC+" "+maxC+"] text2=["+user_min_val+" "+user_max_val+"]");
height = getHeight;
zoom = floor(height/999)+1;
run("Calibration Bar...", "location=[Lower Left] fill=[White] label=Black number=5 decimal=2 font=10 zoom="+zoom+" bold");
//set label
setMetadata("Label", maptype);
//print(getTime()-t1);
//updateResults();
autoUpdate(true);
setBatchMode("exit and display");
}else{
showMessage("binary image required");
}