Login  Register

Re: IPDemo Plugin - calling 'IJ.run(..)' - Image is locked

Posted by Michael Schmid on Oct 09, 2008; 8:53am
URL: http://imagej.273.s1.nabble.com/IPDemo-Plugin-calling-IJ-run-Image-is-locked-tp3694825p3694826.html

Hi Ghislain,

In the IP_Demo.java PlugInFrame the image is locked before doing any  
operation to make sure that there is no other operation running on  
the image at the same time:

     public void actionPerformed(ActionEvent e) {
         ...
         if (!imp.lock())   //this locks the image
             {previousID = 0; return;}

The corresponding imp.unlock(); command is near the end of
     void runCommand(String command, ImagePlus imp, ImageProcessor ip)

Most of the IJ.run(...) commands lock the image themselves; the
ImageProcessor methods don't.
So you have an image that is already locked and then you use IJ.run.
That's why you get the error message.

You can either remove the lock and unlock commands from your  
PluginFrame or avoid using IJ.run commands.

Two more remarks:
  - If you write a PlugInFilter or ExtendedPlugInFilter (in contrast  
to a PlugInFrame or PlugIn) the image will be locked by ImageJ before  
running the (Extended)PlugInFilter.
  - When using IJ.run, the version
     run(ImagePlus imp, String command, String options)
is preferrable because it is always clear which Image to use. Thus it  
won't cause problems due to multithreading (e.g. if the user clicks  
on another image while the plugin is still working).


Michael
________________________________________________________________

On 9 Oct 2008, at 10:26, Ghislain Bugnicourt wrote:

> Hello.
> I am trying to create a plugin that counts the number of lines that  
> cross a
> circle around a point (more precisely, the number of neurites  
> emitted by a
> neuron in culture). I am only at the first steps.
> I downloaded the IPDemo plugin, and I tried to modify it, by  
> replacing a
> button action by :
> IJ.run("Median...", radius="2");
> The problem is that "the image is locked" when I click this button.  
> What
> should I modify to be able to call any IJ action ?
>
> Actually, I don't want to use ip.medianFilter() in the IPdemo  
> plugin, and I
> think that the problem won't only concern the Median call. For  
> instance I
> did the same with IJ.run("Threshold"), but the problem is I can't  
> use the
> 'reset' button after I called this Threshold window (this time, the  
> image
> was not locked...).
>
> So, my question is : did I choose the good plugin to work on  
> (namely IPdemo)
> ? Or should I change the structure of my plugin ?
>
> Thanks for your attention,
> Regards,
>
> Ghislain Bugnicourt - PhD
> Institut Néel - CNRS - France
>
> --
> View this message in context: http://n2.nabble.com/IPDemo-Plugin--- 
> calling-%27IJ.run%28..%29%27---Image-is-locked-tp1311333p1311333.html
> Sent from the ImageJ mailing list archive at Nabble.com.