Search in sources :

Example 6 with FloatProcessor

use of ij.process.FloatProcessor in project GDSC-SMLM by aherbert.

the class IJImagePeakResultsTest method noInterpolateUpInXAtImageEdge.

@Test
public void noInterpolateUpInXAtImageEdge() {
    IJImagePeakResults r = new IJImagePeakResults(title, bounds, 1);
    r.setDisplayFlags(IJImagePeakResults.DISPLAY_WEIGHTED);
    FloatProcessor fp = new FloatProcessor(bounds.width, bounds.height);
    begin(r);
    addValue(r, 2.5f, 1.5f, 2);
    fp.putPixelValue(2, 1, 2);
    r.end();
    float[] expecteds = getImage(fp);
    float[] actuals = getImage(r);
    Assert.assertArrayEquals(expecteds, actuals, 0);
}
Also used : FloatProcessor(ij.process.FloatProcessor) Test(org.junit.Test)

Example 7 with FloatProcessor

use of ij.process.FloatProcessor in project GDSC-SMLM by aherbert.

the class IJImagePeakResultsTest method noInterpolateUpInYAtImageEdge.

@Test
public void noInterpolateUpInYAtImageEdge() {
    IJImagePeakResults r = new IJImagePeakResults(title, bounds, 1);
    r.setDisplayFlags(IJImagePeakResults.DISPLAY_WEIGHTED);
    FloatProcessor fp = new FloatProcessor(bounds.width, bounds.height);
    begin(r);
    addValue(r, 1.5f, 2.5f, 2);
    fp.putPixelValue(1, 2, 2);
    r.end();
    float[] expecteds = getImage(fp);
    float[] actuals = getImage(r);
    Assert.assertArrayEquals(expecteds, actuals, 0);
}
Also used : FloatProcessor(ij.process.FloatProcessor) Test(org.junit.Test)

Example 8 with FloatProcessor

use of ij.process.FloatProcessor in project GDSC-SMLM by aherbert.

the class IJImagePeakResultsTest method canInterpolateDownInXYAtPixelEdge.

@Test
public void canInterpolateDownInXYAtPixelEdge() {
    IJImagePeakResults r = new IJImagePeakResults(title, bounds, 1);
    r.setDisplayFlags(IJImagePeakResults.DISPLAY_WEIGHTED);
    FloatProcessor fp = new FloatProcessor(bounds.width, bounds.height);
    begin(r);
    addValue(r, 1f, 1f, 4);
    fp.putPixelValue(0, 0, 1f);
    fp.putPixelValue(0, 1, 1f);
    fp.putPixelValue(1, 0, 1f);
    fp.putPixelValue(1, 1, 1f);
    r.end();
    float[] expecteds = getImage(fp);
    float[] actuals = getImage(r);
    Assert.assertArrayEquals(expecteds, actuals, 0);
}
Also used : FloatProcessor(ij.process.FloatProcessor) Test(org.junit.Test)

Example 9 with FloatProcessor

use of ij.process.FloatProcessor in project GDSC-SMLM by aherbert.

the class SpotFinderPreview method run.

/*
	 * (non-Javadoc)
	 * 
	 * @see ij.plugin.filter.PlugInFilter#run(ij.process.ImageProcessor)
	 */
public void run(ImageProcessor ip) {
    Rectangle bounds = ip.getRoi();
    MaximaSpotFilter filter = config.createSpotFilter(true);
    // Crop to the ROI
    FloatProcessor fp = ip.crop().toFloat(0, null);
    float[] data = (float[]) fp.getPixels();
    int width = fp.getWidth();
    int height = fp.getHeight();
    Spot[] spots = filter.rank(data, width, height);
    data = filter.getPreprocessedData();
    fp = new FloatProcessor(width, height, data);
    ip = ip.duplicate();
    ip.insert(fp, bounds.x, bounds.y);
    //ip.resetMinAndMax();
    ip.setMinAndMax(fp.getMin(), fp.getMax());
    Overlay o = new Overlay();
    o.add(new ImageRoi(0, 0, ip));
    if (label != null) {
        // Get results for frame
        Coordinate[] actual = ResultsMatchCalculator.getCoordinates(actualCoordinates, imp.getCurrentSlice());
        Coordinate[] predicted = new Coordinate[spots.length];
        for (int i = 0; i < spots.length; i++) {
            predicted[i] = new BasePoint(spots[i].x + bounds.x, spots[i].y + bounds.y);
        }
        // Q. Should this use partial scoring with multi-matches allowed.
        // If so then this needs to be refactored out of the BenchmarkSpotFilter class.
        // TODO - compute AUC and max jaccard and plot			
        // Compute matches
        List<PointPair> matches = new ArrayList<PointPair>(Math.min(actual.length, predicted.length));
        List<Coordinate> FP = new ArrayList<Coordinate>(predicted.length);
        MatchResult result = MatchCalculator.analyseResults2D(actual, predicted, distance * fitConfig.getInitialPeakStdDev0(), null, FP, null, matches);
        // Show scores
        setLabel(String.format("P=%s, R=%s, J=%s", Utils.rounded(result.getPrecision()), Utils.rounded(result.getRecall()), Utils.rounded(result.getJaccard())));
        // Create Rois for TP and FP
        if (showTP) {
            float[] x = new float[matches.size()];
            float[] y = new float[x.length];
            int n = 0;
            for (PointPair pair : matches) {
                BasePoint p = (BasePoint) pair.getPoint2();
                x[n] = p.getX() + 0.5f;
                y[n] = p.getY() + 0.5f;
                n++;
            }
            addRoi(0, o, x, y, n, Color.green);
        }
        if (showFP) {
            float[] x = new float[predicted.length - matches.size()];
            float[] y = new float[x.length];
            int n = 0;
            for (Coordinate c : FP) {
                BasePoint p = (BasePoint) c;
                x[n] = p.getX() + 0.5f;
                y[n] = p.getY() + 0.5f;
                n++;
            }
            addRoi(0, o, x, y, n, Color.red);
        }
    } else {
        float[] x = new float[spots.length];
        float[] y = new float[x.length];
        for (int i = 0; i < spots.length; i++) {
            x[i] = spots[i].x + bounds.x + 0.5f;
            y[i] = spots[i].y + bounds.y + 0.5f;
        }
        PointRoi roi = new PointRoi(x, y);
        // Add options to configure colour and labels
        o.add(roi);
    }
    imp.setOverlay(o);
}
Also used : FloatProcessor(ij.process.FloatProcessor) Spot(gdsc.smlm.filters.Spot) BasePoint(gdsc.core.match.BasePoint) Rectangle(java.awt.Rectangle) ArrayList(java.util.ArrayList) ImageRoi(ij.gui.ImageRoi) MatchResult(gdsc.core.match.MatchResult) BasePoint(gdsc.core.match.BasePoint) Coordinate(gdsc.core.match.Coordinate) MaximaSpotFilter(gdsc.smlm.filters.MaximaSpotFilter) PointPair(gdsc.core.match.PointPair) Overlay(ij.gui.Overlay) PointRoi(ij.gui.PointRoi)

Example 10 with FloatProcessor

use of ij.process.FloatProcessor 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

FloatProcessor (ij.process.FloatProcessor)49 Test (org.junit.Test)22 ImageProcessor (ij.process.ImageProcessor)11 Rectangle (java.awt.Rectangle)8 FHT2 (ij.process.FHT2)5 ImageStack (ij.ImageStack)4 Point (java.awt.Point)4 LinkedList (java.util.LinkedList)4 Future (java.util.concurrent.Future)4 ClusterPoint (gdsc.core.clustering.ClusterPoint)3 IJImagePeakResults (gdsc.smlm.ij.results.IJImagePeakResults)3 ImagePlus (ij.ImagePlus)3 RandomGenerator (org.apache.commons.math3.random.RandomGenerator)3 Well19937c (org.apache.commons.math3.random.Well19937c)3 BasePoint (gdsc.core.match.BasePoint)2 MaximaSpotFilter (gdsc.smlm.filters.MaximaSpotFilter)2 IJTablePeakResults (gdsc.smlm.ij.results.IJTablePeakResults)2 PeakResult (gdsc.smlm.results.PeakResult)2 ColorProcessor (ij.process.ColorProcessor)2 ShortProcessor (ij.process.ShortProcessor)2