use of net.imglib2.view.composite.CompositeView in project imagej-ops by imagej.
the class PartialDerivativeFilterTest method testAllDerivatives.
@Test
public void testAllDerivatives() {
Img<FloatType> img = generateFloatArrayTestImg(false, new long[] { 20, 20, 3 });
Cursor<FloatType> cursorImg = img.cursor();
int counterX = 0;
int counterY = 0;
while (cursorImg.hasNext()) {
if (counterX > 8 && counterX < 12 || counterY > 8 && counterY < 12) {
cursorImg.next().setOne();
} else {
cursorImg.next().setZero();
}
counterX++;
if (counterX % 20 == 0) {
counterY++;
}
if (counterX == 20) {
counterX = 0;
}
if (counterY == 20) {
counterY = 0;
}
}
CompositeIntervalView<FloatType, RealComposite<FloatType>> out = ops.filter().allPartialDerivatives(img);
CompositeView<FloatType, RealComposite<FloatType>>.CompositeRandomAccess outRA = out.randomAccess();
FloatType type = Util.getTypeFromInterval(img).createVariable();
// position 9,8 in all dimensions
outRA.setPosition(new int[] { 9, 8, 0 });
RealComposite<FloatType> outvalue = outRA.get();
Float[] correctValues = new Float[] { 12.0f, 4.0f, 0.0f };
int i = 0;
for (FloatType value : outvalue) {
type.set(correctValues[i]);
assertEquals(type, value);
i++;
}
outRA.setPosition(new int[] { 9, 8, 1 });
outvalue = outRA.get();
correctValues = new Float[] { 12.0f, 4.0f, 0.0f };
i = 0;
for (FloatType value : outvalue) {
type.set(correctValues[i]);
assertEquals(type, value);
i++;
}
outRA.setPosition(new int[] { 9, 8, 2 });
outvalue = outRA.get();
correctValues = new Float[] { 12.0f, 4.0f, 0.0f };
i = 0;
for (FloatType value : outvalue) {
type.set(correctValues[i]);
assertEquals(type, value);
i++;
}
// position 9,9 in all dimensions
outRA.setPosition(new int[] { 9, 9, 0 });
outvalue = outRA.get();
correctValues = new Float[] { 4.0f, 4.0f, 0.0f };
i = 0;
for (FloatType value : outvalue) {
type.set(correctValues[i]);
assertEquals(type, value);
i++;
}
outRA.setPosition(new int[] { 9, 9, 1 });
outvalue = outRA.get();
correctValues = new Float[] { 4.0f, 4.0f, 0.0f };
i = 0;
for (FloatType value : outvalue) {
type.set(correctValues[i]);
assertEquals(type, value);
i++;
}
outRA.setPosition(new int[] { 9, 9, 2 });
outvalue = outRA.get();
correctValues = new Float[] { 4.0f, 4.0f, 0.0f };
i = 0;
for (FloatType value : outvalue) {
type.set(correctValues[i]);
assertEquals(type, value);
i++;
}
// position 9,10 in all dimensions
outRA.setPosition(new int[] { 9, 10, 0 });
outvalue = outRA.get();
correctValues = new Float[] { 0.0f, 0.0f, 0.0f };
i = 0;
for (FloatType value : outvalue) {
type.set(correctValues[i]);
assertEquals(type, value);
i++;
}
outRA.setPosition(new int[] { 9, 10, 1 });
outvalue = outRA.get();
correctValues = new Float[] { 0.0f, 0.0f, 0.0f };
i = 0;
for (FloatType value : outvalue) {
type.set(correctValues[i]);
assertEquals(type, value);
i++;
}
outRA.setPosition(new int[] { 9, 10, 2 });
outvalue = outRA.get();
correctValues = new Float[] { 0.0f, 0.0f, 0.0f };
i = 0;
for (FloatType value : outvalue) {
type.set(correctValues[i]);
assertEquals(type, value);
i++;
}
// position 9,11 in all dimensions
outRA.setPosition(new int[] { 9, 11, 0 });
outvalue = outRA.get();
correctValues = new Float[] { 4.0f, -4.0f, 0.0f };
i = 0;
for (FloatType value : outvalue) {
type.set(correctValues[i]);
assertEquals(type, value);
i++;
}
outRA.setPosition(new int[] { 9, 11, 1 });
outvalue = outRA.get();
correctValues = new Float[] { 4.0f, -4.0f, 0.0f };
i = 0;
for (FloatType value : outvalue) {
type.set(correctValues[i]);
assertEquals(type, value);
i++;
}
outRA.setPosition(new int[] { 9, 11, 2 });
outvalue = outRA.get();
correctValues = new Float[] { 4.0f, -4.0f, 0.0f };
i = 0;
for (FloatType value : outvalue) {
type.set(correctValues[i]);
assertEquals(type, value);
i++;
}
}
use of net.imglib2.view.composite.CompositeView in project imagej-ops by imagej.
the class CollapseNumericViewTest method defaultCollapseNumericTest.
@Test
public void defaultCollapseNumericTest() {
Img<NativeARGBDoubleType> img = new ArrayImgFactory<NativeARGBDoubleType>().create(new int[] { 10, 10 }, new NativeARGBDoubleType());
CompositeIntervalView<NativeARGBDoubleType, NumericComposite<NativeARGBDoubleType>> il2 = Views.collapseNumeric((RandomAccessibleInterval<NativeARGBDoubleType>) img);
CompositeIntervalView<NativeARGBDoubleType, NumericComposite<NativeARGBDoubleType>> opr = ops.transform().collapseNumericView((RandomAccessibleInterval<NativeARGBDoubleType>) img);
assertEquals(il2.numDimensions(), opr.numDimensions());
CompositeView<NativeARGBDoubleType, NumericComposite<NativeARGBDoubleType>> il2_2 = Views.collapseNumeric((RandomAccessible<NativeARGBDoubleType>) img, 1);
CompositeView<NativeARGBDoubleType, NumericComposite<NativeARGBDoubleType>> opr_2 = ops.transform().collapseNumericView((RandomAccessible<NativeARGBDoubleType>) img, 1);
assertEquals(il2_2.numDimensions(), opr_2.numDimensions());
}
use of net.imglib2.view.composite.CompositeView in project imagej-ops by imagej.
the class CollapseRealViewTest method defaultCollapseRealTest.
@Test
public void defaultCollapseRealTest() {
Img<DoubleType> img = new ArrayImgFactory<DoubleType>().create(new int[] { 10, 10 }, new DoubleType());
CompositeIntervalView<DoubleType, RealComposite<DoubleType>> il2 = Views.collapseReal((RandomAccessibleInterval<DoubleType>) img);
CompositeIntervalView<DoubleType, RealComposite<DoubleType>> opr = ops.transform().collapseRealView((RandomAccessibleInterval<DoubleType>) img);
assertEquals(il2.numDimensions(), opr.numDimensions());
CompositeView<DoubleType, RealComposite<DoubleType>> il2_2 = Views.collapseReal((RandomAccessible<DoubleType>) img, 1);
CompositeView<DoubleType, RealComposite<DoubleType>> opr_2 = ops.transform().collapseRealView((RandomAccessible<DoubleType>) img, 1);
assertEquals(il2_2.numDimensions(), opr_2.numDimensions());
}
use of net.imglib2.view.composite.CompositeView in project imagej-ops by imagej.
the class CollapseViewTest method collapseRATest.
@Test
public void collapseRATest() {
Img<DoubleType> img = new ArrayImgFactory<DoubleType>().create(new int[] { 10, 10, 10 }, new DoubleType());
CompositeView<DoubleType, ? extends GenericComposite<DoubleType>> il2 = Views.collapse((RandomAccessible<DoubleType>) img);
CompositeView<DoubleType, ? extends GenericComposite<DoubleType>> opr = ops.transform().collapseView((RandomAccessible<DoubleType>) img);
assertEquals(il2.numDimensions(), opr.numDimensions());
}
use of net.imglib2.view.composite.CompositeView in project imagej-ops by imagej.
the class HessianFilterTest method test.
@Test
public void test() {
Img<FloatType> img = generateFloatArrayTestImg(false, new long[] { 50, 50 });
Cursor<FloatType> cursorImg = img.cursor();
int counterX = 0;
int counterY = 0;
while (cursorImg.hasNext()) {
if (counterX > 20 && counterX < 30 || counterY > 20 && counterY < 30) {
cursorImg.next().setOne();
} else {
cursorImg.next().setZero();
}
counterX++;
if (counterX % 50 == 0) {
counterY++;
}
if (counterX == 50) {
counterX = 0;
}
if (counterY == 50) {
counterY = 0;
}
}
CompositeIntervalView<FloatType, RealComposite<FloatType>> out = ops.filter().hessian(img);
Cursor<RealComposite<FloatType>> outCursor = Views.iterable(out).cursor();
while (outCursor.hasNext()) {
RealComposite<FloatType> values = outCursor.next();
assertEquals(values.get(1), values.get(2));
}
CompositeView<FloatType, RealComposite<FloatType>>.CompositeRandomAccess outRA = out.randomAccess();
// two numbers represent a coordinate: 20|0 ; 21|0 ...
int[] positions = new int[] { 20, 0, 21, 0, 19, 31, 19, 30 };
float[] valuesXX = new float[] { 16.0f, -16.0f, 15.0f, 11.0f };
float[] valuesXY = new float[] { 0.0f, 0.0f, 1.0f, 3.0f };
float[] valuesYY = new float[] { 0.0f, 0.0f, 15.0f, 15.0f };
FloatType type = Util.getTypeFromInterval(img).createVariable();
int i = 0;
int j = 0;
while (i < positions.length - 1) {
int[] pos = new int[2];
pos[0] = positions[i];
pos[1] = positions[i + 1];
outRA.setPosition(pos);
type.set(valuesXX[j]);
assertEquals(type, outRA.get().get(0));
outRA.setPosition(pos);
type.set(valuesXY[j]);
assertEquals(type, outRA.get().get(1));
outRA.setPosition(pos);
type.set(valuesYY[j]);
assertEquals(type, outRA.get().get(3));
i += 2;
j++;
}
}
Aggregations