fixed pixel thresholding

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

fixed pixel thresholding

smh73
Hello,

Does anyone know of a plugin or method for thresholding based on a fixed
number of pixels? e.g. the n brightest pixels within an ROI in each frame of a
stack.

Thanks
m
Reply | Threaded
Open this post in threaded view
|

Re: fixed pixel thresholding

BenTupper
Hi,

On Feb 1, 2010, at 6:38 PM, miko wrote:

> Hello,
>
> Does anyone know of a plugin or method for thresholding based on a  
> fixed
> number of pixels? e.g. the n brightest pixels within an ROI in each  
> frame of a
> stack.


The macro below shows how you might select a threshold on the  
cumulative histogram.  It selects the threshold not on "n brightest  
pixels" but a fraction of the pixels.   I think you could adapt it  
easily enough.  Note that the example is for 8 bit - you'll need to  
tweak it for other depths.

Cheers,
Ben






//BEGIN
run("AuPbSn 40 (56K)");
nBins = 256;
getHistogram(values, counts, nBins);

nThresh = 0.75;  // <----- threshold fraction

cum = newArray(nBins);
cum[0] = counts[0];
tot = counts[0];
for (i=1; i<nBins;i++){
        tot += counts[i];
        cum[i] += tot;
}


thresh = cum[0];
i = 0;
while (thresh/tot < nThresh) {
        print(i + " = " + thresh/tot  + " threshold fraction");
        i++;
        thresh = cum[i];
}

print("Threshold=" + i);
setThreshold(0, i);

//END