ContrastEnhancer stretchHistogram doubt

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

ContrastEnhancer stretchHistogram doubt

Zian_Fanti
Hello, i try to made a plugin to do some operations between images and then
auto adjust the brigth and contrast. For the latter I use the function
stretchHistogram in the class ContrastEnhancer. The resulting image is
displayed correctly (with the brigth and contrast enhanced) but the pixels
value don't change. The question is how can apply the enhance in the pixels
vlues? I figured out I Have to do some update or something like that, but I
can't find how.

This is the code:

ImageProcessor subtracted = imp_1.getProcessor().duplicate();
ImageProcessor ip_2 = imp_2.getProcessor();
subtracted.copyBits(ip_2, 0, 0, Blitter.SUBTRACT);

ContrastEnhancer enhancer = new ContrastEnhancer();
enhancer.stretchHistogram(subtracted, 0.5);
ImagePlus imp_3 = new ImagePlus(null, subtracted);
imp_3.show();
Reply | Threaded
Open this post in threaded view
|

Re: ContrastEnhancer stretchHistogram doubt

Rasband, Wayne (NIH/NIMH) [E]
On Oct 6, 2010, at 11:56 AM, Zian Fanti wrote:

> Hello, i try to made a plugin to do some operations between images and then
> auto adjust the brigth and contrast. For the latter I use the function
> stretchHistogram in the class ContrastEnhancer. The resulting image is
> displayed correctly (with the brigth and contrast enhanced) but the pixels
> value don't change. The question is how can apply the enhance in the pixels
> vlues? I figured out I Have to do some update or something like that, but I
> can't find how.
>
> This is the code:
>
> ImageProcessor subtracted = imp_1.getProcessor().duplicate();
> ImageProcessor ip_2 = imp_2.getProcessor();
> subtracted.copyBits(ip_2, 0, 0, Blitter.SUBTRACT);
>
> ContrastEnhancer enhancer = new ContrastEnhancer();
> enhancer.stretchHistogram(subtracted, 0.5);
> ImagePlus imp_3 = new ImagePlus(null, subtracted);
> imp_3.show();

You can generate the needed code by using the Process>Enhance Contrast command with the recorder running. This is what it looks like:

    IJ.run(imp, "Enhance Contrast", "saturated=0.5 normalize");

-wayne