Problems with Macro / JavaScript in 'Modern Mode'

Tags: #<Tag:0x00007fb884a20e38> #<Tag:0x00007fb884a20b40>



this is my first post in this forum.

I want to analyze images in a format that is not supported by ImageJ or plugins. I succeeded to write an ImageJ1 macro and a JavaScript that read and analyze the image header and then read the image data by calling run(“Raw…”, “parameters”). For ImageJ 1.51n it works and everything looks OK, but when I switch to ‘Modern Mode’ and apply commands from the menu, strange things happen:

E. g. after switching to ‘Modern Mode’, the shortcut ‘Control I’ shows the metadata that I set with setProperty, but ‘Image > Show Info…’ does not. Instead first a new window is opened that shows only a small part of the image (the rest is a white area), then the Info window opens but shows only ImageJ’s info.

Next example: applying ‘Image > Adjust > Auto-Contrast’ also opens a new window showing only a small part of the image. The Auto-Contrast is applied only to this new image. ‘Image > Adjust > Brightness/Contrast’ then indicates a negative brightness value.

Next example: when I zoom in, the indicated coordinates do not match with the location of the cursor (the indicated coordinates are too large). Only when the complete image suites into the window, correact coordinates are shown.

My code (in JavaScript):

// here the image header is read and analyzed:

// variables:
// fPath: file path
// sF: sample format
// wi: width
// he: height
// of: offset
// de: depth
// ch: number of channels
// then the image data are read:

if (ch == 1)
	var params = "open=" + fPath + " image=[" + sF + "] width=" + wi + " height=" + he + " offset=" + of + " number=" + de + " gap=0 little-endian";"Raw...", params);
	var nb = de*ch;
	params = "open=" + fPath + " image=[" + sF + "] width=" + wi + " height=" + he + " offset=" + of + " number=" + nb + " gap=0 little-endian use";"Raw...", params);"Stack to Hyperstack...", "order=xyczt(default) channels=" + ch + " slices=" + de + " frames=1 display=Composite");

var imp = WindowManager.getCurrentImage();
imp.setProperty("Info", header);


My questions:

What is wrong with my JavaScript?
Why does it work for ‘Old Mode’ but not for ‘Modern Mode’?
What have I to do in order that it works for both modes?
What have I to do in order to construct a reader plugin?

(ImageJ 2.0.0-rc-43/1.51n, Java 1.8.0_131 (64-bit), Windows 7)




have none of you actually experienced similar differences of ‘Modern Mode’ vs. ‘Old Mode’?



Welcome to the forum, @bulrichl!

Please note that the modern mode was a trial to re-build a graphical user interface (GUI) for ImageJ2 from scratch, but the current focus of development is on the IJ2 backend. The recommended way to use ImageJ is by using Fiji in its default mode, i.e. the legacy mode, as it preserves full backwards compatibility.

Also note that your JavaScript code uses API from ImageJ 1.x (WindowManager, IJ), so it’s not expected to work in modern mode.


Hi Jan,

thank you very much for your answer. Following your advice I installed Fiji and use it in its default mode now.

Apparently I have asked the wrong questions. The right question might be: how can I modify this script using the API of ImgLib2 and totally avoiding the use of the API of ImgLib1? Unfortunately this is not obvious to me because there seems to be little similarity between these APIs. I am not an experienced programmer, so I need a little help.