WaitForUser() not working

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

WaitForUser() not working

guillaumelobet
I am trying to use the WaitForUserDialog inside a plugin, but it freeze when used. The plugin does the following:

- display a GUI with the options for the analysis (path for the images, ...). The analysis is triggered by a actionPerformed even in the GUI.
- get a list of images and loop over them for the analysis
- if required by the user, the analysis (ROI selection) could be corrected for every image:
    - open the image
    - display the ROI
    - correct the ROI
   - close the image

So, what I need is, inside the analysis loop, to open the image, display the ROI, wait for the user to change/validate it and continue with the next image.

I tried this:

if(manualCorrection){
	ImagePlus ip = currentImage.duplicate();
	ip.show();
	ip.setRoi(new PolygonRoi(roiA[index].getConvexHull(), Roi.POLYGON));
	new WaitForUserDialog("Correct the ROI").show();			
	ip.hide(); ip.close(); ip.flush();
}

But all I see is the frame of the image (the image is not displayed) and the frame of the WaitForUserDialog, but the not t he message. When I click "OK", nothing happens...

Following this postI tried this:
 
if(manualCorrection){
	ImagePlus ip = currentImage.duplicate();
	ip.show();
	ip.setRoi(new PolygonRoi(roiA[index].getConvexHull(), Roi.POLYGON));
	Thread waitDialog = new Thread(new Runnable() {
			public void run() {		 			
		new WaitForUserDialog("Correct the ROI").show();
		}
	});
	waitDialog.start();			
	ip.hide(); ip.close(); ip.flush();
}

But it did not work either. ImageJ does not wait for the user to click OK and the images and messages are only displayed when the loop is finished...

Any ideas?


Reply | Threaded
Open this post in threaded view
|

Re: WaitForUser() not working

Majurski, Michael Paul (Fed)
My first instinct is that your WaitForUserDialog is being run in the Java EDT (Event Dispatch Thread), which handles all user input. Ff that thread hangs there will be no interactivity with the program until that dialog is closed and the EDT can resume.

I would try wrapping your plugin up into its own thread and then launching that thread from run method of your plugin that ImageJ calls.
The class you have implementing Plugin would simply create a new Thread and launch it using thread.start(). That way your WaitForUserDialog can stop the analysis loop (running in its own thread) without bringing the EDT to a halt.

Creating a new thread is fairly simple:
import java.lang.Runnable;
import java.lang.Thread;

...

newThread = Thread(new Runnable() {
    @Override
    public void run() {
        put your program logic here, including asking user for input
    }
});
newThread.start()

However, working with multiple execution threads one needs to be careful about any state that is shared between threads. There has been a lot written about concurrent programming if that topic interests you.


Regards,
Michael Majurski



-----Original Message-----
From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of guillaumelobet
Sent: Monday, August 25, 2014 10:56 AM
To: [hidden email]
Subject: WaitForUser() not working

I am trying to use the WaitForUserDialog inside a plugin, but it freeze when used. The plugin does the following:

- display a GUI with the options for the analysis (path for the images, ...). The analysis is triggered by a actionPerformed even in the GUI.
- get a list of images and loop over them for the analysis
- if required by the user, the analysis (ROI selection) could be corrected for every image:
    - open the image
    - display the ROI
    - correct the ROI
   - close the image

So, what I need is, inside the analysis loop, to open the image, display the ROI, wait for the user to change/validate it and continue with the next image.

I tried this:



But all I see is the frame of the image (the image is not displayed) and the frame of the WaitForUserDialog, but the not t he message. When I click "OK", nothing happens...

Following  this post
<http://imagej.1557.x6.nabble.com/Wait-for-user-NonBlockingGenericDialog-td5005270.html>
I tried this:
 


But it did not work either. ImageJ does not wait for the user to click OK
and the images and messages are only displayed when the loop is finished...

Any ideas?






--
View this message in context: http://imagej.1557.x6.nabble.com/WaitForUser-not-working-tp5009331.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
Reply | Threaded
Open this post in threaded view
|

Re: reverse-engineering a color image diagram

Frederic V. Hessman
I’d like to take a color diagram with a given color bar showing the connection between displayed color and actual value and produce a final real (32 bit) image with the original values (well, as good as it gets).

I tried a quick-n-dirty PluginFilter which reads the RGB values off a ROI, lets me input the extremum orignal values represented by the bar, stores the results in R,G,B, and value arrays, and then tries to convert each color value (r,g,b) in the image to an estimated value v by minimizing the color distance

        (r-R[i])^2+(g-G[i])^2+(b-B[i])^2

but the result is less than spectacular.  Obviously, this sRGB Euclidean distance is not capturing the color nuances well enough.  Should probably use CIE L*a*b….

Surely there’s a plugin out there which does this….

Thanks!

Rick

------------------------------------------------------------------------------------------------
Dr. Frederic V. Hessman     [hidden email]
Institut für Astrophysik          Tel.  +49-551-39-5052
Friedrich-Hund-Platz 1         Fax +49-551-39-5043
37077 Goettingen                 Room F04-133
http://www.Astro.physik.Uni-Goettingen.de/~hessman
-------------------------------------------------------------------------------------------------
MONET: a MOnitoring NEtwork of Telescopes
http://monet.Uni-Goettingen.de
-------------------------------------------------------------------------------------------------
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: WaitForUser() not working

Philippe Mailly
In reply to this post by guillaumelobet
Hi Guillaume,

I had the same freezing problem if you use Swing for GUI instead of
ImageJ GUI.

Philippe

Le 25/08/2014 16:56, guillaumelobet a écrit :

> I am trying to use the WaitForUserDialog inside a plugin, but it freeze when
> used. The plugin does the following:
>
> - display a GUI with the options for the analysis (path for the images,
> ...). The analysis is triggered by a actionPerformed even in the GUI.
> - get a list of images and loop over them for the analysis
> - if required by the user, the analysis (ROI selection) could be corrected
> for every image:
>      - open the image
>      - display the ROI
>      - correct the ROI
>     - close the image
>
> So, what I need is, inside the analysis loop, to open the image, display the
> ROI, wait for the user to change/validate it and continue with the next
> image.
>
> I tried this:
>
>
>
> But all I see is the frame of the image (the image is not displayed) and the
> frame of the WaitForUserDialog, but the not t he message. When I click "OK",
> nothing happens...
>
> Following  this post
> <http://imagej.1557.x6.nabble.com/Wait-for-user-NonBlockingGenericDialog-td5005270.html>
> I tried this:
>  
>
>
> But it did not work either. ImageJ does not wait for the user to click OK
> and the images and messages are only displayed when the loop is finished...
>
> Any ideas?
>
>
>
>
>
>
> --
> View this message in context: http://imagej.1557.x6.nabble.com/WaitForUser-not-working-tp5009331.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
Reply | Threaded
Open this post in threaded view
|

Re: WaitForUser() not working

guillaumelobet
In reply to this post by Majurski, Michael Paul (Fed)
Dear Michael,

Thanks, it works like a charm now. I put everything into the thread, and it run as it should.

Best,

Guillaume