Re: save 16 bit tif

Posted by Thomas Boudier on
URL: http://imagej.273.s1.nabble.com/save-16-bit-tif-tp3695929p3695930.html

Hi Alessandra,

Why not use the imageConverter class :

import ij.*;
import ij.process.*;
import ij.gui.*;
import java.awt.*;
import ij.plugin.filter.*;

public class Filter_Plugin implements PlugInFilter {
        ImagePlus imp;

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

        public void run(ImageProcessor ip) {
                ImageConverter c=new ImageConverter(imp);
                c.convertToGray16();
        }

}

Do not forget to adjust the contrast before converting to 16 bits.

Thomas



>
> I have an ImagePlus stack ('impoutstack'), 32 bit, and I would like to save
> it as a 16 bit tif stack.
> I did this:
>
> *ImageProcessor ip = impoutstack.getProcessor();
> impoutstack.setProcessor(null, ip.convertToShort(true)); // conversion
impoutstack.setCalibration(impoutstack.getCalibration()); // update
calibration

> FileSaver saverstack = new FileSaver(impoutstack);*
> *saverstack.saveAsTiffStack(pathout + "/" + filename + ".tif");*
>
> but at run time I get the exception
>
> *java.lang.ClassCastExceprion at ij.io.ImageWriter.write16BitStack*
>
> Does anyone know how to easily save as 16 bit tif stack?
>
> Thanks a lot,
> Alessandra
>
>