I am using fiji macro. The typical approach of setting scale by adding the size of scale bar in the set scale. Is there an other way to set the scale like by giving the size of each pixel in the macro rather than typical way of setting the scale? I wana skip setting the scale manually.
You can set the pixel size in a macro using
setVoxelSize(width, height, depth, unit)
Defines the voxel dimensions and unit of length (“pixel”, “mm”, etc.) for the current image or stack. A “um” unit will be converted to “µm”. The depth argument is ignored if the current image is not a stack. See also: getVoxelSize.
Hope this helps,
Thanks but I would like to globally set the scale so that I wont need to do this for each image. I would like to define at the beginning of a script that how much is the size of each pixel and it will be set to be used throughout the code. @Volko @haesleinhuepf @imagejan
If you do it in a macro, simply include the setVoxelSize() command after the command that you used to open the image.
Alternatively, you can use the following command at the start of your macro:
run(“Set Scale…”, “distance=100 known=200 unit=um global”);
This simulates using the ‘Set Scale’ command from the menu and sets the ‘Global’ option, but I would always be a bit careful using the ‘Global’ option as you can easily forget that you set it resulting in odd results.
Using the Macro Recorder can help you to see how you can access options in the ImageJ menu from a macro.
The problem is probably due to the incorrect inverted commas at start and end of the parameters - they need to be straight, rather than curly (this can happen when copying and pasting code from a post/email). I re-posted the code below, but this time formatted as code.
run("Set Scale...", "distance=100 known=200 unit=um global");
Alternatively, as mentioned in my previous post, use the macro recorder (Plugins → Macros → Record…) to create the code. Start the recorder and then go to ‘Set Scale’ (‘Analyze → Set Scale’), enter your required parameters, tick the ‘Global’ box and click ‘OK’. The macro recorder will record/create the appropriate command that you can include in your macro.