Skip to content

Instantly share code, notes, and snippets.

@lacan
Created July 6, 2020 09:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lacan/92f07763cb5cd747e319e99f3e984fd8 to your computer and use it in GitHub Desktop.
Save lacan/92f07763cb5cd747e319e99f3e984fd8 to your computer and use it in GitHub Desktop.
Fiji Spot Counting Example
// Script for computing distances from modern spot counter ROIs in Fiji
// Created by Olivier Burri, EPFL BioImaging & Optics Platform, EPFL - BIOP
// ( for @Gabriel on the image.sc forum
// https://forum.image.sc/t/distance-based-colocalization-of-multi-point-tool-points-in-fiji-imagej/39855?u=oburri
// Due to the simple nature of this code, no license applies
#@ImagePlus imp
#@Double distance (label="Distance [um]", value=20)
// Get ROIs
def points = imp.getRoi()
// The Counter IDs are located in the getCounters() function
def ids = points.getCounters() as List
// Separate points into counters for counter 0 and counter 1
points_A = [points.getContainedPoints(), ids].transpose().findAll{ p,i -> i == 0 }.collect{ it[0] }
points_B = [points.getContainedPoints(), ids].transpose().findAll{ p,i -> i == 1 }.collect{ it[0] }
// Find points_B close to Points_A
def B_close_A = points_A.collect { a -> return points_B.findAll { b -> b.distance(a) * imp.getCalibration().pixelWidth < distance } }
// Draw something pretty, make an overlay
def ov = new Overlay()
[points_A, B_close_A].transpose().each{ a, b ->
println(b)
// If there are spots
if( !b.isEmpty() ) {
// Make a line connecting the current Spot A to all spots B
b.each{ bb ->
def line = new Line( a.getX(), a.getY(), bb.getX(), bb.getY() )
ov.add(line)
}
}
}
// Place the overlay on the image
imp.setOverlay(ov)
// Finally Count the number of spots
def rt =ResultsTable.getResultsTable()
B_close_A.eachWithIndex{ p, i ->
rt.incrementCounter()
rt.addValue("Label", imp.getTitle() )
rt.addValue("Spot ID", i )
rt.addValue("Neighbors [<"+distance+" um]", p.size() )
}
rt.show()
// Necessaty Imports
import ij.gui.Overlay
import ij.gui.Line
import ij.measure.ResultsTable
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment