use of net.imglib2.Cursor in project imagej-ops by imagej.
the class NonCirculantNormalizationFactor method createNormalizationImageSemiNonCirculant.
protected void createNormalizationImageSemiNonCirculant() {
// k is the window size (valid image region)
final int length = k.numDimensions();
final long[] n = new long[length];
final long[] nFFT = new long[length];
// also referred to as object space size
for (int d = 0; d < length; d++) {
n[d] = k.dimension(d) + l.dimension(d) - 1;
}
for (int d = 0; d < length; d++) {
nFFT[d] = imgConvolutionInterval.dimension(d);
}
FinalDimensions fd = new FinalDimensions(nFFT);
// create the normalization image
normalization = create.calculate(fd);
// size of the measurement window
final Point size = new Point(length);
final long[] sizel = new long[length];
for (int d = 0; d < length; d++) {
size.setPosition(k.dimension(d), d);
sizel[d] = k.dimension(d);
}
// starting point of the measurement window when it is centered in fft space
final Point start = new Point(length);
final long[] startl = new long[length];
final long[] endl = new long[length];
for (int d = 0; d < length; d++) {
start.setPosition((nFFT[d] - k.dimension(d)) / 2, d);
startl[d] = (nFFT[d] - k.dimension(d)) / 2;
endl[d] = startl[d] + sizel[d] - 1;
}
// size of the object space
final Point maskSize = new Point(length);
final long[] maskSizel = new long[length];
for (int d = 0; d < length; d++) {
maskSize.setPosition(Math.min(n[d], nFFT[d]), d);
maskSizel[d] = Math.min(n[d], nFFT[d]);
}
// starting point of the object space within the fft space
final Point maskStart = new Point(length);
final long[] maskStartl = new long[length];
for (int d = 0; d < length; d++) {
maskStart.setPosition((Math.max(0, nFFT[d] - n[d]) / 2), d);
maskStartl[d] = (Math.max(0, nFFT[d] - n[d]) / 2);
}
final RandomAccessibleInterval<O> temp = Views.interval(normalization, new FinalInterval(startl, endl));
final Cursor<O> normCursor = Views.iterable(temp).cursor();
// draw a cube the size of the measurement space
while (normCursor.hasNext()) {
normCursor.fwd();
normCursor.get().setReal(1.0);
}
final Img<O> tempImg = create.calculate(fd);
// 3. correlate psf with the output of step 2.
correlater.compute(normalization, tempImg);
normalization = tempImg;
final Cursor<O> cursorN = normalization.cursor();
while (cursorN.hasNext()) {
cursorN.fwd();
if (cursorN.get().getRealFloat() <= 1e-3f) {
cursorN.get().setReal(1.0f);
}
}
}
use of net.imglib2.Cursor in project imagej-ops by imagej.
the class PermuteViewTest method permuteCoordinatesOfDimensionTest.
@Test
public void permuteCoordinatesOfDimensionTest() {
Img<DoubleType> img = new ArrayImgFactory<DoubleType>().create(new int[] { 2, 2 }, new DoubleType());
Cursor<DoubleType> c = img.cursor();
Random r = new Random();
while (c.hasNext()) {
c.next().set(r.nextDouble());
}
Cursor<DoubleType> il2 = Views.permuteCoordinates(img, new int[] { 0, 1 }, 1).cursor();
RandomAccess<DoubleType> opr = ops.transform().permuteCoordinatesView(img, new int[] { 0, 1 }, 1).randomAccess();
while (il2.hasNext()) {
il2.next();
opr.setPosition(il2);
assertEquals(il2.get().get(), opr.get().get(), 1e-10);
}
}
use of net.imglib2.Cursor in project imagej-ops by imagej.
the class PermuteViewTest method defaultPermuteCoordinatesTest.
@Test
public void defaultPermuteCoordinatesTest() {
Img<DoubleType> img = new ArrayImgFactory<DoubleType>().create(new int[] { 2, 2 }, new DoubleType());
Cursor<DoubleType> c = img.cursor();
Random r = new Random();
while (c.hasNext()) {
c.next().set(r.nextDouble());
}
Cursor<DoubleType> il2 = Views.permuteCoordinates(img, new int[] { 0, 1 }).cursor();
RandomAccess<DoubleType> opr = ops.transform().permuteCoordinatesView(img, new int[] { 0, 1 }).randomAccess();
while (il2.hasNext()) {
il2.next();
opr.setPosition(il2);
assertEquals(il2.get().get(), opr.get().get(), 1e-10);
}
}
use of net.imglib2.Cursor in project imagej-ops by imagej.
the class PermuteViewTest method defaultPermuteCoordinatesInverseTest.
@Test
public void defaultPermuteCoordinatesInverseTest() {
Img<DoubleType> img = new ArrayImgFactory<DoubleType>().create(new int[] { 2, 2 }, new DoubleType());
Cursor<DoubleType> c = img.cursor();
Random r = new Random();
while (c.hasNext()) {
c.next().set(r.nextDouble());
}
Cursor<DoubleType> il2 = Views.permuteCoordinatesInverse(img, new int[] { 0, 1 }).cursor();
RandomAccess<DoubleType> opr = ops.transform().permuteCoordinatesInverseView(img, new int[] { 0, 1 }).randomAccess();
while (il2.hasNext()) {
il2.next();
opr.setPosition(il2);
assertEquals(il2.get().get(), opr.get().get(), 1e-10);
}
}
use of net.imglib2.Cursor in project imagej-ops by imagej.
the class SubsampleViewTest method defaultSubsampleTest.
@Test
public void defaultSubsampleTest() {
Img<DoubleType> img = new ArrayImgFactory<DoubleType>().create(new int[] { 10, 10 }, new DoubleType());
Random r = new Random();
for (DoubleType d : img) {
d.set(r.nextDouble());
}
SubsampleView<DoubleType> il2 = Views.subsample((RandomAccessible<DoubleType>) img, 2);
SubsampleView<DoubleType> opr = ops.transform().subsampleView(img, 2);
Cursor<DoubleType> il2C = Views.interval(il2, new long[] { 0, 0 }, new long[] { 4, 4 }).localizingCursor();
RandomAccess<DoubleType> oprRA = opr.randomAccess();
while (il2C.hasNext()) {
il2C.next();
oprRA.setPosition(il2C);
assertEquals(il2C.get().get(), oprRA.get().get(), 1e-10);
}
}
Aggregations