use of net.imglib2.view.composite.RealComposite 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.RealComposite in project TrakEM2 by trakem2.
the class LinearIntensityMap method mapARGB.
protected static final <T extends RealType<T>> void mapARGB(final IterableInterval<ARGBType> image, final IterableInterval<RealComposite<T>> coefficients) {
final Cursor<ARGBType> cs = image.cursor();
final Cursor<RealComposite<T>> ct = coefficients.cursor();
while (cs.hasNext()) {
final RealComposite<T> t = ct.next();
final double alpha = t.get(0).getRealDouble();
final double beta = t.get(1).getRealDouble();
final ARGBType s = cs.next();
final int argb = s.get();
final int a = ((argb >> 24) & 0xff);
final double r = ((argb >> 16) & 0xff) * alpha + beta;
final double g = ((argb >> 8) & 0xff) * alpha + beta;
final double b = (argb & 0xff) * alpha + beta;
s.set((a << 24) | ((r < 0 ? 0 : r > 255 ? 255 : (int) (r + 0.5)) << 16) | ((g < 0 ? 0 : g > 255 ? 255 : (int) (g + 0.5)) << 8) | (b < 0 ? 0 : b > 255 ? 255 : (int) (b + 0.5)));
}
}
use of net.imglib2.view.composite.RealComposite 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.RealComposite 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++;
}
}
use of net.imglib2.view.composite.RealComposite in project TrakEM2 by trakem2.
the class LinearIntensityMap method run.
@SuppressWarnings({ "rawtypes", "unchecked" })
public <S extends NumericType<S>> void run(final RandomAccessibleInterval<S> image) {
assert image.numDimensions() == dimensions.numDimensions() : "Number of dimensions do not match.";
final double[] s = new double[dimensions.numDimensions()];
for (int d = 0; d < s.length; ++d) s[d] = image.dimension(d) / dimensions.dimension(d);
final Scale scale = new Scale(s);
// System.out.println( "translation-n " + translation.numDimensions() );
final RandomAccessibleInterval<RealComposite<T>> stretchedCoefficients = Views.offsetInterval(Views.raster(RealViews.transform(RealViews.transform(coefficients, translation), scale)), image);
/* decide on type which mapping to use */
final S t = image.randomAccess().get();
if (ARGBType.class.isInstance(t))
mapARGB(Views.flatIterable((RandomAccessibleInterval<ARGBType>) image), Views.flatIterable(stretchedCoefficients));
else if (RealComposite.class.isInstance(t))
mapComposite(Views.flatIterable((RandomAccessibleInterval) image), Views.flatIterable(stretchedCoefficients));
else if (RealType.class.isInstance(t)) {
final RealType<?> r = (RealType) t;
if (r.getMinValue() > -Double.MAX_VALUE || r.getMaxValue() < Double.MAX_VALUE)
// TODO Bug in javac does not enable cast from RandomAccessibleInterval< S > to RandomAccessibleInterval< RealType >, remove when fixed
mapCrop(Views.flatIterable((RandomAccessibleInterval<RealType>) (Object) image), Views.flatIterable(stretchedCoefficients));
else
// TODO Bug in javac does not enable cast from RandomAccessibleInterval< S > to RandomAccessibleInterval< RealType >, remove when fixed
map(Views.flatIterable((RandomAccessibleInterval<RealType>) (Object) image), Views.flatIterable(stretchedCoefficients));
}
}
Aggregations