Acquiring the LUT of each Channel

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

Acquiring the LUT of each Channel

Mohamed Tleis
Dear members,

I am trying to get the Lookup tables for each channel in a 2 channel tif
image programmaticly. I have blue Lut in the first channel and gray in
the second. Here are my trys with the output commented.
I am never able to get the required results as "rgb[255] in the output"
should be blue for the first channel and white for the second.

Any Ideas?


[code]
import ij.ImagePlus;
import ij.ImageStack;
import ij.process.ImageProcessor;
import ij.process.LUT;
import loci.plugins.BF;
import loci.plugins.in.ImporterOptions;

public class testLuts {

     public void getImpLuts(String path)
     {
         ImagePlus imp = new ImagePlus(path);
         LUT[] luts = imp.getLuts();

         for(int i =0; i < luts.length; i++)
             System.out.println(luts[i].toString());

         /* Output: Exception in thread "main"
java.lang.NullPointerException
     at testLuts.main(testLuts.java:23)
Java Result: 1 */

     }

     public void getIpLut(String path)
     {
         ImagePlus imp = new ImagePlus(path);

         ImageStack stack = imp.getImageStack();


         for(int i =0; i < stack.getSize(); i++)
         {
             ImageProcessor ip = stack.getProcessor(i+1);
             LUT l = ip.getLut();
             System.out.println(l.toString());

/* OUTPUT:             rgb[0]=black, rgb[255]=blue, min=0.0000, max=255.0000
rgb[0]=black, rgb[255]=blue, min=0.0000, max=255.0000 */
         }
     }


     public void withBioFormats(String path)
     {
         try{
             ImporterOptions options = new ImporterOptions();
             options.setId(path);
             options.setAutoscale(true);
options.setColorMode(ImporterOptions.COLOR_MODE_COMPOSITE);

             ImagePlus[] imps = BF.openImagePlus(options);
             LUT[] luts = imps[0].getLuts();
             ImageStack stack = imps[0].getImageStack();
             for(int i = 0; i < luts.length; i++)
             {
System.out.println(luts[i].toString());
             }
             for(int i = 0; i < stack.getSize(); i++)
             {
                 ImageProcessor ip = stack.getProcessor(i+1);
                 LUT lut = ip.getLut();
                 System.out.println(lut.toString());
             }
         }
        catch(Exception x){x.printStackTrace();}
         /* OUTPUT
         rgb[0]=black, rgb[255]=blue, min=1.0000, max=68.0000
         rgb[0]=black, rgb[255]=blue, min=0.0000, max=213.0000
         rgb[0]=black, rgb[255]=white, min=0.0000, max=255.0000
         rgb[0]=black, rgb[255]=white, min=0.0000, max=255.0000*/
     }

     public static void main(String args[])
     {
         testLuts test = new testLuts();
         String path = "myImage.tif";
         test.withBioFormats(path);
         test.getIpLut(path);
         test.getImpLuts(path);
     }

}
[/code]

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Acquiring the LUT of each Channel

Rasband, Wayne (NIH/NIMH) [E]
On Jun 12, 2014, at 10:48 AM, Mohamed Tleis wrote:

> Dear members,
>
> I am trying to get the Lookup tables for each channel in a 2 channel tif image programmaticly. I have blue Lut in the first channel and gray in the second. Here are my trys with the output commented.
> I am never able to get the required results as "rgb[255] in the output" should be blue for the first channel and white for the second.

This code works as expected:

  ImagePlus imp = IJ.getImage();
  LUT[] luts = ((CompositeImage)imp).getLuts();
  for (int i=0; i<luts.length; i++)
      IJ.log(" "+luts[i]);

This is the output:

  rgb[0]=black, rgb[255]=blue, min=0.0000, max=230.0000
  rgb[0]=black, rgb[255]=white, min=0.0000, max=208.0000

-wayne


> Any Ideas?
>
>
> [code]
> import ij.ImagePlus;
> import ij.ImageStack;
> import ij.process.ImageProcessor;
> import ij.process.LUT;
> import loci.plugins.BF;
> import loci.plugins.in.ImporterOptions;
>
> public class testLuts {
>
>    public void getImpLuts(String path)
>    {
>        ImagePlus imp = new ImagePlus(path);
>        LUT[] luts = imp.getLuts();
>
>        for(int i =0; i < luts.length; i++)
>            System.out.println(luts[i].toString());
>
>        /* Output: Exception in thread "main" java.lang.NullPointerException
>    at testLuts.main(testLuts.java:23)
> Java Result: 1 */
>
>    }
>
>    public void getIpLut(String path)
>    {
>        ImagePlus imp = new ImagePlus(path);
>
>        ImageStack stack = imp.getImageStack();
>
>
>        for(int i =0; i < stack.getSize(); i++)
>        {
>            ImageProcessor ip = stack.getProcessor(i+1);
>            LUT l = ip.getLut();
>            System.out.println(l.toString());
>
> /* OUTPUT:             rgb[0]=black, rgb[255]=blue, min=0.0000, max=255.0000
> rgb[0]=black, rgb[255]=blue, min=0.0000, max=255.0000 */
>        }
>    }
>
>
>    public void withBioFormats(String path)
>    {
>        try{
>            ImporterOptions options = new ImporterOptions();
>            options.setId(path);
>            options.setAutoscale(true);
> options.setColorMode(ImporterOptions.COLOR_MODE_COMPOSITE);
>
>            ImagePlus[] imps = BF.openImagePlus(options);
>            LUT[] luts = imps[0].getLuts();
>            ImageStack stack = imps[0].getImageStack();
>            for(int i = 0; i < luts.length; i++)
>            {
> System.out.println(luts[i].toString());
>            }
>            for(int i = 0; i < stack.getSize(); i++)
>            {
>                ImageProcessor ip = stack.getProcessor(i+1);
>                LUT lut = ip.getLut();
>                System.out.println(lut.toString());
>            }
>        }
>       catch(Exception x){x.printStackTrace();}
>        /* OUTPUT
>        rgb[0]=black, rgb[255]=blue, min=1.0000, max=68.0000
>        rgb[0]=black, rgb[255]=blue, min=0.0000, max=213.0000
>        rgb[0]=black, rgb[255]=white, min=0.0000, max=255.0000
>        rgb[0]=black, rgb[255]=white, min=0.0000, max=255.0000*/
>    }
>
>    public static void main(String args[])
>    {
>        testLuts test = new testLuts();
>        String path = "myImage.tif";
>        test.withBioFormats(path);
>        test.getIpLut(path);
>        test.getImpLuts(path);
>    }
>
> }
> [/code]
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html