How to get threshold values used by ThresholdAdjuster

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

How to get threshold values used by ThresholdAdjuster

Bob Loushin
I have a plugin which has the following workflow:

1) plugin starts, some initialization stuff happens.
2) plugin creates a ThresholdAdjuster, user fiddles with settings, hits "Apply", and image is thesholded. The ThresholdAdjuster runs in its own thread, so my plugin just waits for it to be done.
3) program measures stuff in the thresholded version of the image, records results.

In my case, the levels chosen for thresholding can affect the measurement, so I would like to record them with the results for traceability.

Is there a way to recover this information, either from the ThresholdAdjuster or from the image?

Thank you.

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

Re: How to get threshold values used by ThresholdAdjuster

Michael Doube-3
Hi Bob,

> In my case, the levels chosen for thresholding can affect the
> measurement, so I would like to record them with the results for
> traceability.
>
> Is there a way to recover this information, either from the
> ThresholdAdjuster or from the image?

ImageProcessor has two methods, getMaxThreshold() and getMinThreshold()
which will tell you the upper and lower threshold levels applied to the
image.

Michael

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

Re: How to get threshold values used by ThresholdAdjuster

Bob Loushin
Thank you, Michael, for pointing these methods out. But as far as I can tell, once the user hits "Apply" and the image is thresholded (converted from grayscale to binary using the threshold levels selected), the values those methods are returning are reset. They don't hold what levels used to create the image were, but whatever the current levels for the new image are.

Bob

----- Original Message -----
From: "Michael Doube" <[hidden email]>
To: [hidden email]
Cc: "Bob Loushin" <[hidden email]>
Sent: Wednesday, June 27, 2012 1:23:33 PM
Subject: Re: How to get threshold values used by ThresholdAdjuster

Hi Bob,

> In my case, the levels chosen for thresholding can affect the
> measurement, so I would like to record them with the results for
> traceability.
>
> Is there a way to recover this information, either from the
> ThresholdAdjuster or from the image?

ImageProcessor has two methods, getMaxThreshold() and getMinThreshold()
which will tell you the upper and lower threshold levels applied to the
image.

Michael



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

Re: How to get threshold values used by ThresholdAdjuster

Michael Doube-3
Hi Bob,

> once the user hits "Apply" and the image is thresholded
> (converted from grayscale to binary using the threshold levels
> selected), the values those methods are returning are reset.

Right. I know exactly what you mean. I've worked around this before by
having the user set the threshold and then instead of hitting 'Apply' in
the Threshold plugin, they hit 'OK' in a WaitForUser dialog. Then the
thresholds are read from the ImageProcessor.

Michael

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

Re: How to get threshold values used by ThresholdAdjuster

Bob Loushin
In reply to this post by Bob Loushin
Despite the fact that they are reset, I think I've found a work-around that gets me what I want. I'm afraid it might be a bit brittle, but it works in the few tests I've run. Basically, I created a lastMinThreshold variable, then constantly updated it with getMinThreshold() inside the idle loop I used to wait for the user to be done thresholding. And the same for a lastMaxThreshold. When the thread ends, the idle loop quits and the variables are no longer updated, so they end up recording the last threshold values set. I'm concerned there will be occasions when the timing is off and I end up with the wrong values--either the variables don't get updated between when they value is changed by the user and when the ThresholdAdjuster ends, or they get updated one last time after the ThresholdAdjuster ends but before the idle loop realizes it's done. I don't have much experience with threads, so I'm open to suggestions for a better way to keep these in sync. But for now, it's worked in the few tests I've run, so I'll use this and keep watching it to make sure it's reliable. Below is the code I'm using:

boolean done = false;
ThresholdAdjuster thresh = new ThresholdAdjuster();
ThreadGroup threadGroup = Thread.currentThread().getThreadGroup();
while (!done)
{
threshMinLevel = imp.getProcessor().getMinThreshold();
threshMaxLevel = imp.getProcessor().getMaxThreshold();
done = true;
Thread[] threads = new Thread[threadGroup.activeCount()];
threadGroup.enumerate(threads);
for (i=0; i<threads.length; i++)
if (threads[i].getName().equals("ThresholdAdjuster")) done = false;
}
thresh.close();


----- Original Message -----
From: "Bob Loushin" <[hidden email]>
To: [hidden email]
Sent: Wednesday, June 27, 2012 3:01:42 PM
Subject: Re: How to get threshold values used by ThresholdAdjuster

Thank you, Michael, for pointing these methods out. But as far as I can tell, once the user hits "Apply" and the image is thresholded (converted from grayscale to binary using the threshold levels selected), the values those methods are returning are reset. They don't hold what levels used to create the image were, but whatever the current levels for the new image are.

Bob

----- Original Message -----
From: "Michael Doube" <[hidden email]>
To: [hidden email]
Cc: "Bob Loushin" <[hidden email]>
Sent: Wednesday, June 27, 2012 1:23:33 PM
Subject: Re: How to get threshold values used by ThresholdAdjuster

Hi Bob,

> In my case, the levels chosen for thresholding can affect the
> measurement, so I would like to record them with the results for
> traceability.
>
> Is there a way to recover this information, either from the
> ThresholdAdjuster or from the image?

ImageProcessor has two methods, getMaxThreshold() and getMinThreshold()
which will tell you the upper and lower threshold levels applied to the
image.

Michael



--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html 

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html