this post was submitted on 14 Jul 2023
1 points (100.0% liked)

Image Processing and Analysis

94 readers
1 users here now

A community for sharing knowledge (interesting or new methods, scripts, theoretical concepts, etc), asking questions (troubleshooting, asking for suggestions, general concepts, etc) and discussing all topics related to image processing and analysis (show and tell, careers, software, etc).

founded 1 year ago
MODERATORS
QZM
 

I came across a small script that opens a window with a progress bar that increases after the completion of every iteration in a for loop. It's pretty useful in a big macro cycling through many images. Sometimes you just want to know your progress in batch mode. So here is the helpful script (from https://imagej.nih.gov/ij/macros/ProgressBar.txt):

// Progress Bar
//
// This macro demonstrates how to display status
// information and a progress bar in a text window. 
// It uses the Plugins>New>Text Window command
// to open a text window without a menu bar.

  title = "[Progress]";
  run("Text Window...", "name="+ title +" width=25 height=2 monospaced");
  for (i=0; i<100; i++) {
     print(title, "\\Update:"+i+"/"+100+" ("+(i*100)/100+"%)\n"+getBar(i, 100));
     wait(200);
  }
  print(title, "\\Close");

  function getBar(p1, p2) {
        n = 20;
        bar1 = "--------------------";
        bar2 = "********************";
        index = round(n*(p1/p2));
        if (index<1) index = 1;
        if (index>n-1) index = n-1;
        return substring(bar2, 0, index) + substring(bar1, index+1, n);
  }

Note: if you using other nested for loops, ensure that the variable you choose isn't the same as the one here (i), except of course the for loop you're actually trying to find track the process of. Happy macroing!

you are viewing a single comment's thread
view the rest of the comments
[โ€“] [email protected] 2 points 1 year ago* (last edited 1 year ago) (1 children)

Generally I've preferred using the showProgress function in ImageJ, since it doesn't require a new window:

showProgress(progress)

Updates the ImageJ progress bar, where 0.0progress<=1.0. The progress bar is not displayed if the time between the first and second calls to this function is less than 30 milliseconds. It is erased when the macro terminates or progress is >=1.0. Use negative values to show subordinate progress bars as moving dots (example).

showProgress(currentIndex, finalIndex)

Updates the progress bar, where the length of the bar is set to currentIndex/finalIndex of the maximum bar length. The bar is erased if currentIndex>finalIndex or finalIndex==0.

[โ€“] QZM 1 points 1 year ago

Can't believe I didn't know about this. Thanks a lot! This should shave several lines off my macros.