Skip to content

Instantly share code, notes, and snippets.

@bnorthan
Created January 29, 2018 17:04
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 bnorthan/d57f2319b309389279bf40e63edb8026 to your computer and use it in GitHub Desktop.
Save bnorthan/d57f2319b309389279bf40e63edb8026 to your computer and use it in GitHub Desktop.
Saturation detection command modified to also return Huang threshold
package com.tnia.commands;
import net.imagej.ImgPlus;
import net.imagej.ops.OpService;
import net.imagej.ops.special.computer.BinaryComputerOp;
import net.imglib2.IterableInterval;
import net.imglib2.RandomAccessibleInterval;
import net.imglib2.histogram.Histogram1d;
import net.imglib2.realtransform.AffineTransform2D;
import net.imglib2.type.NativeType;
import net.imglib2.type.numeric.RealType;
import net.imglib2.type.numeric.integer.LongType;
import net.imglib2.type.numeric.real.FloatType;
import org.scijava.ItemIO;
import org.scijava.command.Command;
import org.scijava.log.LogService;
import org.scijava.plugin.Parameter;
import org.scijava.plugin.Plugin;
import org.scijava.ui.UIService;
@Plugin(type = Command.class, headless = true, menuPath = "Plugins>Saturation Detection")
public class SaturationDetection<T extends RealType<T> & NativeType<T>> implements Command {
@Parameter
OpService ops;
@Parameter
LogService log;
@Parameter
UIService ui;
@Parameter
ImgPlus img;
@Parameter(type = ItemIO.INPUT)
Integer numBins = 4096;
@Parameter(type = ItemIO.OUTPUT)
Double max;
@Parameter(type = ItemIO.OUTPUT)
Long lastBinCount;
@Parameter(type = ItemIO.OUTPUT)
Long huangThreshold;
BinaryComputerOp<RandomAccessibleInterval<FloatType>, AffineTransform2D, IterableInterval<FloatType>> transformOp = null;
public void run() {
max = ops.stats().max(img).getRealDouble();
Histogram1d<T> hist = (Histogram1d) ops.image().histogram(img, numBins);
huangThreshold = (long) ops.threshold().huang(hist).getRealFloat();
for (LongType t : hist) {
System.out.println(t);
}
// max=hist.max();
lastBinCount = hist.frequency(numBins - 1);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment