Macro for thresholding with measured mean

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

Macro for thresholding with measured mean

Mymy
Hi all, I am writing a macro where measurements are made after thresholding
using 2 times the mean of a specific ROI. Does anyone know what code I could
use where the mean gray value of an ROI (8-bit image) is measured and
sequentially is used for setting the threshold limit? Thanks in advance!



--
Sent from: http://imagej.1557.x6.nabble.com/

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

Re: Macro for thresholding with measured mean

Aryeh Weiss
Take a look at the Bar>Segmentation>Threshold From Background
you can get this by selecting the Bar update site in Fiji. You can then
look at the source, which is a few lines of macro code that get the
relevant statistics. You can modify the setThreshold line to set the
threshold to twice the mean.

For your convenience I pulled out from the Bar_.jar file.
/* Threshold_From_Background.ijm
  * IJ BAR: https://github.com/tferr/Scripts#scripts
  *
  * Sets the threshold as the ROI average plus a factor of its standard
deviation. To call it from
  * other scripts (see http://imagej.net/BAR for details):
  *
  *   tfbpath =
call("bar.Utils.getSegmentationDir")+"Threshold_From_Background.ijm";
  *   runMacro(tfbpath, 3);
  *
  * TF 2014.06
  */

if (selectionType==-1)
     exit("A background-defining ROI is\nrequired but none was found.");

factor = getArgument();
if (factor=="")
     factor = getNumber("Multiplier (Mean + ??*SDeviation):", 3);
getStatistics(area, mean, min, max, std);
setThreshold(mean+factor*std, pow(2, bitDepth));

--aryeh



On 17/07/2019 9:05, Mymy wrote:

> Hi all, I am writing a macro where measurements are made after thresholding
> using 2 times the mean of a specific ROI. Does anyone know what code I could
> use where the mean gray value of an ROI (8-bit image) is measured and
> sequentially is used for setting the threshold limit? Thanks in advance!
>
>
>
> --
> Sent from: http://imagej.1557.x6.nabble.com/
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

--
Aryeh Weiss
Faculty of Engineering
Bar Ilan University
Ramat Gan 52900 Israel

Ph:  972-3-5317638
FAX: 972-3-7384051

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

Re: Macro for thresholding with measured mean

Stoyan Pavlov
In reply to this post by Mymy
Try something like this:


image_title=getTitle();
selectWindow (image_title);
mean_value= getValue("Mean");
lower_threshold=2*mean_value;
selectWindow (image_title);
setThreshold(lower_threshold, 255);
---
If the "getValue" doesn't work you can try with the legacy option:

Run("Measure...");
getResult("Mean");

Best wishes!
Stoyan

On Wed, Jul 17, 2019, 09:19 Mymy <[hidden email]> wrote:

> Hi all, I am writing a macro where measurements are made after thresholding
> using 2 times the mean of a specific ROI. Does anyone know what code I
> could
> use where the mean gray value of an ROI (8-bit image) is measured and
> sequentially is used for setting the threshold limit? Thanks in advance!
>
>
>
> --
> Sent from: http://imagej.1557.x6.nabble.com/
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

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