Search in sources :

Example 1 with GaussianFilter

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

the class CreateData method updateArea.

private void updateArea(int[] mask, int width, int height) {
    // 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
    final float[] pixels = new float[mask.length];
    for (int i = 0; i < pixels.length; i++) {
        pixels[i] = mask[i];
    }
    final GaussianFilter blur = new GaussianFilter();
    final double scaleX = (double) settings.getSize() / width;
    final double scaleY = (double) settings.getSize() / height;
    // Allow extra?
    final double extra = 1;
    final double sd = getPsfSd() * extra;
    blur.convolve(pixels, width, height, sd / scaleX, sd / scaleY);
    // Count pixels in blurred mask. Ignore those that are very faint (at the edge of the region)
    int count = 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
    final FloatProcessor fp = new FloatProcessor(width, height, pixels);
    final 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) {
            count++;
        }
    }
    // Convert
    final double scale = ((double) count) / mask.length;
    // System.out.printf("Scale = %f\n", scale);
    areaInUm = scale * settings.getSize() * settings.getPixelPitch() * settings.getSize() * settings.getPixelPitch() / 1e6;
}
Also used : GaussianFilter(uk.ac.sussex.gdsc.smlm.filters.GaussianFilter) FloatProcessor(ij.process.FloatProcessor) ReadHint(uk.ac.sussex.gdsc.smlm.results.ImageSource.ReadHint) ShortProcessor(ij.process.ShortProcessor)

Aggregations

FloatProcessor (ij.process.FloatProcessor)1 ShortProcessor (ij.process.ShortProcessor)1 GaussianFilter (uk.ac.sussex.gdsc.smlm.filters.GaussianFilter)1 ReadHint (uk.ac.sussex.gdsc.smlm.results.ImageSource.ReadHint)1