Saturday, March 19, 2016

Development Environment

Your ImageJ is now well configured [Link], it is time to create your first script and optimize the way you write your future scripts...

1. How to use the JavaScript Text Editor of ImageJ

1.1. Presentation
Go to Plugins > New > JavaScript and a blank window opens... You are in front of the text editor of ImageJ. Good!!

This editor is really basic because it lacks main features of a classical text editor like syntax highlighting, automatic indentation, etc. however, it is still useful.
In Fig.1, all the features available in this editor menu are displayed...

Fig.1: ImageJ Text Editor with all its menus.

The first time you open this window, just configure it a little bit. I advise you to:
  • Use a Monospaced Font (go to Font > Monospaced Font and check it)
  • Adjust the font size with Font > Make Text Smaller (Ctrl + N) or Larger (Ctrl + M).
  • Save your new settings (Font > Save Settings).
1.2. Here are few tips and tricks  ...
1.2.1. How to run my script?
go to Macros > Run Macro or Ctrl+O

1.2.2. I have an error message, line 34, where is it in my script?
go to Edit > Go to Line or type Ctrl+L, type 34 and the cursor is automatically moved to the beginning of this line.

1.2.3. I have missing brackets and/or parentheses in my code?
Move your cursor in a block of code by clicking somewhere in the text and then go to Edit > Balance (or Ctrl+B). All the text delimited by brackets or parentheses is selected (black background and white font colors).

1.2.4. How to select a word?
Double click on this word...

1.2.5. I want to only run a part of my code
Select several lines in your script and then go to Macros > Evaluate JavaScript (or Ctrl + J)

2. I want my text editor!!

Of course, you can use your favorite text editor (Notepad++, gedit, emacs, Sublime text, etc.) and then load and run your script(s) in ImageJ by choosing the menu item Plugins > Macros > Run..., navigating in your folders to select the good file. This is a very boring repetitive process. You can speed it up by saving your scripts in a dedicated folder located in the folder plugins of ImageJ.

For example, if I move all my scripts in a folder (or directory) entitled CrazyBio_Learning_JS in the plugins folder as follows...

    +-- ImageJ
      +-- luts/
      +-- macros/
      +-- plugins/
        +-- CrazyBio_Learning_JS/
          +-- hello_world.js
          +-- using_variables.js
          +-- using_loop.js
          +-- using_test.js
      +-- samples/

Then, run ImageJ and go to Plugins, a new item CrazyBio_Learning_JS is visible containing the scripts (Fig.2).

Fig.2: All your scripts are now visible in the Plugins > CrazyBio_Learning_JS

Note: If you create a new file in the directory CrazyBio_Learning_JS, you have to restart ImageJ to see this file in the Plugins > CrazyBio_Learning_JS menu.

3. Other crazybiocomputing posts

Further readings are available in ...
  • Programming in JavaScript Series  [Link]
  • Image Processing TOC [Link]

No comments:

Post a Comment