use of net.imglib2.outofbounds.OutOfBoundsConstantValueFactory in project imagej-ops by imagej.
the class DefaultDilate method initialize.
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public void initialize() {
minVal = Util.getTypeFromInterval(in()).createVariable();
minVal.setReal(minVal.getMinValue());
if (f == null) {
f = new OutOfBoundsConstantValueFactory<>(minVal);
}
final UnaryComputerOp neighborComputer = minVal instanceof BitType ? new DilateBitType() : Computers.unary(ops(), Ops.Stats.Max.class, minVal.createVariable(), Iterable.class);
imgCreator = (UnaryFunctionOp) Functions.unary(ops(), Ops.Create.Img.class, Img.class, in(), minVal.createVariable());
if (out() == null)
setOutput(createOutput(in()));
mapper = ops().op(MapNeighborhood.class, out(), in1(), in2(), neighborComputer);
}
use of net.imglib2.outofbounds.OutOfBoundsConstantValueFactory in project imagej-ops by imagej.
the class DefaultErode method initialize.
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public void initialize() {
maxVal = Util.getTypeFromInterval(in()).createVariable();
maxVal.setReal(maxVal.getMaxValue());
if (f == null) {
f = new OutOfBoundsConstantValueFactory<>(maxVal);
}
final UnaryComputerOp neighborComputer = maxVal instanceof BitType ? new ErodeBitType() : Computers.unary(ops(), Ops.Stats.Min.class, maxVal.createVariable(), Iterable.class);
imgCreator = (UnaryFunctionOp) Functions.unary(ops(), Ops.Create.Img.class, Img.class, in(), maxVal.createVariable());
if (out() == null)
setOutput(createOutput(in()));
mapper = ops().op(MapNeighborhood.class, out(), in1(), in2(), neighborComputer);
}
use of net.imglib2.outofbounds.OutOfBoundsConstantValueFactory in project imagej-ops by imagej.
the class DeconvolveTest method testDeconvolve.
@Test
public void testDeconvolve() {
int[] size = new int[] { 225, 167 };
int[] kernelSize = new int[] { 27, 39 };
// create an input with a small sphere at the center
Img<FloatType> in = new ArrayImgFactory<FloatType>().create(size, new FloatType());
placeSphereInCenter(in);
// create a kernel with a small sphere in the center
Img<FloatType> kernel = new ArrayImgFactory<FloatType>().create(kernelSize, new FloatType());
placeSphereInCenter(kernel);
// convolve and calculate the sum of output
@SuppressWarnings("unchecked") final Img<FloatType> convolved = (Img<FloatType>) ops.run(ConvolveFFTF.class, in, kernel);
@SuppressWarnings("unchecked") final RandomAccessibleInterval<FloatType> deconvolved2 = (RandomAccessibleInterval<FloatType>) ops.run(RichardsonLucyF.class, convolved, kernel, null, new OutOfBoundsConstantValueFactory<>(Util.getTypeFromInterval(in).createVariable()), 10);
assertEquals(size[0], deconvolved2.dimension(0));
assertEquals(size[1], deconvolved2.dimension(1));
final Cursor<FloatType> deconvolved2Cursor = Views.iterable(deconvolved2).cursor();
float[] deconvolved2Values = { 1.0936068E-14f, 2.9685445E-14f, 4.280788E-15f, 3.032084E-18f, 1.1261E-39f, 0.0f, -8.7E-44f, -8.11881E-31f, -2.821192E-18f, 1.8687104E-20f, -2.927517E-23f, 1.2815774E-29f, -1.0611375E-19f, -5.2774515E-21f, -6.154334E-20f };
for (int i = 0; i < deconvolved2Values.length; i++) {
assertEquals(deconvolved2Values[i], deconvolved2Cursor.next().get(), 0.0f);
}
}
use of net.imglib2.outofbounds.OutOfBoundsConstantValueFactory in project imagej-ops by imagej.
the class DefaultDetectRidges method calculate.
@Override
public List<? extends WritablePolyline> calculate(RandomAccessibleInterval<T> input) {
double sigma = (width / (2 * Math.sqrt(3)));
// generate the metadata images
RidgeDetectionMetadata ridgeDetectionMetadata = new RidgeDetectionMetadata(input, sigma, lowerThreshold, higherThreshold);
// retrieve the metadata images
Img<DoubleType> p_values = ridgeDetectionMetadata.getPValues();
Img<DoubleType> n_values = ridgeDetectionMetadata.getNValues();
Img<DoubleType> gradients = ridgeDetectionMetadata.getGradients();
// create RandomAccesses for the metadata images
OutOfBoundsConstantValueFactory<DoubleType, RandomAccessibleInterval<DoubleType>> oscvf = new OutOfBoundsConstantValueFactory<>(new DoubleType(0));
RandomAccess<DoubleType> pRA = oscvf.create(p_values);
RandomAccess<DoubleType> nRA = oscvf.create(n_values);
RandomAccess<DoubleType> gradientRA = oscvf.create(gradients);
// create the output polyline list.
List<DefaultWritablePolyline> lines = new ArrayList<>();
// start at the point of greatest maximum absolute value
gradientRA.setPosition(RidgeDetectionUtils.getMaxCoords(gradients, true));
// loop through the maximum values of the image
while (Math.abs(gradientRA.get().get()) > higherThreshold) {
// create the List of points that will be used to make the polyline
List<RealPoint> points = new ArrayList<>();
// get all of the necessary metadata from the image.
long[] eigenvectorPos = { gradientRA.getLongPosition(0), gradientRA.getLongPosition(1), 0 };
// obtain the n-values
nRA.setPosition(eigenvectorPos);
double eigenx = nRA.get().getRealDouble();
nRA.fwd(2);
double eigeny = nRA.get().getRealDouble();
// obtain the p-values
pRA.setPosition(eigenvectorPos);
double px = pRA.get().getRealDouble();
pRA.fwd(2);
double py = pRA.get().getRealDouble();
// start the list by adding the current point, which is the most line-like
// point on the polyline
points.add(RidgeDetectionUtils.get2DRealPoint(gradientRA.getDoublePosition(0) + px, gradientRA.getDoublePosition(1) + py));
// go in the direction to the left of the perpendicular value
getNextPoint(gradientRA, pRA, nRA, points, RidgeDetectionUtils.getOctant(eigenx, eigeny), eigenx, eigeny, px, py);
// flip the array list around so that we get one cohesive line
gradientRA.setPosition(new long[] { eigenvectorPos[0], eigenvectorPos[1] });
Collections.reverse(points);
// go in the opposite direction as before.
eigenx = -eigenx;
eigeny = -eigeny;
getNextPoint(gradientRA, pRA, nRA, points, RidgeDetectionUtils.getOctant(eigenx, eigeny), eigenx, eigeny, px, py);
// set the value to 0 so that it is not reused.
gradientRA.get().setReal(0);
// list has fewer vertices than the parameter, then we do not report it.
if (points.size() > ridgeLengthMin) {
DefaultWritablePolyline pline = new DefaultWritablePolyline(points);
lines.add(pline);
}
// find the next max absolute value
gradientRA.setPosition(RidgeDetectionUtils.getMaxCoords(gradients, true));
}
return lines;
}
use of net.imglib2.outofbounds.OutOfBoundsConstantValueFactory in project imagej-ops by imagej.
the class PadInputFFT method calculate.
@Override
@SuppressWarnings("unchecked")
public O calculate(final I input, final Dimensions paddedDimensions) {
Dimensions paddedFFTInputDimensions;
// if an fftsize op has been set recompute padded size
if (fftSizeOp != null) {
long[][] sizes = fftSizeOp.calculate(paddedDimensions);
paddedFFTInputDimensions = new FinalDimensions(sizes[0]);
} else {
paddedFFTInputDimensions = paddedDimensions;
}
if (obf == null) {
obf = new OutOfBoundsConstantValueFactory<>(Util.getTypeFromInterval(input).createVariable());
}
Interval inputInterval = paddingIntervalCentered.calculate(input, paddedFFTInputDimensions);
return (O) Views.interval(Views.extend(input, obf), inputInterval);
}
Aggregations