Search in sources :

Example 1 with GaussianFilter

use of gdsc.smlm.filters.GaussianFilter in project GDSC-SMLM by aherbert.

the class CreateData method updateArea.

private void updateArea(int[] mask, int w, int h) {
    // Note: The apparent area will be bigger due to the PSF width blurring the edges.
    // Assume the entire max intensity mask is in focus and the PSF is Gaussian in the focal plane.
    // Blur the mask
    float[] pixels = new float[mask.length];
    for (int i = 0; i < pixels.length; i++) pixels[i] = mask[i];
    GaussianFilter blur = new GaussianFilter();
    final double scaleX = (double) settings.size / w;
    final double scaleY = (double) settings.size / h;
    // Allow extra?
    double extra = 1;
    double sd = getPsfSD() * extra;
    blur.convolve(pixels, w, h, sd / scaleX, sd / scaleY);
    // Count pixels in blurred mask. Ignore those that are very faint (at the edge of the region)
    int c = 0;
    //		// By fraction of max value
    //		float limit = 0.1f;
    //		//float min = (float) (Maths.max(pixels) * limit);
    //		float min = limit;
    //		for (float f : pixels)
    //			if (f > min)
    //				c++;
    //		// Rank in order and get fraction of sum
    //		Arrays.sort(pixels);
    //		double sum = 0;
    //		double stop = Maths.sum(pixels) * 0.95;
    //		float after = Maths.max(pixels) + 1;
    //		for (float f : pixels)
    //		{
    //			sum += f;
    //			if (sum > stop)
    //			{
    //				break;
    //				//after = f;
    //				//stop = Float.POSITIVE_INFINITY;
    //			}
    //			if (f > after)
    //				break;
    //			c++;
    //		}
    // Threshold to a mask
    FloatProcessor fp = new FloatProcessor(w, h, pixels);
    ShortProcessor sp = (ShortProcessor) fp.convertToShort(true);
    final int t = AutoThreshold.getThreshold(AutoThreshold.Method.OTSU, sp.getHistogram());
    //Utils.display("Blurred", fp);
    for (int i = 0; i < mask.length; i++) if (sp.get(i) >= t)
        c++;
    // Convert 
    final double scale = ((double) c) / mask.length;
    //System.out.printf("Scale = %f\n", scale);
    areaInUm = scale * settings.size * settings.pixelPitch * settings.size * settings.pixelPitch / 1e6;
}
Also used : GaussianFilter(gdsc.smlm.filters.GaussianFilter) FloatProcessor(ij.process.FloatProcessor) ShortProcessor(ij.process.ShortProcessor)

Aggregations

GaussianFilter (gdsc.smlm.filters.GaussianFilter)1 FloatProcessor (ij.process.FloatProcessor)1 ShortProcessor (ij.process.ShortProcessor)1