Normalizing images with ContrastEnhancer

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

Normalizing images with ContrastEnhancer

JiHO-2
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.

Any help would be really appreciated. Sincerely,

Jean-Olivier Irisson

Observatoire Océanologique
Station Zoologique, 181 Chemin du Lazaret
06230 Villefranche-sur-Mer
Tel: +33 04 93 76 38 04
Mob: +33 06 21 05 19 90
http://www.obs-vlfr.fr/~irisson/
Send me large files at: http://www.obs-vlfr.fr/~irisson/upload/

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

Re: Normalizing images with ContrastEnhancer

Rasband, Wayne (NIH/NIMH) [E]
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