Trying to set a calibration table in plugin

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

Trying to set a calibration table in plugin

Charles Brossollet
Dear list,

I have 16 bits images, and I want to make computations on pixels and  
display the result for each pixel as I point the mouse. So the  
calibration table is perfect for this. I wrote a small plugin that  
takes sets the calibration table that I want, but it doesn't work: no  
error, but the calibrated value doesn't show in the status bar, as if  
the calibration was not active.

I use Fiji (1.42e) on Mac OS X 10.5.6

Here is the code:
import ij.*;
import ij.process.*;
import ij.gui.*;
import java.awt.*;
import ij.plugin.filter.*;

public class Show_Power implements PlugInFilter {
        ImagePlus imp;

        public int setup(String arg, ImagePlus imp) {
                this.imp = imp;
                return DOES_16+DOES_STACKS;
        }

        public void run(ImageProcessor ip) {
                float[] cTable = new float[65536];
                for (int i=0; i<65536; i++)
                {
                        float i_f=1.f;
                        if (i>32768)
                                i_f=(float)(i-32768);
                        cTable[i]=10*(2*log10(i_f)+log10(0.2f)-10.51f) ;
                }
                ip.setCalibrationTable(cTable);
               
                imp.updateAndDraw();
        }
       
        private float log10(float x)
        {
          if (x > 0.0)
            return (float)(Math.log((double)(x)) / Math.log(10.));
          else
            return Float.NEGATIVE_INFINITY;
        }
}

Any help appreciated!
Thanks,

Charles
Reply | Threaded
Open this post in threaded view
|

Re: Trying to set a calibration table in plugin

Wayne Rasband
To assign a calibration table to an image you need to use the
setCTable() method of the Calibration class. Here is an updated version
of your plugin that uses setCTable().

import ij.*;
import ij.plugin.*;
import ij.measure.Calibration;

public class Show_Power implements PlugIn {

        public void run(String arg) {
  ImagePlus imp = IJ.getImage();
                if (imp.getBitDepth()!=16) {
                        IJ.error("16-bit image rquired");
                        return;
                }
                float[] cTable = new float[65536];
                for (int i=0; i<65536; i++) {
                        float i_f=1.f;
                        if (i>32768)
                                i_f=(float)(i-32768);
                        cTable[i]=10*(2*log10(i_f)+log10(0.2f)-10.51f) ;
                }
                imp.getCalibration().setCTable(cTable, "Power");
        }
       
        private float log10(float x) {
          if (x > 0.0)
            return (float)(Math.log((double)(x)) / Math.log(10.));
          else
            return Float.NEGATIVE_INFINITY;
        }

}

-wayne

On Apr 17, 2009, at 9:09 AM, Charles Brossollet wrote:

> Dear list,
>
> I have 16 bits images, and I want to make computations on pixels and
> display the result for each pixel as I point the mouse. So the
> calibration table is perfect for this. I wrote a small plugin that
> takes sets the calibration table that I want, but it doesn't work: no
> error, but the calibrated value doesn't show in the status bar, as if
> the calibration was not active.
>
> I use Fiji (1.42e) on Mac OS X 10.5.6
>
> Here is the code:
> import ij.*;
> import ij.process.*;
> import ij.gui.*;
> import java.awt.*;
> import ij.plugin.filter.*;
>
> public class Show_Power implements PlugInFilter {
> ImagePlus imp;
>
> public int setup(String arg, ImagePlus imp) {
> this.imp = imp;
> return DOES_16+DOES_STACKS;
> }
>
> public void run(ImageProcessor ip) {
> float[] cTable = new float[65536];
> for (int i=0; i<65536; i++)
> {
> float i_f=1.f;
> if (i>32768)
> i_f=(float)(i-32768);
> cTable[i]=10*(2*log10(i_f)+log10(0.2f)-10.51f) ;
> }
> ip.setCalibrationTable(cTable);
>
> imp.updateAndDraw();
> }
>
> private float log10(float x)
> {
>  if (x > 0.0)
>    return (float)(Math.log((double)(x)) / Math.log(10.));
>  else
>    return Float.NEGATIVE_INFINITY;
> }
> }
>
> Any help appreciated!
> Thanks,
>
> Charles
>