> Dear All,
>
>
> I have encountered some strange, inconsistent behaviour using the
> setThreshold command in a macro.
>
> I have included the macro code below. The macro is used to apply a
> local thresholding method to a 16-bit image. There is some initial
> filtering of the image before converting the image to an 8-bit image
> in order to apply the Bernsen local threshold method. The thresholded
> 8-bit image is then used to create a selection that is restored to the
> original image. The area outside of the selection is set to zero and
> the threshold is set to include all values in the selected area. The
> reason for this is that I want to use the Find Maxima function to
> create segmented particles of the areas that are within the selection
> by using the 'Above lower threshold' option (unfortunately there is no
> option to restrict the creation of segmented particles to a selection).
>
> Now, here is the strange thing, for most images the code works fine,
> but occasionally the last setThreshold command doesn't appear to be
> executed correctly and the whole image is selected. However, when it
> does select the whole image and I then manually select the Adjust ->
> Threshold command, the dialog shows the correct lower threshold and
> the image is updated to correctly reflect the threshold settings. So,
> I thought that it may be an issue with the display not being refreshed
> quickly enough, and including a
> wait(1000) before the setThreshold command indeed appears to solve the
> issue at some occasions, but not always.
>
> Unfortunately, even after lots of testing for a few days, I can't come
> up with a reliable way to reproduce the error consistently - the same
> image might process fine at one run (and once it has done it okay, it
> seems to be okay if the code is run repeatedly), but closing and
> re-loading the same image might result in a different result. It also
> doesn't seem to be strictly image size related (my starting images are
> about 2000 x 2000
> pixels) as sometimes cropping a larger image can solve the problem,
> but at other occasions the problem persists with a smaller image.
>
> Just for completeness, I am currently using the Fiji-ImageJ 1.51s
> version with Java 1.8.0_66 (64 bit).
>
>
> Does anybody have an idea what might be going on and how this can be
> resolved?
>
> Thanks for your help,
>
> Volko
>
>
>
>
> curImage=getTitle();
> run("Duplicate...","title=Original");
> run("Select None");
> getStatistics(area, mean, min, max, std, histogram);
> print("Original:",area,min,max);
>
> run("Duplicate...","title=Soma");
> run("Median...", "radius=10");
>
> getStatistics(area, mean, min, max, std, histogram);
> print("Filtered:",area,min,max);
>
> setMinAndMax(min,max);
> run("8-bit");
> run("Auto Local Threshold", "method=Bernsen radius=25 parameter_1=0
> parameter_2=0 white"); run("Create Selection");
>
> selectWindow("Original");
> run("Restore Selection");
> run("Clear Outside");
>
> getStatistics(area, mean, min, max, std, histogram);
> getMinAndMax(minD,maxD); //wait(1000); setThreshold(min,maxD);
> getThreshold(lower,upper); print(lower,upper);
>
>
>
> --
> ImageJ mailing list:
http://imagej.nih.gov/ij/list.html