-
Notifications
You must be signed in to change notification settings - Fork 227
/
functions.html
5477 lines (4725 loc) · 185 KB
/
functions.html
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
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Built-in Macro Functions</title>
<link rel="stylesheet" type="text/css" href="../../docs/ij.css" />
<link rel="stylesheet" type="text/css" media="print" href="../../docs/print.css" />
<link rel="shortcut icon" href="../../favicon.ico">
<script type="text/javascript" src="../../docs/print.js"> </script>
</head>
<body bgcolor="#ffffff">
<noscript><style type="text/css">#printlink{display:none;}</style></noscript>
<font color="#224488">
<a name="Top"></a>
<p class=navbar> <a href="https://imagej.net/ij/">home</a> | <a href="https://imagej.net/ij/download.html">download</a> | <a href="https://imagej.net/ij/developer/index.html">resources</a></p>
<h1>Built-in Macro Functions</h1>
</font>
<blockquote>
<hr>
<div class=alphabar>
<a href="#A">[ A ]</a><a href="#B">[ B ]</a><a
href="#C">[ C ]</a><a href="#D">[ D ]</a><a
href="#E">[ E ]</a><a href="#F">[ F ]</a><a
href="#G">[ G ]</a><a href="#H">[ H ]</a><a
href="#I">[ I ]</a><a href="#J">[ J ]</a><a
href="#K">[ K ]</a><a href="#L">[ L ]</a><a
href="#M">[ M ]</a>
<a id="printlink" style="float:right;" href="#" onclick="javascript:replaceLinks();"><b>Print List</i></b>
<br><a href="#N">[ N ]</a><a href="#O">[ O ]</a><a
href="#P">[ P ]</a><a href="#Q">[ Q ]</a><a
href="#R">[ R ]</a><a href="#S">[ S ]</a><a
href="#T">[ T ]</a><a href="#U">[ U ]</a><a
href="#V">[ V ]</a><a href="#W">[ W ]</a><a
href="#X">[ X ]</a><a href="#Y">[ Y ]</a><a
href="#Z">[ Z ]</a>
</div>
<hr>
<p>
<a name="A"></a> A <a href='#Top'>[ Top ]</a><p>
<a name="abs"></a>
<b>abs(n)</b><br>
Returns the absolute value of <i>n</i>.
<p>
<a name="acos"></a>
<b>acos(n)</b><br>
Returns the inverse cosine (in radians) of <i>n</i>.
<p>
<a name="Array"></a>
<b>Array Functions</b><br>
These functions operate on arrays. Refer to the
<a href="../../macros/examples/ArrayFunctions.txt">ArrayFunctions</a>
macro for examples.
<p>
<blockquote>
<a name="Array.concat"></a>
<b>Array.concat(array1, array2)</b> -
Returns a new array created by joining two or more arrays or values
(<a href="../../macros/examples/ArrayConcatExamples.txt">examples</a>).
<br>
<a name="Array.copy"></a>
<b>Array.copy(array)</b> -
Returns a copy of <i>array</i>.
<br>
<a name="Array.deleteValue"></a>
<b>Array.deleteValue(array, value)</b> -
Returns a version of <i>array</i> where all numeric or string elements
in the array that contain <i>value</i> have been deleted
(<a href="../../macros/examples/ArrayDeleteDemo.txt">examples</a>).
<br>
<a name="Array.deleteIndex"></a>
<b>Array.deleteIndex(array, index)</b> -
Returns a version of <i>array</i> where the element with the
specified index has been deleted.
<br>
<a name="Array.fill"></a>
<b>Array.fill(array, value)</b> -
Assigns the specified numeric value to each element of <i>array</i>.
<br>
<a name="Array.filter"></a>
<b>Array.filter(array, filter)</b>
Returns an array containing the elements of 'array' that contain 'filter',
where 'array' is an array of strings.
Enclose the filter in parans to do regular expression matching.
Requires 1.53f.
<br>
<a name="Array.findMaxima"></a>
<b>Array.findMaxima(array, tolerance)</b> -
Returns an array holding the peak positions
(sorted with descending strength). 'Tolerance' is the minimum amplitude difference
needed to separate two peaks. With v1.51n and later, there is an optional
'edgeMode' argument: 0=include edges, 1=exclude edges(default), 2=circular array.
<a href="../../macros/examples/FindMaxima1D.txt">Examples</a>.<br>
<a name="Array.findMinima"></a>
<b>Array.findMinima(array, tolerance)</b> -
Returns an array holding the minima positions.
<br>
<a name="Array.fourier"></a>
<b>Array.fourier(array, windowType)</b> -
Calculates and returns the Fourier amplitudes of <i>array</i>.
<i>WindowType</i> can be "none", "Hamming", "Hann",
or "flat-top", or may be omitted (meaning "none").
See the <a href="../../macros/examples/TestArrayFourier.txt">TestArrayFourier</a>
macro for an example and more documentation.
<br>
<a name="Array.getSequence"></a>
<b>Array.getSequence(n)</b> -
Returns an array containing the numeric sequence 0,1,2...n-1.
<br>
<a name="Array.getStatistics"></a>
<b>Array.getStatistics(array, min, max, mean, stdDev)</b> -
Returns the <i>min</i>, <i>max</i>, <i>mean</i>, and <i>stdDev</i> of <i>array</i>,
which must contain all numbers.
<br>
<a name="Array.print"></a>
<b>Array.print(array)</b> -
Prints the array on a single line.
<br>
<a name="Array.rankPositions"></a>
<b>Array.rankPositions(array)</b> -
Returns, as an array, the rank position indexes of <i>array</i>, starting with the index of the smallest value
(<a href="../../macros/examples/ArraySortingDemo.txt">example</a>).
<br>
<a name="Array.resample"></a>
<b>Array.resample(array, len)</b> -
Returns an array which is linearly resampled to a different length.
<br>
<a name="Array.reverse"></a>
<b>Array.reverse(array)</b> -
Reverses (inverts) the order of the elements in <i>array</i>.
<br>
<a name="Array.show"></a>
<b>Array.show(array)</b> -
Displays the contents of <i>array</i> in a window.
<br>
<a name="Array.show_multiple"></a>
<b>Array.show("title", array1, array2, ...)</b> -
Displays one or more arrays in a Results window
(<a href="../../macros/examples/ShowArrayDemo.txt">examples</a>).
If <i>title</i> (optional) is "Results", the window will be the active Results
window, otherwise, it will be a dormant Results window
(see also <a href="#IJ.renameResults">IJ.renameResults</a>).
If <i>title</i> ends with "(indexes)", a 0-based Index column is shown.
If <i>title</i> ends with "(row numbers)", the row number column is shown.
<br>
<a name="Array.slice"></a>
<b>Array.slice(array, start, end)</b> -
Extracts a part of an array and returns it.
(<a href="../../macros/examples/ArraySliceExamples.txt">examples</a>).
<br>
<a name="Array.sort"></a>
<b>Array.sort(array)</b> -
Sorts <i>array</i>, which must contain all numbers or all strings.
String sorts are case-insensitive.
<br>
<a name="Array.sort_multiple"></a>
<b>Array.sort(array1, array2, array3...)</b> -
Sorts multiple arrays, where all the arrays adopt the sort
order of <i>array1</i>
(<a href="../../macros/examples/ArraySortDemo.txt">example</a>).
<br>
<a name="Array.trim"></a>
<b>Array.trim(array, n)</b> -
Returns an array that contains the first <i>n</i> elements of <i>array</i>.
<br>
<a name="Array.rotate"></a>
<b>Array.rotate(array, d)</b> -
Rotates the array elements by 'd' steps (positive 'd' = rotate right).
Requires 1.51n.
<a href="../../macros/examples/RotateArray.txt">Examples</a>.
<br>
<a name="Array.getVertexAngles"></a>
<b>Array.getVertexAngles(xArr, yArr, arm)</b> -
From a closed contour given by 'xArr', 'yArr', an array is returned holding vertex angles in degrees (straight=0, convex = positive if contour is clockwise). Set 'arm'=1 to calculate the angle from the closest vertex points left and right, or use arm>1 for more distant neighbours and smoother results.
Requires 1.51n.
<a href="../../macros/examples/VertexAngles.txt">Examples</a>.<br>
</blockquote>
<a name="asin"></a>
<b>asin(n)</b><br>
Returns the inverse sine (in radians) of <i>n</i>.
<p>
<a name="atan"></a>
<b>atan(n)</b><br>
Calculates the inverse tangent (arctangent) of <i>n</i>. Returns
a value in the range -PI/2 through PI/2.
<p>
<a name="atan2"></a>
<b>atan2(y, x)</b><br>
Calculates the inverse tangent of <i>y/x</i> and returns an angle in the
range -PI to PI, using the signs of the arguments
to determine the quadrant. Multiply the result by 180/PI to convert to degrees.
<p>
<a name="autoUpdate"></a>
<b>autoUpdate(boolean)</b><br>
If <i>boolean</i> is true, the display is refreshed each time lineTo(), drawLine(),
drawString(), etc. are called, otherwise, the display is refreshed only when updateDisplay()
is called or when the macro terminates.
<p>
<b> B </b><a name="B"><a href='#Top'>[ Top ]</a><p>
<a name="beep"></a>
<b>beep()</b><br>
Emits an audible beep.
<p>
<a name="bitDepth"></a>
<b>bitDepth()</b><br>
Returns the bit depth of the active image: 8, 16, 24 (RGB) or 32 (float).
<p>
<b> C </b><a name="C"><a href='#Top'>[ Top ]</a><p>
<a name="calibrate"></a>
<b>calibrate(value)</b><br>
Uses the calibration function of the active image to convert a raw pixel value
to a density calibrated value. The argument must be an integer in the range 0-255
(for 8-bit images) or 0-65535 (for 16-bit images). Returns the same value if the active
image does not have a calibration function.
<p>
<a name="call"></a>
<b>call("class.method", arg1, arg2, ...)</b><br>
Calls a public static method in a Java class, passing an arbitrary number
of string arguments, and returning a string. Refer to the
<a href="../../macros/CallJavaDemo.txt">CallJavaDemo</a> macro
and the <a href="https://imagej.net/ij/plugins/imp-props.html">ImpProps</a>
plugin for examples.
<p>
<a name="call_no_args"></a>
<b>call("class.method")</b><br>
Calls a public static no-argument method in a Java class and returns a string.
<p>
<a name="changeValues"></a>
<b>changeValues(v1, v2, v3)</b><br>
Changes pixels in the image or selection that have a value in the range <i>v1</i>-<i>v2</i>
to <i>v3</i>. For example, <i>changeValues(0, 5, 5)</i> changes all pixels less than 5 to 5,
and <i>changeValues(0x0000ff, 0x0000ff, 0xff0000)</i> changes all blue pixels in an RGB image to red.
In ImageJ 1.52d or later, use changeValues(NaN, NaN, value) to replaces NaN values.
<p>
<a name="charCodeAt"></a>
<b>charCodeAt(string, index)</b><br>
Returns the Unicode value of the character at the specified index in <i>string</i>.
Index values can range from 0 to lengthOf(<i>string</i>). Use the fromCharCode() function
to convert one or more Unicode characters to a string.
<p>
<a name="close"></a>
<b>close()</b><br>
Closes the active image. This function has the advantage of not closing the "Log"
or "Results" window when you meant to close the active image. Use
<i>run("Close")</i> to close non-image windows.
<p>
<a name="close_pattern"></a>
<b>close(pattern)</b><br>
Closes windows whose title matches 'pattern', which can contain the
wildcard characters '*' (matches any character sequence) and '?'
(matches single character).
For example, close("Histo*") could be used to dispose all histogram windows.
Non-image windows like "Roi Manager"
have to be specified without wildcards. For text windows, wildcards
are allowed if 'pattern' ends with ".txt", ".ijm", ".js" etc. Use close("*")
to close all image windows. Use close(pattern, "keep") to not close
text or image windows with changes. If 'pattern' is "\\Others", all
images except the front image are closed. The most recent macro
window is never closed.
<p>
<a name="close_all"></a>
<b>close("*")</b><br>
Closes all image windows.
<p>
<a name="close_others"></a>
<b>close("\\Others")</b><br>
Closes all images except for the front image.
<p>
<a name="Color"></a>
<b>Color Functions</b><br>
Functions for working with colors, available
in ImageJ 1.53h and later.
<blockquote>
<a name="Color.set"></a>
<b>Color.set(string)</b><br>
Sets the drawing color, where 'string' is
"red", "blue", etc., or a hex value like "#ff0000".
<br>
<a name="Color.set_value"></a>
<b>Color.set(value)</b><br>
Sets the drawing color. For 8 bit images, 0<=<i>value</i><=255.
For 16 bit images, 0<=<i>value</i><=65535. With RGB images,
use hex constants (e.g., 0xff0000 for red).
<br>
<a name="Color.setForeground"></a>
<b>Color.setForeground(string)</b><br>
Sets the foreground color, where 'string' is
"red", "blue", etc., or a hex value like "#ff0000".
<br>
<a name="Color.setForegroundValue"></a>
<b>Color.setForegroundValue(value)</b><br>
Sets the foreground color to grayscale, where
'value' is a number between 0 and 255.
<br>
<a name="Color.setBackground"></a>
<b>Color.setBackground(string)</b><br>
Sets the background color, where 'string' is
"red", "blue", etc., or a hex value like "#ff0000".
<br>
<a name="Color.setBackgroundValue"></a>
<b>Color.setBackgroundValue(value)</b><br>
Sets the background color to grayscale, where
'value' is a number between 0 (black) and 255 (white).
<br>
<a name="Color.setForeground_r_g_b"></a>
<b>Color.setForeground(r, g, b)</b><br>
Sets the foreground color, where <i>r</i>, <i>g</i>, and <i>b</i> are >= 0 and <= 255.
<br>
<a name="Color.setBackground_r_g_b"></a>
<b>Color.setBackground(r, g, b)</b><br>
Sets the background color, where <i>r</i>, <i>g</i>, and <i>b</i> are >= 0 and <= 255.
<br>
<a name="Color.foreground"></a>
<b>Color.foreground</b><br>
Returns the foreground color as a string, for example
"red" or "#ff0000".
<br>
<a name="Color.background"></a>
<b>Color.background</b><br>
Returns the background color as a string, for example
"cyan" or "#00ffff".
<br>
<a name="Color.toString"></a>
<b>Color.toString(r, g, b)</b><br>
Converts an r,g,b color to a string.
<br>
<a name="Color.toArray"></a>
<b>Color.toArray(string)</b><br>
Converts a color (e.g., "red" or "#ff0000") to a three element array.
<br>
<a name="Color.getLut"></a>
<b>Color.getLut(reds, greens, blues)</b><br>
Returns three arrays containing the red, green and blue intensity values from the
current lookup table. See the
<a href="../../macros/LookupTables.txt">LookupTables</a>
macros for examples.
<br>
<a name="Color.setLut"></a>
<b>Color.setLut(reds, greens, blues)</b><br>
Creates a new lookup table and assigns it to the current image. Three input arrays are
required, each containing 256 intensity values.
<br>
<a name="Color.wavelengthToColor"></a>
<b>Color.wavelengthToColor(wavelength)</b><br>
Converts a wavelength (380-750 nm) into a color
in string format (e.g., "#0031ff").
See also: Help>Examples>Plots>Plot With Spectrum.
<br>
</blockquote>
<a name="cos"></a>
<b>cos(angle)</b><br>
Returns the cosine of an angle (in radians).
<p>
<b> D </b><a name="D"><a href='#Top'>[ Top ]</a><p>
<a name="d2s"></a>
<b>d2s(n, decimalPlaces)</b><br>
Converts the number <i>n</i> into a string using the specified
number of decimal places.
Uses scientific notation if 'decimalPlaces is negative.
Note that d2s stands for "double to string".
<p>
<a name="debug"></a>
<b>debug(arg)</b><br>
Calls the
<a href="macros.html#debugger">macro debugger</a>,
where 'arg' is "break" (the default), "run", "trace", "fast-trace", "dump" or "throw".
Call debug("dump") to display the contents of the symbol table, the tokenized macro
code and the variable stack. Call debug("throw") to display an example
"Exception" window.
<p>
<a name="dialog"></a>
<b>Dialog.create("Title")</b><br>
Creates a modal dialog box with the specified title, or use <i>Dialog.createNonBlocking("Title")</i>
to create a non-modal dialog. Call <i>Dialog.addString()</i>, <i>Dialog.addNumber(),
</i> etc. to add components to the dialog. Call <i>Dialog.show()</i> to display the
dialog and <i>Dialog.getString()</i>, <i>Dialog.getNumber()</i>, etc. to
retrieve the values entered by the user.
Refer to the
<a href="../../macros/DialogDemo.txt">DialogDemo</a>
macro for an example.
<p>
<blockquote>
<a name="Dialog.createNonBlocking"></a>
<b>Dialog.createNonBlocking("Title")</b> -
Creates a non-modal dialog box with the specified title.
<br>
<a name="Dialog.addMessage"></a>
<b>Dialog.addMessage(string)</b> -
Adds a message to the dialog. The message can be broken into multiple
lines by inserting new line characters ("\n") into the string.
<br>
<a name="Dialog.addMessage_font_size"></a>
<b>Dialog.addMessage(string, fontSize, fontColor)</b> -
Adds a message to the dialog using a specified font size
and color
(<a href="../../macros/examples/DialogMessageDemo.txt">example</a>).
The message can be broken into
multiple lines by inserting new line characters ("\n") into the string.
The 'fontSize' and 'fontColor' arguments are optional.
<br>
<a name="Dialog.addString"></a>
<b>Dialog.addString(label, initialText)</b> -
Adds a text field to the dialog, using the specified label and initial text.
<br>
<a name="Dialog.addString_columns"></a>
<b>Dialog.addString(label, initialText, columns)</b> -
Adds a text field to the dialog, where <i>columns</i> specifies the field
width in characters.
<br>
<a name="Dialog.addNumber"></a>
<b>Dialog.addNumber(label, default)</b> -
Adds a numeric field to the dialog, using the specified label and default value.
<br>
<a name="Dialog.addNumber_decimalPlaces"></a>
<b>Dialog.addNumber(label, default, decimalPlaces, columns, units)</b> -
Adds a numeric field, using the specified label and default value. <i>DecimalPlaces</i>
specifies the number of digits to right of decimal point, <i>columns</i> specifies the the field
width in characters and <i>units</i> is a string that is displayed to
the right of the field.
<br>
<a name="Dialog.addSlider"></a>
<b>Dialog.addSlider(label, min, max, default)</b> -
Adds a slider controlled numeric field to the dialog, using the specified label,
and min, max and default values
(<a href="../../macros/examples/SliderDemo.txt">example</a>).
Values with decimal points are used when
(max-min)<=5 and min, max or default
are non-integer.
<br>
<a name="Dialog.addCheckbox"></a>
<b>Dialog.addCheckbox(label, default)</b> -
Adds a checkbox to the dialog, using the specified label and default state (true or false).
<br>
<a name="Dialog.addCheckboxGroup"></a>
<b>Dialog.addCheckboxGroup(rows, columns, labels, defaults)</b> -
Adds a <i>rows</i>x<i>columns</i> grid of checkboxes to the dialog, using the specified labels and default states
(<a href="../../macros/AddCheckboxGroupDemo.txt">example</a>).
<br>
<a name="Dialog.addRadioButtonGroup"></a>
<b>Dialog.addRadioButtonGroup(label, items, rows, columns, default)</b> -
Adds a group of radio buttons to the dialog, where 'label' is the group label, 'items' is
an array containing the button labels, 'rows' and 'columns' specify the grid size, and
'default' is the label of the default button.
(<a href="../../macros/examples/RadioButtonDemo.txt">example</a>).
<br>
<a name="Dialog.addChoice"></a>
<b>Dialog.addChoice(label, items)</b> -
Adds a popup menu to the dialog, where <i>items</i> is a string array containing the menu items.
<br>
<a name="Dialog.addChoice_default"></a>
<b>Dialog.addChoice(label, items, default)</b> -
Adds a popup menu, where <i>items</i> is a string array containing the choices
and <i>default</i> is the default choice.
<br>
<a name="Dialog.addDirectory"></a>
<b>Dialog.addDirectory(label, defaultPath)</b> -
Adds a directory field and "Browse" button. The
field width is determined by the length of 'defaultPath',
with a minimum of 25 and a maximum of 60 columns. Use Dialog
getString to retrieve the directory path. Use
<a href="#File.setDefaultDir">File.setDefaultDir()</a>
to set the default directory used when the user
clicks on "Browse".
Requires 1.53d.
<br>
<b>Dialog.addDirectory(label, defaultPath, columns)</b> -
Adds a directory field and "Browse" button, using a
field width of 'columns'.
Requires 1.54i.
<br>
<a name="Dialog.addFile"></a>
<b>Dialog.addFile(label, defaultPath)</b> -
Adds a file field and "Browse" button. The
field width is determined by the length of 'defaultPath',
with a minimum of 25 and a maximum of 60 columns. Use Dialog
getString to retrieve the file path.
Requires 1.53d.
<br>
<b>Dialog.addFile(label, defaultPath, columns)</b> -
Adds a file field and "Browse" button, using a field width
of 'columns'.
Requires 1.54i.
<br>
<a name="Dialog.addImage"></a>
<b>Dialog.addImage(pathOrURL)</b> -
Adds an image to the dialog. The 'pathOrURL' argument can be a
file path (e.g., "/Users/wayne/Downloads/blobs.tif")
or a URL (e.g., "https://imagej.net/images/blobs.gif").
<br>
<a name="Dialog.addImageChoice"></a>
<b>Dialog.addImageChoice(label)</b> -
Adds a popup menu that lists the currently open images.
Use Dialog getImageChoice() to retrieve the title of
the selected image. The macro aborts if there are no
open images. Requires 1.53d.
<br>
<a name="Dialog.addImageChoice_defaultImage"></a>
<b>Dialog.addImageChoice(label, defaultImage)</b> -
This a version of addImageChoice() with a second argument
for specifying the selected image in the dropdown menu.
Requires 1.53s.
<br>
<a name="Dialog.addHelp"></a>
<b>Dialog.addHelp(url)</b> -
Adds a "Help" button that opens the specified URL in the default browser. This can be used to supply
a help page for this dialog or macro. With v1.46b or later, displays an HTML formatted message if
'url' starts with "<html>"
(<a href="../../macros/examples/DialogWithHelp.txt">example</a>).
<br>
<a name="Dialog.addToSameRow"></a>
<b>Dialog.addToSameRow()</b> -
Makes the next item added appear on the same row as the previous item.
May be used for addNumericField, addSlider, addChoice, addCheckbox, addString,
addMessage, and before the showDialog() method. In the latter case,
the buttons appear to the right of the previous item.
Note that <i>addMessage</i> (and <i>addString</i> if a width of more than 8 is specified)
use the remaining width, so it must be the last item of a row.
Requires 1.51r.
<br>
<a name="Dialog.setInsets"></a>
<b>Dialog.setInsets(top, left, bottom)</b> -
Overrides the default insets (margins) used for the next component added to the dialog.<br>
<small>
Default insets:<br>
addMessage: 0,20,0 (empty string) or 10,20,0<br>
addCheckbox: 15,20,0 (first checkbox) or 0,20,0<br>
addCheckboxGroup: 10,0,0<br>
addNumericField: 5,0,3 (first field) or 0,0,3<br>
addStringField: 5,0,5 (first field) or 0,0,5<br>
addChoice: 5,0,5 (first field) or 0,0,5<br>
</small>
<a name="Dialog.setLocation"></a>
<b>Dialog.setLocation(x, y)</b> -
Sets the screen location where this dialog will be displayed.
<br>
<a name="Dialog.getLocation"></a>
<b>Dialog.getLocation(x, y)</b> -
Returns the screen location of this dialog.
Requires 1.54g.
<br>
<a name="Dialog.show"></a>
<b>Dialog.show()</b> -
Displays the dialog and waits until the user clicks "OK" or "Cancel". The macro
terminates if the user clicks "Cancel".
<br>
<a name="Dialog.getString"></a>
<b>Dialog.getString()</b> -
Returns a string containing the contents of the next text,
directory or file field.
<br>
<a name="Dialog.getNumber"></a>
<b>Dialog.getNumber()</b> -
Returns the contents of the next numeric field.
<br>
<a name="Dialog.getCheckbox"></a>
<b>Dialog.getCheckbox()</b> -
Returns the state (true or false) of the next checkbox.
<br>
<a name="Dialog.getChoice"></a>
<b>Dialog.getChoice()</b> -
Returns the selected item (a string) from the next popup menu.
<br>
<a name="Dialog.getRadioButton"></a>
<b>Dialog.getRadioButton()</b> -
Returns the selected item (a string) from the next radio button group.
<br>
<a name="Dialog.getImageChoice"></a>
<b>Dialog.getImageChoice()</b> -
Returns the title of the image selected in the next image
choice popup menu.
<br>
</blockquote>
<a name="doCommand"></a>
<b>doCommand("Command")</b><br>
Runs an ImageJ menu command in a separate thread and returns immediately. As an example,
<i>doCommand("Start Animation")</i> starts animating the current stack in a separate
thread and the macro continues to execute. Use <i>run("Start Animation")</i> and the
macro hangs until the user stops the animation.
<p>
<a name="doWand"></a>
<b>doWand(x, y)</b><br>
Equivalent to clicking on the current image at (x, y) with the wand tool.
Note that some objects, especially one pixel wide lines,
may not be reliably traced unless they have been thresholded (highlighted in red)
using <a href="#setThreshold">setThreshold</a>.
<p>
<a name="doWand_tolerance"></a>
<b>doWand(x, y, tolerance, mode)</b><br>
Traces the boundary of the area with pixel values within
'tolerance' of the value of the pixel at (x, y).
'mode' can be "4-connected", "8-connected" or "Legacy".
"Legacy" is for compatibility with previous versions of ImageJ;
it is ignored if 'tolerance' > 0.
If 'mode' contains 'smooth', the contour is smoothed by interpolation
(<a href="../../macros/examples/SmoothLetters.txt">example</a>).
<p>
<a name="drawLine"></a>
<b>drawLine(x1, y1, x2, y2)</b><br>
Draws a line between (x1, y1) and (x2, y2). Use setColor() to
specify the color of the line and setLineWidth() to vary the line width.
See also: <a href="#Overlay">Overlay.drawLine</a>.
<p>
<a name="drawOval"></a>
<b>drawOval(x, y, width, height)</b><br>
Draws the outline of an oval using the current color and line width.
See also:
<a href="#fillOval">fillOval</a>,
<a href="#setColor">setColor</a>,
<a href="#setLineWidth">setLineWidth</a>,
<a href="#autoUpdate">autoUpdate</a> and
<a href="#Overlay">Overlay.drawEllipse</a>.
<p>
<a name="drawRect"></a>
<b>drawRect(x, y, width, height)</b><br>
Draws the outline of a rectangle using the current color and line width.
See also:
<a href="#fillRect">fillRect</a>,
<a href="#setColor">setColor</a>,
<a href="#setLineWidth">setLineWidth</a>,
<a href="#autoUpdate">autoUpdate</a> and
<a href="#Overlay">Overlay.drawRect</a>
<p>
<a name="drawString"></a>
<b>drawString("text", x, y)</b><br>
Draws text at the specified location.
The first character is drawn obove and to the right of (x, y).
Call <a href="#setFont">setFont()</a>
to specify the font.
Call <a href="#setJustification">setJustification()</a>
to have the text centered or right justified.
Call <a href="#getStringWidth">getStringWidth()</a> to get the width of the
text in pixels.
Refer to the
<a href="../../macros/TextDemo.txt">TextDemo</a> macro for examples
and to
<a href="../../macros/examples/DrawTextWithBackground.txt">DrawTextWithBackground</a>
to see how to draw text with a background.
<p>
<a name="drawString_background"></a>
<b>drawString("text", x, y, background)</b><br>
Draws text at the specified location with a filled background
(<a href="../../macros/examples/DrawTextWithBackground.txt">examples</a>).
<p>
<a name="dump"></a>
<b>dump()</b><br>
Writes the contents of the symbol table, the tokenized macro code and the variable stack to the "Log" window.
<p>
<b> E </b><a name="E"><a href='#Top'>[ Top ]</a><p>
<a name="endsWith"></a>
<b>endsWith(string, suffix)</b><br>
Returns <i>true</i> (1) if <i>string</i> ends with <i>suffix</i>.
See also:
<a href="#startsWith">startsWith</a>,
<a href="#indexOf">indexOf</a>,
<a href="#substring">substring</a>,
<a href="#matches">matches</a>.
<p>
<a name="eval"></a>
<b>eval(macro)</b><br>
Evaluates (runs) one or more lines of macro code. An optional
second argument can be used to pass a string to the macro
being evaluated.
See also:
<a href="../../macros/EvalDemo.txt">EvalDemo</a> macro and
<a href="#runMacro">runMacro</a> function.
<p>
<a name="eval_script"></a>
<b>eval("script", javascript)</b><br>
Evaluates the
<a href="../javascript.html">JavaScript</a>
code contained in the string <i>javascript</i> and returns,
as a string, the value of the last statement executed.
For example
<i>eval("script", "IJ.getInstance().setAlwaysOnTop(true);")</i>.
See also: <a href="#runMacro">runMacro(path, arg)</a>.
<p>
<a name="eval_js"></a>
<b>eval("js", script)</b><br>
Evaluates the
<a href="../javascript.html">JavaScript</a>
code contained in the string <i>script</i> and returns,
as a string, the value of the last statement executed.
For example
<i>eval("js", "Prefs.blackBackground")</i> returns
either "true" or "false".
<p>
<a name="eval_bsh"></a>
<b>eval("bsh", script)</b><br>
Evaluates the
<a href="https://imagej.net/ij/plugins/bsh/index.html">BeanShell</a>
code contained in the string <i>script</i>.
<p>
<a name="eval_python"></a>
<b>eval("python", script)</b><br>
Evaluates the
<a href="https://imagej.net/ij/plugins/jython/index.html">Python</a>
code contained in the string <i>script</i>.
<p>
<a name="exec"></a>
<b>exec(string or strings)</b><br>
Executes a native command and returns the output of that command
as a string. Also opens Web pages in the default browser and documents
in other applications (e.g., Excel).
With commands with multiple arguments, each argument should be passed as a separate string. For example<br>
<i>exec("open", "/Users/wayne/test.jpg", "-a", "/Applications/Gimp.app");</i><br>
Refer to the
<a href="../../macros/ExecExamples.txt">ExecExamples</a>
macro for examples.
<p>
<a name="exit"></a>
<b>exit</b><br>
Terminates execution of the macro.
<p>
<a name="exit_message"></a>
<b>exit("error message")</b><br>
Terminates execution of the macro and displays an error message.
<p>
<a name="exp"></a>
<b>exp(n)</b><br>
Returns the exponential number e (i.e., 2.718...) raised to the power of <i>n</i>.
<p>
<a name="ext"></a>
<a name="Ext"></a>
<b>Ext (Macro Extension) Functions</b><br>
These are functions that have been added to the macro language by plugins using
the MacroExtension interface. The
<a href="https://imagej.net/ij/plugins/5d-extensions.html">Image5D_Extensions</a>
plugin, for example, adds functions that work with Image5D. The
<a href="https://imagej.net/plugins/serial-macro-extensions">Serial Macro Extensions</a>
plugin adds functions, such as Ext.open("COM8", 9600, "") and Ext.write("a"), that talk to serial devices.
<p>
<b> F </b><a name="F"><a href='#Top'>[ Top ]</a><p>
<a name="file"></a>
<b>File Functions</b><br>
These functions allow you to get information about a file, read or write a text file,
create a directory, or to delete, rename or move a file or directory.
Note that these functions return a string, with the exception of
<i>File.length</i>, <i>File.exists</i>, <i>File.isDirectory</i>, <i>File.rename</i>
and <i>File.delete</i> when used in an assignment statement,
for example "length=File.length(path)".
The
<a href="../../macros/FileDemo.txt">FileDemo</a>
macro demonstrates how to use these functions.
See also:
<a href="#getDirectory">getDirectory</a> and
<a href="#getFileList">getFileList</a>.
<p>
<blockquote>
<a name="File.append"></a>
<b>File.append(string, path)</b> -
Appends <i>string</i> to the end of the specified file.
<br>
<a name="File.close"></a>
<b>File.close(f)</b> -
Closes the specified file, which must have been opened using File.open().
<br>
<a name="File.copy"></a>
<b>File.copy(path1, path2)</b> -
Copies a file.
<br>
<a name="File.dateLastModified"></a>
<b>File.dateLastModified(path)</b> -
Returns the date and time the specified file was last modified.
<br>
<a name="File.delete"></a>
<b>File.delete(path)</b> -
Deletes the specified file or directory. With v1.41e or later, returns "1" (true)
if the file or directory was successfully deleted.
If the file is a directory, it must be empty.
The file must be in the user's home directory, the ImageJ directory
or the temp directory.
<br>
<a name="File.directory"></a>
<b>File.directory</b> -
The directory path of the last file opened using a file open dialog, a file save dialog,
drag and drop, <a href="#open">open(path)</a>
or <a href="#runMacro">runMacro(path)</a>.<br>
<a name="File.exists"></a>
<b>File.exists(path)</b> -
Returns "1" (true) if the specified file exists.<br>
<a name="File.getName"></a>
<b>File.getName(path)</b> -
Returns the file name (e.g., "blobs.tif") from <i>path</i>.<br>
<a name="File.getNameWithoutExtension"></a>
<b>File.getNameWithoutExtension(path)</b> -
Returns the name (e.g., "blobs") from <i>path</i> without the extension.
<br>
<a name="File.getDirectory"></a>
<b>File.getDirectory(path)</b> -
Returns the directory (e.g., "C:/Users/wayne/images/") from <i>path</i>.
<br>
<a name="File.getDefaultDir"></a>
<b>File.getDefaultDir</b> -
Returns the default directory used by file open dialogs
or the current working directory if called from a
command line macro and File.setDefaultDir() has
not been called.
<br>
<a name="File.setDefaultDir"></a>
<b>File.setDefaultDir(directoryPath)</b> -
Sets the default directory used by file open dialogs.
<br>
<a name="File.getParent"></a>
<b>File.getParent(path)</b> -
Returns the parent of the file specified by <i>path</i>.<br>
<a name="File.isFile"></a>
<b>File.isFile(path)</b> -
Returns "1" (true) if the specified file is not a directory.<br>
<a name="File.isDirectory"></a>
<b>File.isDirectory(path)</b> -
Returns "1" (true) if the specified file is a directory.<br>
<a name="File.lastModified"></a>
<b>File.lastModified(path)</b> -
Returns the time the specified file was last modified as
the number of milliseconds since January 1, 1970.<br>
<a name="File.length"></a>
<b>File.length(path)</b> -
Returns the length in bytes of the specified file as a string, or as
a number when used in an assignment statement,
for example "length=File.length(path)".
<br>
<a name="File.makeDirectory"></a>
<b>File.makeDirectory(path)</b> -
Creates a directory.<br>
<a name="File.name"></a>
<b>File.name</b> -
The name of the last file opened using a file open dialog, a file save dialog,
drag and drop, or the <a href="#open">open(path)</a> function.<br>
<a name="File.nameWithoutExtension"></a>
<b>File.nameWithoutExtension</b> -
The name of the last file opened with the extension removed.
<br>
<a name="File.open"></a>
<b>File.open(path)</b> -
Creates a new text file and returns a file variable that refers to it. To write to the file,
pass the file variable to the
<a href="#print">print</a> function.
Displays a file save dialog box if <i>path</i> is an empty string.
The file is closed when the macro exits.
Currently, only one file can be open at a time.
For an example, refer to the
<a href="../../macros/SaveTextFileDemo.txt">SaveTextFileDemo</a> macro.
<br>
<a name="File.openAsString"></a>
<b>File.openAsString(path)</b> -
Opens a text file and returns the contents as a string. Displays a file
open dialog box if <i>path</i> is an empty string.
Use <i>lines=split(str, "\n")</i> to convert the string to
an array of lines.
See also: <a href="#File.openUrlAsString">File.openUrlAsString</a>.
<br>
<a name="File.openAsRawString"></a>
<b>File.openAsRawString(path)</b> -
Opens a file and returns up to the first 5,000 bytes as a string.
Returns all the bytes in the file if the name ends with ".txt".
Refer to the
<a href="../../macros/First10Bytes.txt">First10Bytes</a>
and
<a href="../../macros/ZapGremlins.txt">ZapGremlins</a>
macros for examples.
<br>
<a name="File.openAsRawString"></a>
<b>File.openAsRawString(path, count)</b> -
Opens a file and returns up to the first <i>count</i> bytes as a string.
<br>
<a name="File.openUrlAsString"></a>
<b>File.openUrlAsString(url)</b> -
Opens a URL and returns the contents as a string. Returns an emptly
string if the host or file cannot be found. With v1.41i and later, returns "<Error: message>"
if there any error, including host or file not found.
<br>
<a name="File.openSequence"></a>
<b>File.openSequence(path, options)</b> -
Opens the images in the specified directory as a stack. Uses
a virtual stack if the 'options' string contains
'virtual'. A filter, image type, start,
step, count and scale can also be set, for example
"filter=abc bitdepth=32 start=10 step=2 count=10 scale=50".
Requires 1.53p.
<br>