variablesmacrosimagejfiji

Use variable in calibrate function ImageJ macro


I want to convert the grayscale values to nm (height) values using the Analyze->Calibrate function in ImageJ. I also would like to do this automatically, where the desired values are read out from the file name. So I used the macro record function to get this:

run("Calibrate...", "function=[Straight Line] unit=nm text1=[0\015 255] text2=[0\015 12]");

and changed it to

a = 12; run("Calibrate...", "function=[Straight Line] unit=nm text1=[0\015 255] text2=[0\015 a]");

where "a" will represent my maximum height level.

However this does not work and the variable "a" is not read as its value. Does anybody knows how to overcome this? I used the same strategy to convert x/y pixel value to distance, and that does work.

The above example is the only thing I tried since I had no idea what else to do.


Solution

  • In ImageJ Macro language, arguments are passed as strings. You need to do:

    a = 12;
    run("Calibrate...", "function=[Straight Line] unit=nm text1=[0\015 255] text2=[0\015 " + a + "]");
    

    This will substitute 12 after the space and before the square bracket, in the string to be passed as an argument.