Search in sources :

Example 1 with DataRange

use of net.imagej.autoscale.DataRange in project imagej-plugins-commands by imagej.

the class Binarize method run.

// -- Command methods --
@Override
@SuppressWarnings("unchecked")
public void run() {
    long[] dims = Intervals.dimensionsAsLongArray(inputData);
    String err = checkInputMask(inputMask, dims);
    if (err != null) {
        cancel(err);
        return;
    }
    CalibratedAxis[] axes = new CalibratedAxis[dims.length];
    inputData.axes(axes);
    AxisType[] types = new AxisType[dims.length];
    for (int i = 0; i < dims.length; i++) {
        types[i] = axes[i].type();
    }
    Dataset mask = inputMask != null ? inputMask : datasetSrv.create(new BitType(), dims, "Mask", types, isVirtual(inputData));
    mask.setAxes(axes);
    RandomAccess<BitType> maskAccessor = (RandomAccess<BitType>) mask.getImgPlus().randomAccess();
    RandomAccess<? extends RealType<?>> dataAccessor = inputData.getImgPlus().randomAccess();
    DataRange minMax = calcDataRange(inputData);
    Histogram1d<T> histogram = null;
    boolean testLess = maskPixels.equals(INSIDE);
    DoubleType val = new DoubleType();
    // Better performance? Especially for CellImgs?
    if (thresholdEachPlane && planeCount(inputData) > 1) {
        // threshold each plane separately
        long[] planeSpace = planeSpace(inputData);
        PointSetIterator pIter = new HyperVolumePointSet(planeSpace).iterator();
        while (pIter.hasNext()) {
            long[] planePos = pIter.next();
            histogram = buildHistogram(inputData, planePos, minMax, histogram);
            double cutoffVal = cutoff(histogram, method, testLess, val);
            PointSet planeData = planeData(inputData, planePos);
            PointSetIterator iter = planeData.iterator();
            while (iter.hasNext()) {
                updateMask(iter.next(), testLess, cutoffVal, dataAccessor, maskAccessor);
            }
        }
    } else {
        // threshold entire dataset once
        histogram = buildHistogram(inputData, null, minMax, null);
        double cutoffVal = cutoff(histogram, method, testLess, val);
        PointSet fullData = fullData(dims);
        PointSetIterator iter = fullData.iterator();
        while (iter.hasNext()) {
            updateMask(iter.next(), testLess, cutoffVal, dataAccessor, maskAccessor);
        }
    }
    assignColorTables(mask);
    if (changeInput) {
        // TODO - should inputData be ItemIO.BOTH????
        inputData.setImgPlus(mask.getImgPlus());
    } else
        outputMask = mask;
}
Also used : Dataset(net.imagej.Dataset) RandomAccess(net.imglib2.RandomAccess) PointSet(net.imglib2.ops.pointset.PointSet) HyperVolumePointSet(net.imglib2.ops.pointset.HyperVolumePointSet) PointSetIterator(net.imglib2.ops.pointset.PointSetIterator) BitType(net.imglib2.type.logic.BitType) DoubleType(net.imglib2.type.numeric.real.DoubleType) AxisType(net.imagej.axis.AxisType) DataRange(net.imagej.autoscale.DataRange) HyperVolumePointSet(net.imglib2.ops.pointset.HyperVolumePointSet) CalibratedAxis(net.imagej.axis.CalibratedAxis)

Example 2 with DataRange

use of net.imagej.autoscale.DataRange in project vcell by virtualcell.

the class InFrameDisplayService method autoscale.

/**
 * Scales the brightness and contrast for better display.
 * Does not change the underlying pixel intensities.
 * @param datasetView
 */
private void autoscale(DatasetView datasetView) {
    DataRange range = autoscaleService.getDefaultIntervalRange(datasetView.getData());
    datasetView.setChannelRanges(range.getMin(), range.getMax());
    datasetView.getProjector().map();
    datasetView.update();
}
Also used : DataRange(net.imagej.autoscale.DataRange)

Example 3 with DataRange

use of net.imagej.autoscale.DataRange in project imagej-plugins-commands by imagej.

the class BrightnessContrast method computeDataMinMax.

// -- Helper methods --
// TODO we have a couple refresh problems
// 1) right now if you bounce between two displays with this dialog open the
// dialog values (like min, max, and hist don't update)
// 2) even if you can fix 1) the fact that we don't change to a new
// HistogramBundle but rather tweak the existing one might cause refresh()
// probs also. Because the update() code checks if the T's are the same.
// This means there is a implicit requirement for object reference equality
// rather than using something like equals(). Or a isChanged() interface
// (since in this case equals() would not work either).
private void computeDataMinMax(final RandomAccessibleInterval<? extends RealType<?>> img) {
    // FIXME: Reconcile this with DefaultDatasetView.autoscale(int). There is
    // no reason to hardcode the usage of ComputeMinMax twice. Rather, there
    // should be a single entry point for obtain the channel min/maxes from
    // the metadata, and if they aren't there, then compute them. Probably
    // Dataset (not DatasetView) is a good place for it, because it is metadata
    // independent of the visualization settings.
    DataRange range = autoscaleService.getDefaultRandomAccessRange(img);
    dataMin = range.getMin();
    dataMax = range.getMax();
    final MutableModuleItem<Double> minItem = getInfo().getMutableInput("min", Double.class);
    minItem.setSoftMinimum(dataMin);
    minItem.setSoftMaximum(dataMax);
    final MutableModuleItem<Double> maxItem = getInfo().getMutableInput("max", Double.class);
    maxItem.setSoftMinimum(dataMin);
    maxItem.setSoftMaximum(dataMax);
    // System.out.println("IN HERE!!!!!!");
    // System.out.println(" dataMin = " + dataMin);
    // System.out.println(" dataMax = " + dataMax);
    @SuppressWarnings({ "unchecked", "rawtypes" }) Iterable<T> iterable = Views.iterable((RandomAccessibleInterval<T>) (RandomAccessibleInterval) img);
    BinMapper1d<T> mapper = new Real1dBinMapper<T>(dataMin, dataMax, 256, false);
    Histogram1d<T> histogram = new Histogram1d<T>(iterable, mapper);
    if (bundle == null) {
        bundle = new HistogramBundle(histogram);
    } else {
        bundle.setHistogram(0, histogram);
    }
    bundle.setDataMinMax(dataMin, dataMax);
    // bundle.setLineSlopeIntercept(1, 0);
    log().debug("computeDataMinMax: dataMin=" + dataMin + ", dataMax=" + dataMax);
// force a widget refresh to see new Hist (and also fill min and max fields)
// NOPE. HistBundle is unchanged. Only internals are. So no
// refresh called. Note that I changed InteractiveCommand::update() to
// always setValue() and still this did not work. !!!! Huh?
// update(getInfo().getMutableInput("bundle", HistogramBundle.class),
// bundle);
// NOPE
// getInfo().getInput("bundle", HistogramBundle.class).setValue(this,
// bundle);
// NOPE
// getInfo().setVisible(false);
// getInfo().setVisible(true);
// NOPE
// getInfo().getMutableInput("bundle",HistogramBundle.class).initialize(this);
// NOPE
// getInfo().getMutableInput("bundle",HistogramBundle.class).callback(this);
}
Also used : Real1dBinMapper(net.imglib2.histogram.Real1dBinMapper) HistogramBundle(net.imagej.widget.HistogramBundle) RandomAccessibleInterval(net.imglib2.RandomAccessibleInterval) Histogram1d(net.imglib2.histogram.Histogram1d) DataRange(net.imagej.autoscale.DataRange)

Example 4 with DataRange

use of net.imagej.autoscale.DataRange in project imagej-plugins-commands by imagej.

the class SaltAndPepper method setupWorkingData.

private void setupWorkingData() {
    selection = overlayService.getSelectionBounds(display);
    inputImage = input.getImgPlus();
    position = new long[inputImage.numDimensions()];
    accessor = inputImage.randomAccess();
    if (autoCalcMinMax) {
        DataRange range = autoscaleService.getDefaultIntervalRange(inputImage);
        pepperValue = range.getMin();
        saltValue = range.getMax();
        RealType<?> t = inputImage.firstElement();
        @SuppressWarnings({ "unchecked", "rawtypes" }) final ComputeMinMax<? extends RealType<?>> cmm = new ComputeMinMax(inputImage, t.createVariable(), t.createVariable());
        cmm.process();
        pepperValue = cmm.getMin().getRealDouble();
        saltValue = cmm.getMax().getRealDouble();
    }
}
Also used : DataRange(net.imagej.autoscale.DataRange) ComputeMinMax(net.imglib2.algorithm.stats.ComputeMinMax)

Aggregations

DataRange (net.imagej.autoscale.DataRange)4 Dataset (net.imagej.Dataset)1 AxisType (net.imagej.axis.AxisType)1 CalibratedAxis (net.imagej.axis.CalibratedAxis)1 HistogramBundle (net.imagej.widget.HistogramBundle)1 RandomAccess (net.imglib2.RandomAccess)1 RandomAccessibleInterval (net.imglib2.RandomAccessibleInterval)1 ComputeMinMax (net.imglib2.algorithm.stats.ComputeMinMax)1 Histogram1d (net.imglib2.histogram.Histogram1d)1 Real1dBinMapper (net.imglib2.histogram.Real1dBinMapper)1 HyperVolumePointSet (net.imglib2.ops.pointset.HyperVolumePointSet)1 PointSet (net.imglib2.ops.pointset.PointSet)1 PointSetIterator (net.imglib2.ops.pointset.PointSetIterator)1 BitType (net.imglib2.type.logic.BitType)1 DoubleType (net.imglib2.type.numeric.real.DoubleType)1