Getting user input from Dialog boxes for scaling and analyzing particles

I’m writing a Fiji macro to analyze cross sectional area of muscle fibers. For accurate measurements with my macro you have to set the pixels per known distance (scale) and the prominence (for segmentation). I have a single dialog box where the user can input these values, but I don’t know how to get those values into the code where they need to be.

For the sake of simplicity, lets start with “how do I get the input from a custom dialog box to set the scale for the image”?

Thanks!

Use macro variables and script parameters.

  • First, record the Set Scale… command using the macro recorder. This will give you something like:

    run("Set Scale...", "distance=5 known=1 pixel=1 unit=um");
    
  • Get a user parameter, e.g. distance_in_pixels using a script parameter:

    #@ Double distance_in_pixels
    
  • Use the new variable in the recorded command by employing string concatenation:

    run("Set Scale...", "distance=" + distance_in_pixels + " known=1 pixel=1 unit=um");
    

I hope these basic building blocks help getting you started. To add more items to the user dialog, create more script parameters using the hash-at (#@) syntax.