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

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

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

Ghislain Bugnicourt
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
Reply | Threaded
Open this post in threaded view
|

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

Michael Schmid
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.
Reply | Threaded
Open this post in threaded view
|

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

Ghislain Bugnicourt
Hi, and thanks for your response Michael.
I should have understood that myself, anyway you made me save time...
I inserted "imp.unlock()" to be able to use IJ.run(..). It works.
Now, I am facing the other problem I mentioned in the first post : after a Thresholding and other actions, I would like to be able to reload the image completely, which is not the same as 'resetting' (that is to say just a 'undo').
I didn't find such a 'simple' function anywhere : should I write it myself ( for the moment I don't know how to do) ? For myself at least, it would be useful to have a 'reload current image without saving' tool in ImageJ's 'file' menu (just a suggestion :) ).

Ghislain Bugnicourt - PhD
Institut Néel - CNRS - France


Michael Schmid-3 wrote
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
Reply | Threaded
Open this post in threaded view
|

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

Michael Schmid
Hi Ghislain,

what about File>Revert?
Or do you need something else?

Michael

   http://en.wikipedia.org/wiki/RTFM  :-)

________________________________________________________________

On 9 Oct 2008, at 13:23, Ghislain Bugnicourt wrote:

> Hi, and thanks for your response Michael.
> I should have understood that myself, anyway you made me save time...
> I inserted "imp.unlock()" to be able to use IJ.run(..). It works.
> Now, I am facing the other problem I mentioned in the first post :  
> after a
> Thresholding and other actions, I would like to be able to reload  
> the image
> completely, which is not the same as 'resetting' (that is to say  
> just a
> 'undo').
> I didn't find such a 'simple' function anywhere : should I write it  
> myself (
> for the moment I don't know how to do) ? For myself at least, it  
> would be
> useful to have a 'reload current image without saving' tool in  
> ImageJ's
> 'file' menu (just a suggestion :) ).
>
> Ghislain Bugnicourt - PhD
> Institut Néel - CNRS - France
>
>
>
> Michael Schmid-3 wrote:
>>
>> 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
>>
>
> --
> View this message in context: http://n2.nabble.com/IPDemo-Plugin--- 
> calling-%27IJ.run%28..%29%27---Image-is-locked-tp1311333p1311733.html
> Sent from the ImageJ mailing list archive at Nabble.com.
Reply | Threaded
Open this post in threaded view
|

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

Ghislain Bugnicourt
That's what I was looking for.
I'm really sorry about asking such a stupid question. At least I learned one word today : revert.

<quote author="Michael Schmid-3">
Hi Ghislain,

what about File>Revert?
Or do you need something else?

Michael

   http://en.wikipedia.org/wiki/RTFM  :-)