Search code examples
javaimageimage-manipulationimagej

Increase contrast of image using ImageJ library (Java)


I am trying to increase the contrast of an image by some factor x

So far I am able to read in an image, and get its processor like this

ImagePlus im = new ImagePlus(imagePathHere);
ImageProcessor ip = im.getProcessor();

I am aware of ContrastEnhancer.java and ContrastAdjuster.java but I am not sure how they would be used. Ultimately, I would want something like this

ImagePlus imc = increaseContrast(im, 0.5)

Thank you!


Solution

  • This seems to work:

    ImagePlus im = new ImagePlus(imagePathHere);
    ContrastEnhancer enh = new ContrastEnhancer();
    enh.stretchHistogram(plus, i);
    

    where i < 100;

    When you call

    im.getImage();
    

    you will get an image with increased contrast.