Search code examples
image-processingimagej

changes not updating in ImageJ


guys just now i downloaded the ImageJ Jar. Completely new to it. I tried flipping/rotating the image. The program is executing but no changes are being reflected to the image. My code is ---

    import ij.ImagePlus;
    import ij.process.ImageProcessor;

    public class ImageProcessing{
    public static void main(String arg[]){
    ImagePlus imp= new ImagePlus("images/Koala.jpg");
    ImageProcessor ip=imp.getProcessor();
    try{ip.rotateLeft();}catch(Exception e){
        e.printStackTrace();
    }

    imp.updateAndDraw();

}
} 

Stuck since an hour, kindly help guys... thanks in advance..!


Solution

  • ImageProcessor#rotateLeft() returns a new ImageProcessor, that should be assigned to the ImagePlusagain.

    The following code works for me within Fiji/ImageJ:

    import ij.IJ;
    import ij.ImagePlus;
    import ij.plugin.PlugIn;
    import ij.process.ImageProcessor;
    
    public class Image_Processing implements PlugIn {
        public void run(String arg){
            ImagePlus imp = IJ.openImage("http://imagej.nih.gov/ij/images/clown.jpg");
            ImageProcessor ip=imp.getProcessor().rotateLeft();
            imp.setProcessor(ip);
            imp.show();
        }
    } 
    

    Hope that helps.