Login  Register

TrakEM2 image Normalization script error

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

TrakEM2 image Normalization script error

Ashwin
Hi all,

I am trying to normalize images in a trakEM2 project to a fixed mean and Std. Here is what I have so far;


import ij.*;
import ij.process.*;
import ij.plugin.filter.*;
import ij.measure.Measurements;
import ini.trakem2.display.*;


// parameters
newVar = 44.0;
newMean = 144.0;

p = Display.getFront().getActive();
imp = p.getImagePlus();
ip = imp.getProcessor();

stats = ImageStatistics.getStatistics( ip, Measurements.MEAN + Measurements.STD_DEV, null);

fp = ip.convertToFloat();

        // subtract mean
        fp.subtract(stats.mean);
       
        // divide by std dev
        fp.multiply(1.0 / stats.stdDev);

        // multiply by the new variance
        fp.multiply( newVar );

        // add the new mean
        fp.add( newMean );

        // convert to byte
        ip = fp.convertToByte( false );

imp.setProcessor( ip );

At the end of the script the selected image does not update to the new values. In the BeanShell interpreter, I do not get any errors either. But the image remains the same. I checked to see if ip is actually getting updated to the new values and it is. I am not sure why this is happening.

Could someone help with this?

Thanks,
Ashwin
Reply | Threaded
Open this post in threaded view
| More
Print post
Permalink

Re: TrakEM2 image Normalization script error

Albert Cardona-2
I'd use the image filters inside trakem2. See the popup menu at adjust images - image filters.

A.

On Jul 17, 2013, at 5:03 PM, Ashwin <[hidden email]> wrote:

> Hi all,
>
> I am trying to normalize images in a trakEM2 project to a fixed mean and
> Std. Here is what I have so far;
>
>
> import ij.*;
> import ij.process.*;
> import ij.plugin.filter.*;
> import ij.measure.Measurements;
> import ini.trakem2.display.*;
>
>
> // parameters
> newVar = 44.0;
> newMean = 144.0;
>
> p = Display.getFront().getActive();
> imp = p.getImagePlus();
> ip = imp.getProcessor();
>
> stats = ImageStatistics.getStatistics( ip, Measurements.MEAN +
> Measurements.STD_DEV, null);
>
> fp = ip.convertToFloat();
>
>    // subtract mean
>    fp.subtract(stats.mean);
>    
>    // divide by std dev
>    fp.multiply(1.0 / stats.stdDev);
>
>    // multiply by the new variance
>    fp.multiply( newVar );
>
>    // add the new mean
>    fp.add( newMean );
>
>    // convert to byte
>    ip = fp.convertToByte( false );
>
> imp.setProcessor( ip );
>
> At the end of the script the selected image does not update to the new
> values. In the BeanShell interpreter, I do not get any errors either. But
> the image remains the same. I checked to see if ip is actually getting
> updated to the new values and it is. I am not sure why this is happening.
>
> Could someone help with this?
>
> Thanks,
> Ashwin
>
>
>
> --
> View this message in context: http://imagej.1557.x6.nabble.com/TrakEM2-image-Normalization-script-error-tp5004014.html
> Sent from the ImageJ mailing list archive at Nabble.com.
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html

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