follow-up question regarding macros for adjusting contrast

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

follow-up question regarding macros for adjusting contrast

William Jeffrey Triffo
hello,

I recently posted a macro (attached inline below) that I wish to use for
adding scalebars and adjusting contrast of a series of images, followed
by conversion to jpeg.

I have the scalebars part working now, but the contrast adjustment is
not working. I tried "Apply LUT", but the files are originally 16-bit; I
ran "8-bit", but then the macro issues an error that "The display range
must first be updated using Image>Adjust>Brightness/Contrast...". (I
tried having the macro launch "run("Brightness/Contrast...")" to see if
it just wanted that window up prior to the contrast adjustment, but this
did not work of course)

When I am manipulating an image by hand in ImageJ, if I "Save As" to
jpeg (from a 16-bit grayscale image), it applies the contrast adjustment
- I do not have to click "Apply" in the B/C dialog. This tells me that I
am missing something regarding how the macro is operating differently
than the normal UI.

Also, I noticed that when I click "Auto" in the B/C dialog, the max/min
values are different than what results from calling run("Enhance
Contrast", "saturated=0.5") in the macro; but this is the same command
that pops up in the macro recorder when I click "Auto".

any suggestions as to how I can get the adjusted-contrast image to save
properly, and also why the min/max values appear to be different when
calling "Enhance Contrast" in a macro vs. the "Auto" button in the B/C
dialog? I also noticed that if I call run("Enhance Contrast", ...)
multiple times, it does not appear to change the min/max in each
iteration - I have been in the habit of clicking "Auto" in the B/C
dialog 1-3 times, but am realizing that setting a loop to call the
equivalent macro command may not be doing the same thing.

thanks for the advice that's been given thus far,

-Jeff


  macro "Batch Convert Image to JPEG with 1 Contrast and Scalebar"
{convert("jpeg");}

  function convert(format) {
      requires("1.33s");
      desired_bar = getNumber("Please input desired scale-bar length in
nm:",100);
      desired_height = getNumber("Please input desired scale-bar
thickness:",12);

      auto_con = getBoolean("Do you want auto-contrast adjustment?");
      if(auto_con == 1)
         con_rounds = getNumber("How many rounds of auto-contrast?",1);

      dir1 = getDirectory("Choose Source Directory ");
      dir2 = getDirectory("Choose Destination Directory ");
      list = getFileList(dir1);
      setBatchMode(true);
      for (i=0; i<list.length; i++) {
          showProgress(i+1, list.length);
          open(dir1+list[i]);
          getPixelSize(unit,pW,pH);

          if (unit=="microns")
        bar_length = desired_bar / 1000;
      else if (unit=="nm")
        bar_length = desired_bar;
          else {
                bar_length = desired_bar;
                print("Scale of image" +list[i] + "not in nm or microns");
                }
        //  print("Image " +list[i]+ " has units of " +unit+ " and scale
bar of " +bar_length+ " " +unit);

      if(auto_con == 1){
        //  run("Brightness/Contrast...");
             for(j=0; j < con_rounds; j++){
      run("Enhance Contrast", "saturated=0.5");
          print("running contrast enhance pass " +j+ "on image " +list[i]);}
          getMinAndMax(min,max);
          print("image " +list[i]+ " has min = " +min+ " and max = " +max);
          run("8-bit");
         run("Apply LUT");

          }

      run("Scale Bar...", "width=" + bar_length + " height=" +
desired_height + " font=14 color=White background=None location=[Lower
Right]");

          saveAs(format, dir2+list[i]);
          close();
      }
  }