use of net.imglib2.exception.IncompatibleTypeException in project imagej-ops by imagej.
the class Convolve method run.
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public void run() {
// TODO: get the dimension indices from the image dependent on the
// selected
// axes -> OR: just map the kernel dimension labels to the image
// dimension
// labels
final int[] axisIndices = new int[] { 0, 1 };
// number of indicies must be conform with the dimensionality of axes
if (axes.length != axisIndices.length) {
throw new IllegalArgumentException("The number of selected dimension doesn't conforms with the kernel size.");
}
if (asFloat) {
try {
out = (ImgPlus) in.factory().imgFactory(new FloatType()).create(in, new FloatType());
} catch (final IncompatibleTypeException e) {
throw new IllegalArgumentException(e);
}
} else {
out = (ImgPlus<O>) in.factory().create(in, in.firstElement().createVariable());
}
final Op op = ops.op(Ops.Filter.Convolve.class, out, in, kernel);
if (in.numDimensions() > kernel.numDimensions()) {
if (op instanceof UnaryComputerOp) {
// if the selected convolve op is a function and the kernel dimensions
// doesn't match the input image dimensions, than we can still convolve
// each slice individually
ops.run(Ops.Slice.class, out, in, op, axisIndices);
} else {
throw new IllegalArgumentException("The input image has more dimensions than the kernel!");
}
} else if (in.numDimensions() == kernel.numDimensions()) {
// no 'slicing' necessary
ops.run(op, out, in, kernel);
}
}
use of net.imglib2.exception.IncompatibleTypeException in project imagej-ops by imagej.
the class DefaultTubeness method compute.
@Override
public void compute(final RandomAccessibleInterval<T> input, final IterableInterval<DoubleType> tubeness) {
cancelReason = null;
final int numDimensions = input.numDimensions();
// Sigmas in pixel units.
final double[] sigmas = new double[numDimensions];
for (int d = 0; d < sigmas.length; d++) {
final double cal = d < calibration.length ? calibration[d] : 1;
sigmas[d] = sigma / cal;
}
/*
* Hessian.
*/
// Get a suitable image factory.
final long[] gradientDims = new long[numDimensions + 1];
final long[] hessianDims = new long[numDimensions + 1];
for (int d = 0; d < numDimensions; d++) {
hessianDims[d] = input.dimension(d);
gradientDims[d] = input.dimension(d);
}
hessianDims[numDimensions] = numDimensions * (numDimensions + 1) / 2;
gradientDims[numDimensions] = numDimensions;
final Dimensions hessianDimensions = FinalDimensions.wrap(hessianDims);
final FinalDimensions gradientDimensions = FinalDimensions.wrap(gradientDims);
final ImgFactory<DoubleType> factory = ops().create().imgFactory(hessianDimensions);
final Img<DoubleType> hessian = factory.create(hessianDimensions, new DoubleType());
final Img<DoubleType> gradient = factory.create(gradientDimensions, new DoubleType());
final Img<DoubleType> gaussian = factory.create(input, new DoubleType());
// Handle multithreading.
final int nThreads = Runtime.getRuntime().availableProcessors();
final ExecutorService es = threadService.getExecutorService();
try {
// Hessian calculation.
HessianMatrix.calculateMatrix(Views.extendBorder(input), gaussian, gradient, hessian, new OutOfBoundsBorderFactory<>(), nThreads, es, sigma);
statusService.showProgress(1, 3);
if (isCanceled())
return;
// Hessian eigenvalues.
final RandomAccessibleInterval<DoubleType> evs = TensorEigenValues.calculateEigenValuesSymmetric(hessian, TensorEigenValues.createAppropriateResultImg(hessian, factory, new DoubleType()), nThreads, es);
statusService.showProgress(2, 3);
if (isCanceled())
return;
final AbstractUnaryComputerOp<Iterable<DoubleType>, DoubleType> method;
switch(numDimensions) {
case 2:
method = new Tubeness2D(sigma);
break;
case 3:
method = new Tubeness3D(sigma);
break;
default:
System.err.println("Cannot compute tubeness for " + numDimensions + "D images.");
return;
}
ops().transform().project(tubeness, evs, method, numDimensions);
statusService.showProgress(3, 3);
return;
} catch (final IncompatibleTypeException | InterruptedException | ExecutionException e) {
e.printStackTrace();
return;
}
}
use of net.imglib2.exception.IncompatibleTypeException in project imagej-ops by imagej.
the class LocalThresholdTest method testLocalMeanResultsConsistency.
/**
* @see LocalMeanThresholdIntegral
* @see LocalMeanThreshold
*/
@Test
public void testLocalMeanResultsConsistency() {
Img<BitType> out2 = null;
Img<BitType> out3 = null;
try {
out2 = in.factory().imgFactory(new BitType()).create(in, new BitType());
out3 = in.factory().imgFactory(new BitType()).create(in, new BitType());
} catch (IncompatibleTypeException exc) {
exc.printStackTrace();
}
// Default implementation
ops.run(LocalMeanThreshold.class, out2, in, new RectangleShape(2, false), new OutOfBoundsMirrorFactory<ByteType, Img<ByteType>>(Boundary.SINGLE), 0.0);
// Integral image-based implementation
ops.run(LocalMeanThresholdIntegral.class, out3, in, new RectangleShape(2, false), new OutOfBoundsMirrorFactory<ByteType, Img<ByteType>>(Boundary.SINGLE), 0.0);
testIterableIntervalSimilarity(out2, out3);
}
use of net.imglib2.exception.IncompatibleTypeException in project imagej-ops by imagej.
the class LocalThresholdTest method testLocalSauvolaResultsConsistency.
/**
* @see LocalSauvolaThresholdIntegral
* @see LocalSauvolaThreshold
*/
@Test
public void testLocalSauvolaResultsConsistency() {
Img<BitType> out2 = null;
Img<BitType> out3 = null;
try {
out2 = in.factory().imgFactory(new BitType()).create(in, new BitType());
out3 = in.factory().imgFactory(new BitType()).create(in, new BitType());
} catch (IncompatibleTypeException exc) {
exc.printStackTrace();
}
// Default implementation
ops.run(LocalSauvolaThreshold.class, out2, normalizedIn, new RectangleShape(2, false), new OutOfBoundsMirrorFactory<ByteType, Img<ByteType>>(Boundary.SINGLE), 0.5, 0.5);
// Integral image-based implementation
ops.run(LocalSauvolaThresholdIntegral.class, out3, normalizedIn, new RectangleShape(2, false), new OutOfBoundsMirrorFactory<ByteType, Img<ByteType>>(Boundary.SINGLE), 0.5, 0.5);
testIterableIntervalSimilarity(out2, out3);
}
use of net.imglib2.exception.IncompatibleTypeException in project imagej-ops by imagej.
the class ApplyManualThresholdTest method testApplyThreshold.
@Test
public void testApplyThreshold() throws IncompatibleTypeException {
final Img<BitType> out = bitmap();
final UnsignedShortType threshold = new UnsignedShortType(30000);
ops.run(ApplyManualThreshold.class, out, in, threshold);
assertCount(out, 54);
}
Aggregations