2 Replies Latest reply on Nov 4, 2011 11:23 AM by 897927

    How to auto adjust images in imageJ?


      I would like to know How can I adjust the contrast and brightness in imageJ using a Java application?
      imageJ has
      and inside it an
      function which is not public, so I cannot call it? any one has experience with this?

      Best Regards,
        • 1. Re: How to auto adjust images in imageJ?
          Your calling class needs to be at that access modifier allowance ,
          since your caller probably isn't,
          you can make a small class with that access level(no specifier - is between protected and private) to join it that you can reference with your caller package level,
          or probably better, a nested class of that access level in your caller class with global scope instantiation in your caller.

          *// not all syntax is here - This just to give you a guide of the type of access specifier shuffling and reprocessing to obtain the methods variables at the same level as obtaining the ability to call the method , it may be more practical to target the class in imageJ that instantiates the ContrastAdjuster class and simply obtain its reference to ContrastAdjuster*
          *//ContrastAdjuster adj - should be passed from wherever it is instantiated , presumably its in a higher level class frame in the application*

          public class IwasCalling{
          CallAutoAdjuster callAUTContraster;

          public IwasCalling(ContrastAdjuster adj){
          callAUTContraster = new CallAutoAdjuster();


          //start nested class
          class CallAutoAdjuster{

          void callAutoAdjuster(){

          autoAdjust(imp,ip); // ImagePlus imp , ImageProcessor ip

          }//end method

          }//end nested

          }//end iwascalling

          Edited by: 893871 on Nov 3, 2011 6:53 PM

          After taking a good look at the .java files
          --i find the doAutoAdjust variable requires to be set in the public class ContrastAdjuster and call notify()--
          ..and i have no idea how i lost the plot there... it was the contrast slider value you wanted
          so a method would be from some class you create
          // contr is the reference to the ij plugin frame extended from JFrame that ContrastAdjuster.java extends from
          public int adJustContrast(int slideVal){ // this listener method sets an int in  ContrastAdjuster public synchronized void adjustmentValueChanged(AdjustmentEvent e)
          // with the line contrastValue = contrastSlider.getValue();
          // int sliderRange = 256; this global int is divided by two appears to be the Max for contrast and the or a scrollbar appears to be a make-shift slider value changer
          contr.contrastValue = slideVal; // global accessible int in ContrastAdjuster
          return contr.contrastValue;
          public boolean adjAuto(){
          contr.doAutoAdjust = true;
          return contr.doAutoAdjust;
          public void updateNotifyComm(){ // now update the app
          //............... so you would call from somewhere to do it by this after making those methods
          updateNotifyComm(); // or just running code of contr.notify();
          // i have no idea how that became boolean  doAutoAdjust in my mind
          // for auto adjust
          Edited by: 893871 on Nov 3, 2011 8:15 PM

          Edited by: 893871 on Nov 3, 2011 8:17 PM

          Edited by: 893871 on Nov 3, 2011 8:23 PM
          • 2. Re: How to auto adjust images in imageJ?
            Thank you for your assistance,

            I was able to find a simpler way to do that, thanks to imageJ
            developer Wayne Rasband,
            Recording a macro will generate the java code which can be used in the java application:
            IJ.run(imPlus, "Enhance Contrast", "saturated=0.35");
            Best Regards,