Hi all,
I have the following code: import ij.*; import ij.process.*; import ij.gui.*; import java.awt.*; import ij.plugin.*; import ij.plugin.filter.Convolver; import ij.io.*; public class Colli_Shots implements PlugIn { public void run(String arg) { OpenDialog od = new OpenDialog("Open.....", null); Opener op = new Opener(); String directory = od.getDirectory(); String filename = od.getFileName(); ImagePlus imp = new ImagePlus(directory); ImageProcessor ip = imp.getProcessor(); float[] H = {1,0,1,2,0,2,1,0,1}; Convolver cv = new Convolver(); cv.setNormalize(false); cv.convolve(ip,H,3,3); //imp.updateAndDraw(); } } I just to apply a sobel operator to an image. However when I run the above code, it compiles but I get a NullPOinterException. Any ideas why this is? Thanks for your time Gary |
Hi,
I think this might has to do with creating a new ImagePlus, you are assigning the directory name to a new imagePlus, maybe you mean new ImagePlus(directory+ "/" + filename); or whatever separator used. Best Regards, On Thu, Apr 19, 2012 at 12:52 PM, Gary <[hidden email]> wrote: > Hi all, > > I have the following code: > > import ij.*; > import ij.process.*; > import ij.gui.*; > import java.awt.*; > import ij.plugin.*; > import ij.plugin.filter.Convolver; > import ij.io.*; > > public class Colli_Shots implements PlugIn { > public void run(String arg) { > > OpenDialog od = new OpenDialog("Open.....", null); > Opener op = new Opener(); > String directory = od.getDirectory(); > String filename = od.getFileName(); > > ImagePlus imp = new ImagePlus(directory); > ImageProcessor ip = imp.getProcessor(); > float[] H = {1,0,1,2,0,2,1,0,1}; > Convolver cv = new Convolver(); > cv.setNormalize(false); > cv.convolve(ip,H,3,3); > //imp.updateAndDraw(); > > } > > } > > > I just to apply a sobel operator to an image. However when I run the above > code, > it compiles but I get a NullPOinterException. > > Any ideas why this is? > > Thanks for your time > > Gary > |
In reply to this post by bateman
On Apr 19, 2012, at 6:52 AM, Gary wrote:
> Hi all, > > I have the following code: > > import ij.*; > import ij.process.*; > import ij.gui.*; > import java.awt.*; > import ij.plugin.*; > import ij.plugin.filter.Convolver; > import ij.io.*; > > public class Colli_Shots implements PlugIn { > public void run(String arg) { > > OpenDialog od = new OpenDialog("Open.....", null); > Opener op = new Opener(); > String directory = od.getDirectory(); > String filename = od.getFileName(); > > ImagePlus imp = new ImagePlus(directory); > ImageProcessor ip = imp.getProcessor(); > float[] H = {1,0,1,2,0,2,1,0,1}; > Convolver cv = new Convolver(); > cv.setNormalize(false); > cv.convolve(ip,H,3,3); > //imp.updateAndDraw(); > > } > } > > I just to apply a sobel operator to an image. However when I run the above code, > it compiles but I get a NullPOinterException. > > Any ideas why this is? The ImagePlus constructor requires a full file path: ImagePlus imp = new ImagePlus(directory+filename); However, an easier way to open the image is to use IJ.openImage(""). Here is an example: public void run(String arg) { ImagePlus imp = IJ.openImage(""); ImageProcessor ip = imp.getProcessor(); float[] H = {1,0,1,2,0,2,1,0,1}; Convolver cv = new Convolver(); cv.setNormalize(false); cv.convolve(ip,H,3,3); imp.show(); } -wayne |
Free forum by Nabble | Edit this page |