Login  Register

Re: How can I write a similar plugin that opens a file from a specified path?

Posted by vcaldas on Aug 05, 2014; 12:20pm
URL: http://imagej.273.s1.nabble.com/How-can-I-write-a-similar-plugin-that-opens-a-file-from-a-specified-path-tp5009034p5009035.html

Didn't test for small bugs, but this should work.

Cheers.
Victor


package gui;
import ij.IJ;
import ij.ImagePlus;
import ij.plugin.PlugIn;
import ij.process.ImageProcessor;

public class My_Inverter implements PlugIn {
        String FileName;
    private static final int DOES_8G = 0;

        public int setup (String arg, ImagePlus imp) {
        return DOES_8G; // This plugin accepts 8-bit grayscale images
    }

    public void run(String arg0) {
               
                FileName = IJ.getFilePath("Choose the file");
                ImagePlus imp= IJ.openImage(FileName );
                ImageProcessor ip = imp.getProcessor();
                Inverter(ip);
                imp.draw();
        }
   
    public void Inverter(ImageProcessor ip) {
        int w = ip.getWidth();
        int h = ip.getHeight();

        for (int u = 0; u < w; u++) {
            for (int v = 0; v < h; v++) {
                int p = ip.getPixel(u, v);
                ip.putPixel(u, v, 255-p);
            }
        }
    }
}