-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathVisualization_toolset.ijm
More file actions
2126 lines (1974 loc) · 80 KB
/
Copy pathVisualization_toolset.ijm
File metadata and controls
2126 lines (1974 loc) · 80 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
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
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//Bundle of macros for image visualization and handling in ImageJ / Fiji
//kevin.terretaz@gmail.com
//1.0 210207
//1.1 210208 forgotten adjustments + up to 7 Set LUTs
//1.2 210215 bugs correction (Splitviews, Max all)
//1.3 210228 add settings for composite switch and auto-contrast icon
// add toggle channels shortcuts tools.
//1.4 210411 gammaLUTs, better SplitView and all images channel toggle key
//2.0 220704 remove gamma icon, add multiTool icon (with gammaLUT inside), add borders to SplitView
//3.0 230428 Big refont, add action bars, new tools for the MultiTool and web documentation
//3.1 231002 bug corrections, refactoring code and adding default border to splitviews
/*This is free and unencumbered software released into the public domain. Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled binary, for any purpose, commercial or non-commercial, and by any means.
In jurisdictions that recognize copyright laws, the author or authors of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of relinquishment in perpetuity of all present and future rights to this software under copyright law.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
For more information, please refer to <http://unlicense.org/>
*/
//for image window size backup (macro[2])
var POSITION_BACKUP_TITLE = "";
var X_POSITION_BACKUP = 300;
var Y_POSITION_BACKUP = 300;
var WIDTH_POSITION_BACKUP = 400;
var HEIGHT_POSITION_BACKUP = 400;
// for quick Set LUTs
var CHOSEN_LUTS = get_Pref_LUTs_List(newArray("Cyan","Magenta","Yellow","Red","Green","Blue","Grays","k_Blue","k_Magenta","k_Orange","k_Green"));
var NOICE_LUTs = 0;
// For split_View
var COLOR_MODE = "Colored";
var MONTAGE_STYLE = "Linear";
var LABELS = "No labels";
var BORDER_SIZE = "Auto";
var FONT_SIZE = 30;
var CHANNEL_LABELS = newArray("GFP","RFP","DNA","Other","DIC");
var TILES = newArray(1);
// For MultiTool
var MAIN_TOOL = "Move Windows";
var MULTITOOL_LIST = newArray("Move Windows", "Slice / Frame Tool", "LUT Gamma Tool", "Curtain Tool", "Magic Wand", "Scale Bar Tool", "Multi-channel Plot Tool");
var LAST_CLICK_TIME = 0;
//For wand tool
var WAND_BOX_SIZE = 5;
var ADD_TO_MANAGER = 0;
var TOLERANCE_THRESHOLD = 40;
var EXPONENT = 2;
var FIT_MODE = "None";
// title of the assigned target image : space + [7] key
var TARGET_IMAGE_TITLE = "";
// for Scale Bar Tool
var REMOVE_SCALEBAR_TEXT = false;
// for multitool switch
var LAST_TOOL = 0;
// for Action Bars
var ACTION_BAR_STRING = "";
//--------------------------------------------------------------------------------------------------------------------------------------
// MULTI TOOL
//--------------------------------------------------------------------------------------------------------------------------------------
macro "Multi Tool (double click to configure) - icon:viz_toolset_1.png" {
multi_Tool();
}
macro "Multi Tool (double click to configure) Options" {
Dialog.createNonBlocking("Multitool Options");
Dialog.addRadioButtonGroup("__________________ __ Main Tool : __________________ __", MULTITOOL_LIST, 4, 2, MAIN_TOOL);
Dialog.addCheckbox("Remove text under scale bar?", REMOVE_SCALEBAR_TEXT);
Dialog.addMessage("________________ Magic Wand options : ______________");
Dialog.addNumber("Detection window size", WAND_BOX_SIZE);
Dialog.addSlider("Tolerance estimation threshold", 0, 100, TOLERANCE_THRESHOLD);
Dialog.addSlider("Adjustment speed", 1, 2, EXPONENT);
Dialog.addCheckbox("Auto add ROI to manager?", ADD_TO_MANAGER);
Dialog.addChoice("Fit selection? How?", newArray("None","Fit Spline","Fit Ellipse"), FIT_MODE);
Dialog.addHelp("https://kwolby.notion.site/Multi-Tool-526950d8bafc41fd9402605c60e74a99");
Dialog.show();
MAIN_TOOL = Dialog.getRadioButton();
REMOVE_SCALEBAR_TEXT = Dialog.getCheckbox();
WAND_BOX_SIZE = Dialog.getNumber();
TOLERANCE_THRESHOLD = Dialog.getNumber();
EXPONENT = Dialog.getNumber();
ADD_TO_MANAGER = Dialog.getCheckbox();
FIT_MODE = Dialog.getChoice();
save_Main_Tool(MAIN_TOOL);
}
macro "Stacks Menu Built-in Tool" {}
// macro "LUT Menu Built-in Tool" {}
//--------------------------------------------------------------------------------------------------------------------------------------
//------POPUP
//--------------------------------------------------------------------------------------------------------------------------------------
var pmCmds = newMenu("Popup Menu",
newArray("Set Main Tool", "Remove Overlay", "Duplicate...","Set LUTs","Set active path", "Set target image",
"-", "Record...", "Monitor Memory...","Control Panel...", "Startup Macros..."));
macro "Popup Menu" {
command = getArgument();
if (command == "Set Main Tool") show_main_Tools_Popup_Bar();
else if (command == "Set LUTs") {get_LUTs_Dialog(); apply_LUTs();}
else if (command == "Set active path") set_Active_Path();
else if (command == "Set target image") set_Target_Image();
else run(command);
}
//--------------------------------------------------------------------------------------------------------------------------------------
// PREVIEW OPENER
//--------------------------------------------------------------------------------------------------------------------------------------
macro "Preview Opener Action Tool - icon:viz_toolset_2.png"{
if (!isOpen("Preview Opener.tif")) make_Preview_Opener();
}
//--------------------------------------------------------------------------------------------------------------------------------------
// ACTION BARS
//--------------------------------------------------------------------------------------------------------------------------------------
var Action_Bars_Menu = newMenu("Action Bars Menu Tool",
newArray("Main Macro Shortcuts",
"-", "Splitview Macros", "Numerical Keyboard Macros", "More Macros",
"-", "Online Help"));
macro "Action Bars Menu Tool - icon:viz_toolset_3.png" {
command = getArgument();
if (command == "Main Macro Shortcuts") show_All_Macros_Action_Bar();
else if (command == "SplitView Macros") show_SplitView_Bar();
else if (command == "Numerical Keyboard Macros") show_Numerical_Keyboard_Bar();
else if (command == "More Macros") show_Other_Macros();
else if (command == "Online Help") run("URL...", "url=[https://kwolby.notion.site/Macros-Shortcuts-f6a0cb526bcf4cb78ac72ff8cd29f30b]");
}
//--------------------------------------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------------------------------------------
//NUMPAD KEYS
macro "[n0]"{
if (no_Alt_no_Space()) paste_Favorite_LUT();
if (isKeyDown("space")) set_Favorite_LUT();
}
macro "[n1]"{
if (no_Alt_no_Space()) run("Grays");
if (isKeyDown("space")) toggle_Channel(1);
if (isKeyDown("alt")) toggle_Channel_All(1);
}
macro "[n2]"{
if (no_Alt_no_Space()) run("k_Green");
if (isKeyDown("space")) toggle_Channel(2);
if (isKeyDown("alt")) toggle_Channel_All(2);
}
macro "[n3]"{
if (no_Alt_no_Space()) run("Red");
if (isKeyDown("space")) toggle_Channel(3);
if (isKeyDown("alt")) toggle_Channel_All(3);
}
macro "[n4]"{
if (no_Alt_no_Space()) run("k_Blue");
if (isKeyDown("space")) toggle_Channel(4);
if (isKeyDown("alt")) toggle_Channel_All(4);
}
macro "[n5]"{
if (no_Alt_no_Space()) run("k_Magenta");
if (isKeyDown("space")) toggle_Channel(5);
if (isKeyDown("alt")) toggle_Channel_All(5);
}
macro "[n6]"{
if (no_Alt_no_Space()) run("k_Orange");
if (isKeyDown("space")) toggle_Channel(6);
if (isKeyDown("alt")) toggle_Channel_All(6);
}
macro "[n7]"{
if (no_Alt_no_Space()) run("Cyan");
if (isKeyDown("space")) toggle_Channel(7);
if (isKeyDown("alt")) toggle_Channel_All(7);
}
macro "[n8]"{
if (no_Alt_no_Space()) run("Magenta");
if (isKeyDown("space")) run("8-bit");
if (isKeyDown("alt")) run("16-bit");
}
macro "[n9]"{
if (no_Alt_no_Space()) run("Yellow");
if (isKeyDown("space")) run("glasbey_on_dark");
}
//TOP NUMBER KEYS
macro "[1]" {
if (no_Alt_no_Space()) apply_LUTs();
else if (isKeyDown("space")) apply_All_LUTs();
else if (isKeyDown("alt")) get_My_LUTs();
}
macro "[2]" {
if (no_Alt_no_Space()) maximize_Image();
else if (isKeyDown("space")) restore_Image_Position();
else if (isKeyDown("alt")) full_Screen_Image();
}
macro "[4]" {
if (nImages()==0) exit();
if (no_Alt_no_Space()) {run("Make Montage...", "scale=1"); setOption("Changes", 0); }
else if (isKeyDown("space")) run("Montage to Stack...");
}
macro "[7]" {
if (no_Alt_no_Space()) set_Target_Image();
}
macro "[8]" {
if (nImages()==0) exit();
if (no_Alt_no_Space()) run("Rename...");
else if (isKeyDown("space")) rename(get_Time_Stamp("short") + "_" + getTitle());
else if (isKeyDown("alt")) rename(get_Time_Stamp("full") + "_" + getTitle());
}
macro "[9]" {
if (no_Alt_no_Space()) {if(File.exists(getDirectory("temp")+"test.tif")) open(getDirectory("temp")+"test.tif"); }
else if (isKeyDown("space")) {if (nImages()==0) exit(); saveAs("tif", getDirectory("temp")+"test.tif");}
}
//LETTER KEYS
macro "[a]" {
if (nImages()==0) exit();
if (no_Alt_no_Space()) run("Select All");
else if (isKeyDown("space")) run("Restore Selection");
else if (isKeyDown("alt")) run("Select None");
}
macro "[A]" {
if (nImages()==0) exit();
if (no_Alt_no_Space()) { if (bitDepth() == 24) run("Enhance True Color Contrast", "saturated=0.1"); else run("Enhance Contrast", "saturated=0.1");}
else if (isKeyDown("space")) enhance_All_Channels();
else if (isKeyDown("alt")) enhance_All_Images_Contrasts();
}
macro "[b]" {
if (nImages()==0) exit();
if (no_Alt_no_Space()) split_View("Vertical", "Colored", "No labels");
else if (isKeyDown("space")) split_View("Vertical", "Grayscale", "No labels");
else if (isKeyDown("alt")) quick_Figure_Splitview("vertical");
}
macro "[B]" {
if (no_Alt_no_Space()) run("Blobs (25K)");
else if (isKeyDown("space")) quick_Scale_Bar();
}
macro "[C]" { run("Brightness/Contrast...");}
macro "[d]" {
if (nImages()==0) exit();
if (no_Alt_no_Space()) {getDimensions(width, height, channels, slices, frames); if (channels>1 || bitDepth()==24) run("Split Channels"); else run("Stack to Images");}
else if (isKeyDown("space")) {run("Duplicate...", " "); string_To_Recorder("run(\"Duplicate...\", \" \");");}//slice
else if (isKeyDown("alt")) duplicate_Channel();
}
macro "[D]" {
if (no_Alt_no_Space()) {if (nImages()==0) exit(); run("Duplicate...", "duplicate"); string_To_Recorder("run(\"Duplicate...\", \"duplicate\");");}
else if (isKeyDown("space")) open_Memory_And_Recorder();
}
macro "[E]" { my_Tile();}
macro "[F]" {
if (no_Alt_no_Space()) my_Tool_Roll();
}
macro "[f]" {
if (nImages()==0) exit();
if (no_Alt_no_Space()) run("Gamma...");
else if (isKeyDown("space")) set_Gamma_LUT_All_Channels(0.8);
}
macro "[G]" {
if (nImages()==0) exit();
if (no_Alt_no_Space()) run("Z Project...", "projection=[Max Intensity] all");
else if (isKeyDown("space")) z_Project_All();
else if (isKeyDown("alt")) run("Z Project...", "projection=[Sum Slices] all");
}
macro "[g]" {
if (nImages()==0) exit();
if (no_Alt_no_Space()) run("Z Project...");
else if (isKeyDown("space")) color_Code_Progressive_Max();
else if (isKeyDown("alt")) color_Code_No_Projection();
}
macro "[H]" { run("Show All");}
macro "[i]" {
if (nImages()==0) exit();
if (no_Alt_no_Space()) run("Invert LUTs");
else if (isKeyDown("space")) inverted_Overlay_HSB();
else if (isKeyDown("alt")) run("Invert LUT");
}
macro "[J]" {
if (nImages()==0) exit();
if (no_Alt_no_Space()) {run("Input/Output...", "jpeg=100"); saveAs("Jpeg");}
else if (isKeyDown("space")) save_As_LZW_compressed_tif();
}
macro "[j]" {
if (no_Alt_no_Space()) run("Macro");
else if (isKeyDown("space")) { if (nImages()==0) exit(); run("Subtract Background...");}
}
macro "[k]" {
if (nImages()==0) exit();
if (no_Alt_no_Space()) multi_Plot();
else if (isKeyDown("space")) multi_Plot(); //normalized multiplot
else if (isKeyDown("alt")) multi_Plot_Z_Axis();
}
macro "[l]" {
if (no_Alt_no_Space()) run("Find Commands...");
}
macro "[M]" {
if (nImages()==0) exit();
if (no_Alt_no_Space()) fast_Merge();
else if (isKeyDown("space")) run("Merge Channels...");
}
macro "[n]" {
if (no_Alt_no_Space()) Hela();
}
macro "[N]" {
if (no_Alt_no_Space()) show_Numerical_Keyboard_Bar();
}
macro "[o]" {
if (nImages()==0) {run("Open..."); exit();}
if (matches(getTitle(), ".*Preview Opener.*")) open_From_Preview_Opener();
else run("Open...");
}
macro "[p]" {
if (nImages()==0) exit();
if (no_Alt_no_Space()) split_View("Linear", "Grayscale", "No labels");
else if (isKeyDown("space")) split_View("Square", "Grayscale", "No labels");
else if (isKeyDown("alt")) quick_Figure_Splitview("linear");
}
macro "[Q]" { composite_Switch(); }
macro "[R]" {
if (nImages()==0) exit();
if (no_Alt_no_Space()) auto_Contrast_All_Channels();
else if (isKeyDown("space")) auto_Contrast_All_Images();
else if (isKeyDown("alt")) propagate_Contrasts_All_Images();
}
macro "[r]" {
if (no_Alt_no_Space()) adjust_Contrast();
else if (isKeyDown("space")) {run("Install...","install=["+getDirectory("macros")+"/StartupMacros.fiji.ijm]"); setTool(15);}
}
macro "[S]" {
if (nImages()==0) exit();
if (no_Alt_no_Space()) split_View("Square", "Colored", "No labels");
else if (isKeyDown("space")) split_View("Linear", "Colored", "No labels");
else if (isKeyDown("alt")) split_View_Dialog();
}
macro "[s]" {
if (nImages()==0) exit();
if (no_Alt_no_Space()) saveAs("Tiff");
else if (isKeyDown("alt")) save_All_Images_Dialog();
}
macro "[v]" {
if (no_Alt_no_Space()) run("Paste");
else if (isKeyDown("space")) run("System Clipboard");
else if (isKeyDown("alt")) open(getDirectory("temp")+"/copiedLut.lut");
}
macro "[w]" {
if (no_Alt_no_Space()) {
if (nImages()==0) exit();
//avoid "are you sure?" and stores path in case of misclick
path = getDirectory("image") + getTitle();
if (File.exists(path)) call("ij.Prefs.set","last.closed", path);
close();
}
else if (isKeyDown("space")) open(call("ij.Prefs.get","last.closed",""));
else if (isKeyDown("alt")) close("\\Others");
}
macro "[x]" {
if (nImages()==0) exit();
if (no_Alt_no_Space()) copy_LUT();
else if (isKeyDown("alt")) {run("Copy to System"); showStatus("copy to system");}
}
macro "[y]" {
if (no_Alt_no_Space()) run("Synchronize Windows");
else if (isKeyDown("space")) {if (nImages()==0) exit(); getCursorLoc(x, y, z, modifiers); doWand(x, y, estimate_Tolerance(), "8-connected");}
}
macro "[Z]" {
if (no_Alt_no_Space()) run("Channels Tool...");
else if (isKeyDown("space")) run("LUT Channels Tool");
}
function my_Tool_Roll() {
if (toolID() != 15) {
LAST_TOOL = toolID();
setTool(15);
}
else
setTool(LAST_TOOL);
}
function save_Main_Tool(main_Tool) {
call("ij.Prefs.set","Multi_Tool.Main_Tool", main_Tool);
setTool(15);
return main_Tool;
}
function get_Main_Tool(default_Main_Tool) {
return call("ij.Prefs.get","Multi_Tool.Main_Tool", default_Main_Tool);
}
function save_Pref_LUT(index, lut_Name) {
call("ij.Prefs.set","Fav_LUT." + index, lut_Name);
}
function get_Pref_LUT(index, default_LUT) {
return call("ij.Prefs.get","Fav_LUT." + index, default_LUT);
}
function get_Pref_LUTs_List(default_LUTs){
chosen_luts = newArray();
for ( i = 0; i < 8; i++) chosen_luts[i] = get_Pref_LUT(i, default_LUTs[i]);
return chosen_luts;
}
function string_To_Recorder(string) {
if (isOpen('Recorder')) call("ij.plugin.frame.Recorder.recordString",string + "\n");
}
function quick_Figure_Splitview(linear_or_Vertical){
if (nImages()==0) exit();
getDimensions(width, height, channels, slices, frames);
BORDER_SIZE = minOf(height, width) * 0.02;
if (linear_or_Vertical == "linear") split_View("Linear", "Grayscale", "Add labels");
else split_View("Vertical", "Grayscale", "Add labels");
run("Copy to System");
}
function unique_Rename(name) {
final_Name = name;
i = 1;
while (isOpen(final_Name)) {
final_Name = name + "_" + i;
i++;
}
rename(final_Name);
}
function arrange_Channels() {
// whithout losing metadata
if (nImages()==0) exit();
infos = getMetadata("Info");
run("Arrange Channels...");
setMetadata("Info", infos);
string_To_Recorder("run(\"Arrange Channels...\");");
}
// adapted from here https://forum.image.sc/t/automatic-scale-bar-in-fiji-imagej/60774
function quick_Scale_Bar(){
if (nImages()==0) exit();
color = "White";
// approximate size of the scale bar relative to image width :
scalebar_Size = 0.23;
getPixelSize(unit, pixel_Width, pixel_Height);
if (unit == "pixels") exit("Image not spatially calibrated");
// image width in measurement units
shortest_Image_Edge = pixel_Width * minOf(Image.width, Image.height);
// initial scale bar length in measurement units :
scalebar_Length = 1;
// 1-2-5 series is calculated by repeated multiplication with 2.3, rounded to one significant digit
while (scalebar_Length < shortest_Image_Edge * scalebar_Size)
scalebar_Length = round((scalebar_Length*2.3)/(Math.pow(10,(floor(Math.log10(abs(scalebar_Length*2.3)))))))*(Math.pow(10,(floor(Math.log10(abs(scalebar_Length*2.3))))));
if (REMOVE_SCALEBAR_TEXT) {
scalebar_Settings_String = " height=" + minOf(Image.width, Image.height)/30 + " font=" + maxOf(Image.width, Image.height)/30 + " color="+color+" hide overlay";
print("Scale Bar length = " + scalebar_Length);
}
else scalebar_Settings_String = " height=" + minOf(Image.width, Image.height)/30 + " font=" + minOf(Image.width, Image.height)/15 + " color="+color+" bold overlay";
run("Scale Bar...", "width=&scalebar_Length " + scalebar_Settings_String);
string_To_Recorder("run(\"Scale Bar...\", \"width=" + scalebar_Length + scalebar_Settings_String + "\"");
}
function save_As_LZW_compressed_tif(){
path = getDir("save As LZW compressed tif");
title = File.nameWithoutExtension();
print( path + File.separator + title);
run("Bio-Formats Exporter", "save=["+ path + File.separator + title + "_.tif] compression=LZW");
}
// true if
function no_Alt_no_Space(){
if(!isKeyDown("space") && !isKeyDown("alt"))
return true;
else return false;
}
function duplicate_Channel() {
if (nImages()==0) exit();
getDimensions(width, height, channels, slices, frames);
title = getTitle() + "_dup";
Stack.getPosition(channel, slice, frame);
if (channels > 1 && frames==1) {
run("Duplicate...", "duplicate title=title channels=&channel");
string_To_Recorder("run(\"Duplicate...\", \"duplicate title=" + title + " channels=" + channel + "\");");
}
else {
run("Duplicate...", "duplicate title=title channels=&channel frames=frame");
string_To_Recorder("run(\"Duplicate...\", \"duplicate title=" + title + " channels=" + channel + " frames=" + frame + "\");");
}
}
function set_Target_Image(){
if (nImages()==0) exit();
// modify the global variable TARGET_IMAGE_TITLE with the current image title
showStatus("Target Image title");
run("Alert ", "object=Image color=Orange duration=1000");
TARGET_IMAGE_TITLE = getTitle();
}
function open_Memory_And_Recorder() {
run("Record...");
wait(20);
Table.setLocationAndSize(screenWidth()-430, 0, 430, 125,"Recorder");
run("Monitor Memory...");
wait(20);
Table.setLocationAndSize(screenWidth()-676, 0, 255, 120,"Memory");
}
function composite_Switch(){
if (nImages()==0) exit();
if (!is("composite")) exit();
Stack.getDisplayMode(mode);
if (mode == "color" || mode == "greyscale") Stack.setDisplayMode("composite");
else Stack.setDisplayMode("color");
}
/*
* About Flags (or Modifiers) from getCursorLoc()
* shift = +1
* ctrl = +2
* command = +4 (Mac)
* alt = +8
* middle also +8
* leftClick = +16
* cursor over selection = +32
* So e.g. if (leftclick + alt) Flags = 24
*/
//inspired by Robert Haase Windows Position tool from clij
function multi_Tool(){
if (nImages == 0) exit();
//Main Tool stored on Pref file
MAIN_TOOL = get_Main_Tool("Move Windows"); //"Move Windows" if not set yet
// Double click ?
if (is_double_click()) {
maximize_Image();
exit();
}
setupUndo();
//limit this to stay reactive on big images
if (Image.width() < 1400 && Image.height() < 1400) call("ij.plugin.frame.ContrastAdjuster.update");
getCursorLoc(x, y, z, flags);
//middle click on selection
if (flags == 40) {
roiManager("Add");
exit();
}
//middle click
if (flags == 8) {
if (matches(getTitle(), ".*Preview Opener.*")) open_From_Preview_Opener();
if (matches(getTitle(), ".*Lookup Tables.*")) set_LUT_From_Montage();
if (Image.height == 32 || Image.width == 256) copy_LUT();
if (MAIN_TOOL == "Curtain Tool") set_Target_Image();
else composite_Switch();
}
//left Click on selection
if (flags > 32 && MAIN_TOOL != "Magic Wand") move_selection_Tool();
if (flags > 32) flags -= 32;
//left Click
if (flags == 16) {
if (MAIN_TOOL == "Move Windows") move_Windows();
else if (MAIN_TOOL == "Contrast Adjuster") live_Contrast();
else if (MAIN_TOOL == "LUT Gamma Tool") live_Gamma();
else if (MAIN_TOOL == "Slice / Frame Tool") live_Scroll();
else if (MAIN_TOOL == "Magic Wand") magic_Wand();
else if (MAIN_TOOL == "Curtain Tool") curtain_Tool();
else if (MAIN_TOOL == "Scale Bar Tool") scale_Bar_Tool();
else if (MAIN_TOOL == "Multi-channel Plot Tool") live_MultiPlot();
}
if (flags == 9) if (bitDepth()!=24) paste_LUT(); // shift + middle click
if (flags == 10 || flags == 14) if (bitDepth()!=24) paste_Favorite_LUT(); // ctrl + middle click
if (flags == 17) live_Contrast(); // shift + drag
if (flags == 18 || flags == 20) k_Rectangle_Tool(); // ctrl + drag
if (flags == 24) if (MAIN_TOOL=="Slice / Frame Tool") move_Windows(); else live_Scroll(); // alt + drag
if (flags == 25) box_Auto_Contrast(); // shift + alt + drag
if (flags == 26 || flags == 28) curtain_Tool();
}
function is_double_click() {
double_click = false;
click_time = getTime(); // in ms
if (click_time - LAST_CLICK_TIME < 200) double_click = true;
LAST_CLICK_TIME = click_time;
return double_click;
}
function k_Rectangle_Tool() {
getCursorLoc(x_origin, y_origin, z, flags);
getCursorLoc(last_x, last_y, z, flags);
remove_ROI = true;
if (flags > 32) exit();
while (flags >= 16) {
rect_x = x_origin;
rect_y = y_origin;
getCursorLoc(x, y, z, flags);
if (x != last_x || y != last_y) {
if (x <= x_origin) rect_x = x;
if (y <= y_origin) rect_y = y;
rect_width = abs(x_origin - x);
rect_heigth = abs(y_origin - y);
makeRectangle(rect_x, rect_y, rect_width, rect_heigth);
getCursorLoc(last_x, last_y, z, flags);
if (flags >= 32) flags -= 32;
remove_ROI = false;
}
wait(10);
}
if (remove_ROI) run("Select None");
}
function move_selection_Tool() {
getCursorLoc(x_origin, y_origin, z, flags);
getCursorLoc(last_x, last_y, z, flags);
getSelectionBounds(roi_x, roi_y, width, height);
if (flags >= 32) flags -= 32;
while (flags == 16) {
getCursorLoc(x, y, z, flags);
if (x != last_x || y != last_y) {
setSelectionLocation(roi_x - (x_origin-x), roi_y - (y_origin-y));
getCursorLoc(last_x, last_y, z, flags);
}
wait(10);
if (flags >= 32) flags -= 32;
}
}
function scale_Bar_Tool(){
//adapted from Aleš Kladnik here https://forum.image.sc/t/automatic-scale-bar-in-fiji-imagej/60774
getPixelSize(unit,w,h);
if (unit == "pixels") exit("Image not spatially calibrated");
bar_Length = 1; // initial scale bar length in measurement units
bar_Relative_Size = 0;
bar_Height = 0;
if (REMOVE_SCALEBAR_TEXT == true) text_Parameter = "hide";
else text_Parameter = "bold";
font_Size = minOf(Image.width, Image.height) / 15; // estimation of "good" font size
getCursorLoc(x2, y2, z2, flags2);
getCursorLoc(last_x, last_y, z, flags);
while (flags >= 16) { //left click
getCursorLoc(x, y, z, flags);
getDisplayedArea(area_x, area_y, width, height);
//if mouse moved
if (x != last_x || y != last_y) {
// approximate size of the scale bar relative to image width
bar_Relative_Size = round(((width-(x - area_x))/width) * 10);
// recursively calculate a 1-2-5-10-20... series
// 1-2-5 series is calculated by repeated multiplication with 2.3, rounded to one significant digit
for (i = 0; i < bar_Relative_Size; i++) {
magical_Formula = Math.pow( 10, (floor( Math.log10( abs(bar_Length * 2.3)))));
bar_Length = round( (bar_Length*2.3) / magical_Formula) * magical_Formula;
}
bar_Height = round(((height - (y - area_y)) / height) * Image.height/20);
//if size or height values changed from last loop, update scale bar
if (bar_Relative_Size != last_Size || bar_Height != last_Height)
run("Scale Bar...", "width=&bar_Length height=&bar_Height font=&font_Size color=White background=None location=[Lower Right] "+ text_Parameter +" overlay");
showStatus("height = "+bar_Height+ "px length = "+ bar_Length + unit);
bar_Length = 1;
}
//save changes
last_Size = bar_Relative_Size;
last_Height = bar_Height;
getCursorLoc(last_x, last_y, z, flags);
wait(10);
}
}
function curtain_Tool() {
getCursorLoc(last_x, y, z, flags);
getDimensions(width, height, channels, slices, frames);
setBatchMode(true);
id = getImageID();
while (flags&16>0) {
selectImage(id);
getCursorLoc(x, y, z, flags);
if (x != last_x) {
if (x < 0) x = 0;
if (isOpen(TARGET_IMAGE_TITLE)) selectWindow(TARGET_IMAGE_TITLE);
else exit();
setKeyDown("none");
makeRectangle(x, 0, width-x, height);
run("Duplicate...","title=part");
selectImage(id);
run("Add Image...", "image=part x="+ x +" y=0 opacity=100"); //zero
while (Overlay.size>1) Overlay.removeSelection(0);
close("part");
last_x = x;
wait(10);
}
}
selectWindow(TARGET_IMAGE_TITLE);
run("Select None");
selectImage(id);
Overlay.remove;
}
function move_Windows() {
getCursorLoc(x, y, z, flags);
origin_x = get_Cursor_Screen_Loc_X();
origin_y = get_Cursor_Screen_Loc_Y();
getLocationAndSize(origin_window_x, origin_window_y, width, height);
while (flags == 16) {
x = get_Cursor_Screen_Loc_X();
y = get_Cursor_Screen_Loc_Y();
Table.setLocationAndSize(x - (origin_x - origin_window_x), y - (origin_y - origin_window_y), width, height, getTitle());
getCursorLoc(x, y, z, flags);
wait(10);
}
}
function get_Cursor_Screen_Loc_X(){
x = parseInt(eval("bsh", "import java.awt.MouseInfo; MouseInfo.getPointerInfo().getLocation().x;"));
return x;
}
function get_Cursor_Screen_Loc_Y(){
y = parseInt(eval("bsh", "import java.awt.MouseInfo; MouseInfo.getPointerInfo().getLocation().y;"));
return y;
}
function live_Contrast() {
if (bitDepth() == 24) exit();
resetMinAndMax();
getMinAndMax(min, max);
getCursorLoc(x, y, z, flags);
flags = flags%32; //remove "cursor in selection" flag
while (flags >= 16) {
getCursorLoc(x, y, z, flags);
getDisplayedArea(area_x, area_y, width, height);
flags = flags%32; //remove "cursor in selection" flag
new_Max = ((x - area_x) / width) * max;
new_Min = ((height - (y - area_y)) / height) * max / 2;
if (new_Max < 0) new_Max = 0;
if (new_Min < 0) new_Min = 0;
if (new_Min > new_Max) new_Min = new_Max;
setMinAndMax(new_Min, new_Max);
call("ij.plugin.frame.ContrastAdjuster.update");
wait(10);
}
}
function live_Gamma(){
setBatchMode(1);
getLut(reds, greens, blues);
// copy_LUT();
setColor("white");
setFont("SansSerif", Image.height/20, "bold antialiased");
getCursorLoc(x, y, z, flags);
flags = flags%32; //remove "cursor in selection" flag
while (flags >= 16) {
getCursorLoc(x, y, z, flags);
getDisplayedArea(area_x, area_y, width, height);
flags = flags%32; //remove "cursor in selection" flag
gamma = d2s(((x - area_x) / width) * 2, 2); if (gamma < 0) gamma=0;
gamma_LUT(gamma, reds, greens, blues);
showStatus("Gamma on LUT : " + gamma);
wait(10);
}
setBatchMode(0);
run("Select None");
}
function live_Scroll() {
getDimensions(width, height, channels, slices, frames);
if(slices==1 && frames==1) exit();
getCursorLoc(x, y, z, flags);
flags = flags%32; //remove "cursor in selection" flag
while(flags >= 16) {
getCursorLoc(x, y, z, flags);
getDisplayedArea(area_x, area_y, width, height);
flags = flags%32; //remove "cursor in selection" flag
if (frames > 1) Stack.setFrame(((x - area_x) / width) * frames);
else Stack.setSlice(((x - area_x) / width) * slices);
wait(10);
}
}
function box_Auto_Contrast() {
if (bitDepth==24) exit();
size = 75;
getCursorLoc(x, y, z, flags);
makeRectangle(x - size/2, y - size/2, size, size);
auto_Contrast_All_Channels();
run("Select None");
}
function magic_Wand(){
getCursorLoc(x, y, z, flags);
if (flags>=32) flags -= 32; //remove "cursor in selection" flag
if (ADD_TO_MANAGER){
run("ROI Manager...");
roiManager("show all without labels");
}
if (flags == 16) { //left click
adjust_Tolerance();
}
if (FIT_MODE != "None"){
run(FIT_MODE);
getSelectionCoordinates(xpoints, ypoints);
makeSelection(4, xpoints, ypoints);
}
if (ADD_TO_MANAGER) roiManager("Add");
wait(30);
}
function adjust_Tolerance() {
getCursorLoc(x2, y2, z, flags); //origin
getCursorLoc(x, y, z, flags);
if (flags>=32) flags -= 32; //remove "cursor in selection" flag
zoom = getZoom();
tolerance = estimate_Tolerance();
while (flags >= 16) {
getCursorLoc(x, y, z, flags);
if (flags>=32) flags -= 32; //remove "cursor in selection" flag
distance = (x*zoom - x2*zoom);
if (distance < 0) new_Tolerance = tolerance - pow(abs(distance), EXPONENT);
else new_Tolerance = tolerance + pow(abs(distance), EXPONENT);
if (new_Tolerance < 0) new_Tolerance = 0;
showStatus(new_Tolerance);
doWand(x2, y2, new_Tolerance, "Legacy");
wait(30);
}
}
function estimate_Tolerance(){
run("Select None");
setBatchMode(1);
getCursorLoc(x, y, z, flags);
makeRectangle(x - (WAND_BOX_SIZE / 2), y - (WAND_BOX_SIZE / 2), WAND_BOX_SIZE, WAND_BOX_SIZE);
getStatistics(bla, bla, bla, max, bla, bla);;
tolerance = (TOLERANCE_THRESHOLD / 100) * max;
return tolerance;
}
function copy_LUT() {
if (nImages()==0) exit();
if (bitDepth() == 24) exit();
getCursorLoc(x, y, z, flags);
saveAs("lut", getDirectory("temp")+"/copiedLut.lut");
showStatus("Copy LUT");
}
function paste_LUT(){
if (bitDepth() == 24) exit();
open(getDirectory("temp")+"/copiedLut.lut");
showStatus("Paste LUT");
}
function set_Favorite_LUT(){
if (nImages()==0) exit();
if (bitDepth() == 24) exit();
saveAs("lut", getDirectory("temp") + "/favoriteLUT.lut");
showStatus("new favorite LUT");
}
function paste_Favorite_LUT(){
if (bitDepth() == 24) exit();
open(getDirectory("temp") + "/favoriteLUT.lut");
showStatus("Paste LUT");
}
function get_Time_Stamp(full_or_short) {
getDateAndTime(year, month, day_Of_Week, day_Of_Month, hour, minute, second, msec);
if (full_or_short == "short")
time_Stamp = "" + toString(year-2000) + toString(IJ.pad(month+1, 2)) + toString(IJ.pad(day_Of_Month, 2)) + "_";
else time_Stamp = "" + toString(year-2000) + toString(IJ.pad(month+1, 2)) + toString(IJ.pad(day_Of_Month, 2)) + "_" + toString(hour) + toString(minute) + toString(second);
return time_Stamp;
}
//toggle channel number (i)
function toggle_Channel(i) { //modified from J.Mutterer
if (nImages()==0) exit();
if (is("composite")) {
Stack.getActiveChannels(string);
channel_Index = string.substring(i-1,i);
Stack.setActiveChannels(string.substring(0, i-1) + !channel_Index + string.substring(i)); //at the end it looks like Stack.setActiveChannels(1101);
showStatus("channel " + i + " toggled");
}
}
function toggle_Channel_All(i) {
setBatchMode(1);
for (k=0; k<nImages; k++) {
selectImage(k+1);
toggle_Channel(i);
}
showStatus("channel "+i+" toggled");
setBatchMode(0);
}
function open_From_Preview_Opener() {
infos = getMetadata("Info");
path_List = split(infos, ",,");
rows = getInfo("xMontage");
lines = getInfo("yMontage");
bloc_Size = 400;
index = 0;
getCursorLoc(x, y, z, flags);
line_Position = floor(y / bloc_Size);
row_Position = floor(x / bloc_Size);
index = (line_Position * rows) + row_Position;
path = getDirectory("image") + path_List[index];
if (File.exists(path)) {
if (endsWith(path, '.tif')||endsWith(path, '.png')||endsWith(path, '.jpg')||endsWith(path, 'jpeg')) open(path);
else run('Bio-Formats Importer', 'open=[' + path + ']');
showStatus("opening " + path_List[index]);
}
else showStatus("can't find " + path_List[index]);
}
//create a montage with snapshots of all opened images (virtual or not)
//in their curent state. Will close all but the montage.
function make_Preview_Opener() {
if (nImages == 0) exit();
Dialog.createNonBlocking("Make Preview Opener");
Dialog.addMessage("Creates a montage with snapshots of all opened images (virtual or not).\n" +
"This will close all but the montage. Are you sure?");
Dialog.addHelp("https://kwolby.notion.site/Preview-Opener-581219eab9f748bc8269d0d8ffe9172d");
Dialog.show();
setBatchMode(1);
all_IDs = newArray(nImages);
paths_List = "";
concat_Options = "open ";
for (i=0; i<nImages ; i++) {
selectImage(i+1);
if (i==0) {
source_Folder = getDirectory("image");
File.setDefaultDir(source_Folder);
}
all_IDs[i] = getImageID();
paths_List += getTitle() +",,";
}
for (i=0; i<all_IDs.length; i++) {
selectImage(all_IDs[i]);
if (!is("Virtual Stack") && bitDepth()!=24) {
getDimensions(width, height, channels, slices, frames);
getLut(reds,greens,blues);
if (slices * frames != 1) run("Z Project...", "projection=[Max Intensity] all");
setLut(reds, greens, blues);
}
rgb_Snapshot();
run("Scale...", "x=- y=- width=400 height=400 interpolation=Bilinear average create");
rename("image"+i);
concat_Options += "image"+i+1+"=[image"+i+"] ";
}
run("Concatenate...", concat_Options);
run("Make Montage...", "scale=1");
rename("Preview Opener");
infos = getMetadata("Info");
setMetadata("Info", paths_List + "\n" + infos);
close("\\Others");
setBatchMode(0);
saveAs("tiff", source_Folder + "_Preview Opener");
}
//Supposed to create an RGB snapshot of any kind of opened image
function rgb_Snapshot(){
if (nImages()==0) exit();
title = getTitle();
Stack.getPosition(channel, slice, frame);
getDimensions(width, height, channels, slices, frames);
if (channels > 1) Stack.getDisplayMode(mode);
if (bitDepth()==24) run("Duplicate..."," ");
else if (channels==1) run("Duplicate...", "title=toClose channels=&channels slices=&slice frames=&frame");
else if (mode!="composite") run("Duplicate...", "title=toClose channels=channel slices=&slice frames=&frame");
else run("Duplicate...", "duplicate title=toClose slices=&slice frames=&frame");
run("RGB Color", "keep");
unique_Rename("rgb_" + title);
close("toClose");
setOption("Changes", 0);
}
function Hela(){
setBatchMode(1);
run("HeLa Cells (48-bit RGB)");
makeRectangle(23, 0, 580, 478);
run("Crop");
run("Remove Overlay");
run("Remove Slice Labels");
apply_LUTs();
makeRectangle(173, 255, 314, 178);
enhance_All_Channels();
run("Select None");
setOption("Changes",0);
setBatchMode(0);
}
function live_MultiPlot() {