ImageJ Macro: Different types of arrays

Hi there,

First of all, is there a way in the FIji macro language to check what type a certain variable is, like you can do in Python? (x.type)

If not, can someone explain to me the differences between these two ways of creating an empty “Array”, for example for the purpose of populating it later in a for loop:

NewVar = ‘’ ';
NewVar2 = NewArray(size);

I understand my question is super vague, so if anyone can point me in the right direction in terms of what to read about this, I would be grateful.

1 Like

Hi @Isq,

first of all, ImageJ macro is compared to Python a quite limited language. It’s made for calling some ImageJ operations in a row, not for building complex software. If you plan to build something bigger with ImageJ, I’d recommend using Fijis Jython. There is a nice online tutorial by @albertcardona.

Regarding your questions: I’m not aware of any isType or typeOf method.
The newArray Method works like this:

emptyArray = newArray(0);
print("Empty array:")

arrayWithThreeElements = newArray(3);
print("Array with three empty elements:")

arrayWithFourElements = newArray(1,2,3,4);
print("Array with four elements:")

longArray = Array.concat(arrayWithThreeElements, arrayWithFourElements);
print("Array with seven elements:")


There is also some explanation of numeric variables, strings and arrays online:

Let us know if that helps!



@haesleinhuepf this Jython resource is absolutely amazing, I guess if I plan to do more complex macro development it’s worth learning it (I already know some Python so hopefully it shouldn’t take too long), I definitely feel the ImageJ macro is quite restricting.

Thanks again :wink:

1 Like

Hi @Isq,
My general advice would be, if your macro is longer than about 10 lines, use a scripting language instead. Macros are great to quickly put together a batch processing job that mostly calls plugins; for more complex code, you’ll hit the macro language limitations rather fast, and while solutions can exist, they become unnecessarily convoluted–I say that having written tons of macro code myself, and even an entire interactive macro language interpreter, that later became the base for my scripting language interpreters (now in fiji-legacy update site) and even later the Script Editor itself. My suggestion is python (jython), as it is easy to learn, many already know it, and you can trivially call any of the many available libraries in Fiji–and if you need more java libraries, just drop them into and they’ll be available to your script upon restarting Fiji.