Skip to content

Instantly share code, notes, and snippets.

@imagejan
Created June 25, 2018 20:14
Show Gist options
  • Save imagejan/8bdb771ba653571cc07438c8e24dba79 to your computer and use it in GitHub Desktop.
Save imagejan/8bdb771ba653571cc07438c8e24dba79 to your computer and use it in GitHub Desktop.
Get the mode of an image histogram in ImageJ (using ImageJ Ops and ImgLib2)
#@ Img input
#@ OpService ops
import net.imglib2.algorithm.stats.Max
histogram = ops.run("histogram", input)
cursor = Max.findMax(histogram)
value = input.firstElement().copy()
histogram.getCenterValue(cursor.getLongPosition(0), value)
println "Mode value: $value"
println "Mode count: ${cursor.get()}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment