Skip to content

Commit 030cb59

Browse files
committed
Update examples of scripts in ReadMe #15
1 parent 5d86339 commit 030cb59

File tree

1 file changed

+80
-12
lines changed

1 file changed

+80
-12
lines changed

README.md

Lines changed: 80 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,33 +7,101 @@ IJP Scala Console is simple user interface for executing Scala scripts.
77
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/net.sf.ij-plugins/scala-console_3/badge.svg)](https://maven-badges.herokuapp.com/maven-central/net.sf.ij-plugins/scala-console_3)
88
[![Scaladoc](https://javadoc.io/badge2/net.sf.ij-plugins/scala-console_3/scaladoc.svg)](https://javadoc.io/doc/net.sf.ij-plugins/scala-console_3)
99

10+
**Contents**
11+
12+
<!-- TOC -->
13+
14+
* [ijp-scala-console](#ijp-scala-console)
15+
* [ImageJ Script Examples](#imagej-script-examples)
16+
* [ImageJ Plugin Download](#imagej-plugin-download)
17+
* [Related Projects](#related-projects)
18+
* [License](#license)
19+
20+
<!-- TOC -->
21+
22+
Overview
23+
--------
24+
1025
The Scala Console can be run stand-alone, embedded in a desktop application, or [ImageJ] plugin. UI is build with
1126
ScalaFX.
1227

1328
![Screenshot](docs/images/Scala-Console-2_screenshot.png)
1429

30+
ImageJ Plugin Download
31+
----------------------
32+
33+
Binaries can be downloaded from the [releases] page. Extract the binaries to the ImageJ plugins directory. The plugin
34+
will be available through ImageJ menu: `Plugins` > `Scripting` > `Scala Console`.
35+
1536
ImageJ Script Examples
1637
----------------------
1738

18-
Example of an ImageJ script that get a handle to currently selected image and runs the "Median" filter plugin. If there
19-
is no image an error dialog is shown:
39+
### Get Access to Current Image
40+
41+
Assume that you opened an image in ImageJ, for instance, using `File` > `Open Samples` > `Leaf`
42+
43+
The following script will get a handle to the current activa image (`IJ.getImage`), assign it to a value `imp`, and then
44+
print it:
2045

2146
```scala
22-
import ij.IJ._
47+
import ij.IJ
2348

24-
Option(getImage) match {
25-
case Some(imp) => run(imp, "Median...", "radius=4")
26-
case None => noImage()
27-
}
49+
val imp = IJ.getImage
50+
println(imp)
2851
```
2952

30-
Additional example scripts can be found the [examples] directory.
53+
Note: if there is no image open a "No image" dialog will be shown and execution will be aborted
3154

32-
ImageJ Plugin Download
33-
----------------------
55+
Note: that the first thing the script does is to import ImageJ's object `IJ` from package `ij`. Object `IJ` contains
56+
many
57+
frequently used ImageJ methods, like:
58+
59+
* `getImage` - get current image
60+
* `openImage` - load image from a file
61+
* `run` - run a plugin or a command
62+
* `save` - save current image
63+
* `setSlice` - select slice in current image
64+
* `showMessage` - display dialog with a message
65+
66+
Full list can be found here: https://imagej.nih.gov/ij/developer/api/ij/ij/IJ.html
67+
68+
Note: you can use methods contained in `IJ` directly, without prefixing with `IJ`. To do that import a specific method,
69+
for instance, `import ij.IJ.getImage` or all the available methods `import ij.IJ.*`. Here is a shorted version of the
70+
above example:
71+
72+
```scala
73+
import ij.IJ.*
74+
75+
println(getImage)
76+
```
77+
78+
### Run a command "Median..." to process current image
79+
80+
You can execute any menu command using `IJ.run` method and providing command name. In simplest form you only provide command name, it will run on the current open image:
81+
```scala
82+
import ij.IJ.*
83+
84+
run("Median...")
85+
```
86+
The command may open additional dialog asking for options. If you know what options you want to pass you can do that:
87+
```scala
88+
import ij.IJ.*
89+
90+
run("Median...", "radius=4")
91+
```
92+
If you want to control on which image the command runs, you can do that too:
93+
```scala
94+
import ij.IJ.*
95+
96+
val imp = getImage
97+
run(imp, "Median...", "radius=4")
98+
```
99+
The options are listed in a single string using names of fields in the dialog. For boolean values, you use only filed name if value is true (checkbox is checked), you skip the field name of value is false.
100+
101+
Hint: You can use Macro Recorder (`Plugins` > `Macros` > `Record`) to record a command then copy it to your script.
102+
103+
Additional example scripts can be found the [examples] directory.
34104

35-
Binaries can be downloaded from the [releases] page. Extract the binaries to the ImageJ plugins directory. The plugin
36-
install `Plugins` > `Scripting` > `Scala Console`.
37105

38106
Related Projects
39107
----------------

0 commit comments

Comments
 (0)