Re: Normalizing images with ContrastEnhancer
Posted by
Rasband, Wayne (NIH/NIMH) [E] on
Jan 17, 2014; 1:29am
URL: http://imagej.273.s1.nabble.com/Normalizing-images-with-ContrastEnhancer-tp5006145p5006146.html
On Jan 16, 2014, at 6:36 PM, JiHO wrote:
> Hello everyone,
>
> We're writing a command line java program which uses ImageJ as a library.
> The goal is to run it in headless mode, on a remote server, churning
> through millions of images.
>
> A step of the process of requires to normalize the image. It works
> perfectly with
>
> IJ.run(imp, "Enhance Contrast...", "saturated=0.1 normalize");
>
> however, using this code on a Linux box requires an X11 connection because
> it requests some elements of the interface even if the interface itself is
> not drawn (as far as I understood). We have circumvented it by using Xvfb
> but it looks like we should be able to use the method stretchHistogram of
> the class ContrastEnhancer directly and (hopefully) do not got through the
> GUI stuff. However, while our code compiles fine, the image appears
> unaffected. Here is the relevant bit of code. It gets an ImagePlus object
> named imp:
>
> IJ.save(imp, "orig.jpg")
> ImageProcessor ip = imp.getProcessor();
> ContrastEnhancer ce = new ContrastEnhancer();
> ce.stretchHistogram(ip, 0.1);
> ip.resetMinAndMax();
> ImagePlus imp2 = new ImagePlus("", ip);
> IJ.save(imp2, "final.jpg");
>
> the images orig and final are the same. equalization works great using
> ce.equalize(ip) but the normalize method of ContrastEnhancer is not public
> so we can't use it the same way. Wether normalization is performed or not
> is decided within stretchHistogram by a boolan variable which is again
> internal to ContrastEnhancer, and external to stretchHistogram. It can be
> set through the interface but we cannot find how to set it programmatically.
The latest ImageJ daily build (1.48q7) adds a setNormalize(boolean) method to the ContrastEnhancer class so all you need to do is add
ce.setNormalize(true);
just before the stretchHistogram() call.
-wayne
--
ImageJ mailing list:
http://imagej.nih.gov/ij/list.html