Hi,
I would like to write a plugin similar to this one: import ij.ImagePlus; import ij.plugin.filter.PlugInFilter; import ij.process.ImageProcessor; public class My_Inverter implements PlugInFilter { public int setup (String arg, ImagePlus im) { return DOES_8G; // This plugin accepts 8-bit grayscale images } public void run (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); } } } } But I would like it to open an image from a specified path, instead of working on an image which is already open in ImageJ. How can I change the code to do that? Thanks, Avital -- ImageJ mailing list: http://imagej.nih.gov/ij/list.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); } } } } |
Thank you for your answer - I'm getting an error message that is related to
the first line: package gui. I tried commenting it out, and then it allowed me to choose a file interactively, but it didn't seem to do anything else. In this case, I didn't see an error message. Do you have any suggestions how to fix it? Thanks, Avital On Tue, Aug 5, 2014 at 3:20 PM, vcaldas <[hidden email]> wrote: > 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); > } > } > } > } > > > > > -- > View this message in context: > http://imagej.1557.x6.nabble.com/How-can-I-write-a-similar-plugin-that-opens-a-file-from-a-specified-path-tp5009034p5009035.html > Sent from the ImageJ mailing list archive at Nabble.com. > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Are you using an IDE? Because this
package gui; is just local. You don't need it anyway. If you have debug messages, send them I check. I have similar codes here, so, this is easy to fix =) Cheers |
Free forum by Nabble | Edit this page |