Hello everyone!
I'm building a Plug-in Filter and used the plug-in recorder to get some code from other plug-ins to re-use it. Although my plug-in has no errors from java it does nothing and I can't see where the problem is. The code is this: import ij.*; import ij.process.*; import ij.gui.*; import java.awt.*; import ij.plugin.ImageCalculator; import ij.plugin.filter.*; public class Cell_Marking implements PlugInFilter { ImagePlus imp; public int setup(String arg, ImagePlus imp) { this.imp = imp; return DOES_8G; } public void run(ImageProcessor ip) { ImagePlus copy = new ImagePlus(); copy = imp.duplicate(); copy.updateAndDraw(); IJ.run(imp, "Gray Morphology", "radius=20 type=circle operator=open"); ImageCalculator ic; ic = new ImageCalculator(); ImagePlus imp3 = ic.run("Subtract create", imp, copy); imp3.updateAndDraw(); } } What am I doing wrong? Best regards, João Silva -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Hi,
you should use the following imp3.show(); if you want to display your new image instead of updateAndDraw(); cheers, jp 2013/5/13 João Silva <[hidden email]> > Hello everyone! > > I'm building a Plug-in Filter and used the plug-in recorder to get some > code from other plug-ins to re-use it. > Although my plug-in has no errors from java it does nothing and I can't > see where the problem is. > > The code is this: > > import ij.*; > import ij.process.*; > import ij.gui.*; > import java.awt.*; > import ij.plugin.ImageCalculator; > import ij.plugin.filter.*; > > public class Cell_Marking implements PlugInFilter { > ImagePlus imp; > > public int setup(String arg, ImagePlus imp) { > this.imp = imp; > return DOES_8G; > } > > public void run(ImageProcessor ip) { > ImagePlus copy = new ImagePlus(); > copy = imp.duplicate(); > copy.updateAndDraw(); > IJ.run(imp, "Gray Morphology", "radius=20 type=circle operator=open"); > ImageCalculator ic; > ic = new ImageCalculator(); > ImagePlus imp3 = ic.run("Subtract create", imp, copy); > imp3.updateAndDraw(); > } > > } > > > > What am I doing wrong? > > > Best regards, > > João Silva > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Hi,
I've tried that already and it also doesn't work... Best regards, João Silva ________________________________________ De: ImageJ Interest Group [[hidden email]] em nome de Jean-Philippe Grossier [[hidden email]] Enviado: segunda-feira, 13 de Maio de 2013 14:42 Para: [hidden email] Assunto: Re: Plugin creation Hi, you should use the following imp3.show(); if you want to display your new image instead of updateAndDraw(); cheers, jp 2013/5/13 João Silva <[hidden email]> > Hello everyone! > > I'm building a Plug-in Filter and used the plug-in recorder to get some > code from other plug-ins to re-use it. > Although my plug-in has no errors from java it does nothing and I can't > see where the problem is. > > The code is this: > > import ij.*; > import ij.process.*; > import ij.gui.*; > import java.awt.*; > import ij.plugin.ImageCalculator; > import ij.plugin.filter.*; > > public class Cell_Marking implements PlugInFilter { > ImagePlus imp; > > public int setup(String arg, ImagePlus imp) { > this.imp = imp; > return DOES_8G; > } > > public void run(ImageProcessor ip) { > ImagePlus copy = new ImagePlus(); > copy = imp.duplicate(); > copy.updateAndDraw(); > IJ.run(imp, "Gray Morphology", "radius=20 type=circle operator=open"); > ImageCalculator ic; > ic = new ImageCalculator(); > ImagePlus imp3 = ic.run("Subtract create", imp, copy); > imp3.updateAndDraw(); > } > > } > > > > What am I doing wrong? > > > Best regards, > > João Silva > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Hi João,
Try using a PlugIn instead of a PlugInFilter. The behavior of PlugInFilter has several restrictions and differences from that of vanilla PlugIns. Below is a version of your plugin that (I think) accomplishes what you are trying to do. Regards, Curtis -- import ij.IJ; import ij.ImagePlus; import ij.plugin.ImageCalculator; import ij.plugin.PlugIn; public class Cell_Marking implements PlugIn { public void run(String arg) { ImagePlus imp = IJ.getImage(); ImagePlus copy = imp.duplicate(); IJ.run(imp, "Gray Morphology", "radius=20 type=circle operator=open"); ImageCalculator ic = new ImageCalculator(); ImagePlus imp3 = ic.run("Subtract create", copy, imp); imp.setProcessor(imp3.getProcessor()); imp.updateAndDraw(); } } On Mon, May 13, 2013 at 9:03 AM, João Silva <[hidden email]> wrote: > Hi, > > I've tried that already and it also doesn't work... > > Best regards, > > João Silva > ________________________________________ > De: ImageJ Interest Group [[hidden email]] em nome de Jean-Philippe > Grossier [[hidden email]] > Enviado: segunda-feira, 13 de Maio de 2013 14:42 > Para: [hidden email] > Assunto: Re: Plugin creation > > Hi, > > you should use the following > imp3.show(); > if you want to display your new image instead of updateAndDraw(); > > cheers, > > jp > > > 2013/5/13 João Silva <[hidden email]> > > > Hello everyone! > > > > I'm building a Plug-in Filter and used the plug-in recorder to get some > > code from other plug-ins to re-use it. > > Although my plug-in has no errors from java it does nothing and I can't > > see where the problem is. > > > > The code is this: > > > > import ij.*; > > import ij.process.*; > > import ij.gui.*; > > import java.awt.*; > > import ij.plugin.ImageCalculator; > > import ij.plugin.filter.*; > > > > public class Cell_Marking implements PlugInFilter { > > ImagePlus imp; > > > > public int setup(String arg, ImagePlus imp) { > > this.imp = imp; > > return DOES_8G; > > } > > > > public void run(ImageProcessor ip) { > > ImagePlus copy = new ImagePlus(); > > copy = imp.duplicate(); > > copy.updateAndDraw(); > > IJ.run(imp, "Gray Morphology", "radius=20 type=circle operator=open"); > > ImageCalculator ic; > > ic = new ImageCalculator(); > > ImagePlus imp3 = ic.run("Subtract create", imp, copy); > > imp3.updateAndDraw(); > > } > > > > } > > > > > > > > What am I doing wrong? > > > > > > Best regards, > > > > João Silva > > > > -- > > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > > > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
In reply to this post by João Silva
Hi João,
you should use the 'show()' method of an ImagePlus to display it. According to the documentation: ImagePlus.updateAndDraw() Updates this image from the pixel data in its associated ImageProcessor, then displays it. Does nothing if there is no window associated with this image (i.e. show() has not been called). There is a restriction of a PlugInFilter: The image is locked while you run the PlugInFilter to avoid other commands interfering. Thus, you have to unlock it (imp.unlock) if you want to modify it by an IJ.run command (this counts as a separate command). You will hear a beep if you try to process a locked image. Anyhow, I think that you want to leave the original unchanged and run the "Gray Morphology" filter on the copy. Then you need not unlock the original, and you can still use a PluginFilter. Then you may also specify a NO_CHANGES flag: return DOES_8G | NO_CHANGES; Michael ________________________________________________________________ On May 13, 2013, at 16:03, João Silva wrote: > Hi, > > I've tried that already and it also doesn't work... > > Best regards, > > João Silva > ________________________________________ > De: ImageJ Interest Group [[hidden email]] em nome de Jean-Philippe Grossier [[hidden email]] > Enviado: segunda-feira, 13 de Maio de 2013 14:42 > Para: [hidden email] > Assunto: Re: Plugin creation > > Hi, > > you should use the following > imp3.show(); > if you want to display your new image instead of updateAndDraw(); > > cheers, > > jp > > > 2013/5/13 João Silva <[hidden email]> > >> Hello everyone! >> >> I'm building a Plug-in Filter and used the plug-in recorder to get some >> code from other plug-ins to re-use it. >> Although my plug-in has no errors from java it does nothing and I can't >> see where the problem is. >> >> The code is this: >> >> import ij.*; >> import ij.process.*; >> import ij.gui.*; >> import java.awt.*; >> import ij.plugin.ImageCalculator; >> import ij.plugin.filter.*; >> >> public class Cell_Marking implements PlugInFilter { >> ImagePlus imp; >> >> public int setup(String arg, ImagePlus imp) { >> this.imp = imp; >> return DOES_8G; >> } >> >> public void run(ImageProcessor ip) { >> ImagePlus copy = new ImagePlus(); >> copy = imp.duplicate(); >> copy.updateAndDraw(); >> IJ.run(imp, "Gray Morphology", "radius=20 type=circle operator=open"); >> ImageCalculator ic; >> ic = new ImageCalculator(); >> ImagePlus imp3 = ic.run("Subtract create", imp, copy); >> imp3.updateAndDraw(); >> } >> >> } >> >> >> >> What am I doing wrong? >> >> >> Best regards, >> >> João Silva >> >> -- >> ImageJ mailing list: http://imagej.nih.gov/ij/list.html >> > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Free forum by Nabble | Edit this page |