TrakEM2 image Normalization script error
Posted by Ashwin on Jul 17, 2013; 9:03pm
URL: http://imagej.273.s1.nabble.com/TrakEM2-image-Normalization-script-error-tp5004014.html
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