use of net.imglib2.FinalInterval in project vcell by virtualcell.
the class ImageStatsForPlotting method computeMean.
/**
* Computes the mean of each XY slice along the 3rd dimension
* TODO: Currently assumes only 3 dimensions, must handle time series of z stacks and multiple channels
* @param data
* @return Pair containing A) the 3rd dimension index, and B) the mean value of the XY slice
*/
private Pair<double[], double[]> computeMean(RandomAccessibleInterval<T> data, IterableInterval<BitType> mask) {
double[] indices = new double[(int) data.dimension(2)];
double[] means = new double[indices.length];
for (int z = 0; z < indices.length; z++) {
FinalInterval interval = Intervals.createMinMax(0, 0, z, data.dimension(0) - 1, data.dimension(1) - 1, z);
double mean = 0.0;
RandomAccessibleInterval<T> cropped = ops.transform().crop(data, interval);
if (mask == null) {
mean = ops.stats().mean(Views.iterable(cropped)).getRealDouble();
} else {
Cursor<BitType> maskCursor = mask.localizingCursor();
RandomAccess<T> dataRA = cropped.randomAccess();
RealSum sum = new RealSum();
int size = 0;
maskCursor.reset();
while (maskCursor.hasNext()) {
maskCursor.fwd();
if (maskCursor.get().get()) {
dataRA.setPosition(maskCursor);
sum.add(dataRA.get().getRealDouble());
size++;
}
}
mean = sum.getSum() / size;
}
indices[z] = z;
means[z] = mean;
}
return new ValuePair<double[], double[]>(indices, means);
}
use of net.imglib2.FinalInterval in project vcell by virtualcell.
the class LargestRegionSlice method run.
@Override
public void run() {
int maxArea = 0;
int zOfMaxArea = 0;
for (int z = 0; z < data.dimension(2); z++) {
FinalInterval interval = Intervals.createMinMax(0, 0, z, data.dimension(0) - 1, data.dimension(1) - 1, z);
RandomAccessibleInterval<BitType> croppedRAI = ops.transform().crop(data, interval);
IterableInterval<BitType> croppedII = Views.iterable(croppedRAI);
Cursor<BitType> cursor = croppedII.cursor();
int area = 0;
while (cursor.hasNext()) {
if (cursor.next().get()) {
area++;
}
}
if (area > maxArea) {
maxArea = area;
zOfMaxArea = z;
}
}
FinalInterval interval = Intervals.createMinMax(0, 0, zOfMaxArea, data.dimension(0) - 1, data.dimension(1) - 1, zOfMaxArea);
output = ops.transform().crop(data, interval);
}
use of net.imglib2.FinalInterval in project imagej-ops by imagej.
the class IntegralImgTest method testIntegralImageSimilarity.
/**
* @see DefaultIntegralImg
* @see SquareIntegralImg
*/
@SuppressWarnings({ "unchecked" })
@Test
public void testIntegralImageSimilarity() {
RandomAccessibleInterval<LongType> out1 = (RandomAccessibleInterval<LongType>) ops.run(DefaultIntegralImg.class, in);
RandomAccessibleInterval<DoubleType> out2 = (RandomAccessibleInterval<DoubleType>) ops.run(WrappedIntegralImg.class, in);
// Remove 0s from integralImg by shifting its interval by +1
final long[] min = new long[out2.numDimensions()];
final long[] max = new long[out2.numDimensions()];
for (int d = 0; d < out2.numDimensions(); ++d) {
min[d] = out2.min(d) + 1;
max[d] = out2.max(d);
}
// Define the Interval on the infinite random accessibles
final FinalInterval interval = new FinalInterval(min, max);
LocalThresholdTest.testIterableIntervalSimilarity(Views.iterable(out1), Views.iterable(Views.offsetInterval(out2, interval)));
}
use of net.imglib2.FinalInterval in project imagej-ops by imagej.
the class SliceTest method testNonZeroMinimumInterval.
@Test
public void testNonZeroMinimumInterval() {
Img<ByteType> img3D = ArrayImgs.bytes(50, 50, 3);
IntervalView<ByteType> interval2D = Views.interval(img3D, new FinalInterval(new long[] { 25, 25, 2 }, new long[] { 35, 35, 2 }));
final int[] xyAxis = new int[] { 0, 1 };
// iterate through every slice, should return a single
// RandomAccessibleInterval<?> from 25, 25, 2 to 35, 35, 2
final SlicesII<ByteType> hyperSlices = new SlicesII<>(interval2D, xyAxis, true);
final Cursor<RandomAccessibleInterval<ByteType>> c = hyperSlices.cursor();
int i = 0;
while (c.hasNext()) {
c.next();
i++;
}
assertEquals(1, i);
}
use of net.imglib2.FinalInterval in project imagej-ops by imagej.
the class DefaultMarchingCubes method calculate.
@SuppressWarnings({ "unchecked" })
@Override
public DefaultMesh calculate(final RandomAccessibleInterval<T> input) {
DefaultMesh output = new DefaultMesh();
ExtendedRandomAccessibleInterval<T, RandomAccessibleInterval<T>> extended = Views.extendValue(input, (T) new BoolType(false));
Cursor<T> c = Views.interval(extended, new FinalInterval(new long[] { input.min(0) - 1, input.min(1) - 1, input.min(2) - 1 }, new long[] { input.max(0) + 1, input.max(1) + 1, input.max(2) + 1 })).localizingCursor();
while (c.hasNext()) {
c.next();
int cursorX = c.getIntPosition(0);
int cursorY = c.getIntPosition(1);
int cursorZ = c.getIntPosition(2);
Cursor<T> cu = getCube(extended, cursorX, cursorY, cursorZ);
int i = 0;
double[] vertex_values = new double[8];
while (cu.hasNext()) {
vertex_values[i++] = (cu.next().get()) ? 1 : 0;
}
// 6------7
// /| /|
// 2-----3 |
// | 4---|-5
// |/ |/
// 0-----1
vertex_values = mapFlatIterableToLookUpCube(vertex_values);
// 4------5
// /| /|
// 7-----6 |
// | 0---|-1
// |/ |/
// 3-----2
int cubeindex = getCubeIndex(vertex_values);
if (EDGE_TABLE[cubeindex] != 0) {
int[] p0 = new int[] { 0 + cursorX, 0 + cursorY, 1 + cursorZ };
int[] p1 = new int[] { 1 + cursorX, 0 + cursorY, 1 + cursorZ };
int[] p2 = new int[] { 1 + cursorX, 0 + cursorY, 0 + cursorZ };
int[] p3 = new int[] { 0 + cursorX, 0 + cursorY, 0 + cursorZ };
int[] p4 = new int[] { 0 + cursorX, 1 + cursorY, 1 + cursorZ };
int[] p5 = new int[] { 1 + cursorX, 1 + cursorY, 1 + cursorZ };
int[] p6 = new int[] { 1 + cursorX, 1 + cursorY, 0 + cursorZ };
int[] p7 = new int[] { 0 + cursorX, 1 + cursorY, 0 + cursorZ };
double[][] vertlist = new double[12][];
/* Find the vertices where the surface intersects the cube */
if (0 != (EDGE_TABLE[cubeindex] & 1)) {
vertlist[0] = interpolatePoint(p0, p1, vertex_values[0], vertex_values[1]);
}
if (0 != (EDGE_TABLE[cubeindex] & 2)) {
vertlist[1] = interpolatePoint(p1, p2, vertex_values[1], vertex_values[2]);
}
if (0 != (EDGE_TABLE[cubeindex] & 4)) {
vertlist[2] = interpolatePoint(p2, p3, vertex_values[2], vertex_values[3]);
}
if (0 != (EDGE_TABLE[cubeindex] & 8)) {
vertlist[3] = interpolatePoint(p3, p0, vertex_values[3], vertex_values[0]);
}
if (0 != (EDGE_TABLE[cubeindex] & 16)) {
vertlist[4] = interpolatePoint(p4, p5, vertex_values[4], vertex_values[5]);
}
if (0 != (EDGE_TABLE[cubeindex] & 32)) {
vertlist[5] = interpolatePoint(p5, p6, vertex_values[5], vertex_values[6]);
}
if (0 != (EDGE_TABLE[cubeindex] & 64)) {
vertlist[6] = interpolatePoint(p6, p7, vertex_values[6], vertex_values[7]);
}
if (0 != (EDGE_TABLE[cubeindex] & 128)) {
vertlist[7] = interpolatePoint(p7, p4, vertex_values[7], vertex_values[4]);
}
if (0 != (EDGE_TABLE[cubeindex] & 256)) {
vertlist[8] = interpolatePoint(p0, p4, vertex_values[0], vertex_values[4]);
}
if (0 != (EDGE_TABLE[cubeindex] & 512)) {
vertlist[9] = interpolatePoint(p1, p5, vertex_values[1], vertex_values[5]);
}
if (0 != (EDGE_TABLE[cubeindex] & 1024)) {
vertlist[10] = interpolatePoint(p2, p6, vertex_values[2], vertex_values[6]);
}
if (0 != (EDGE_TABLE[cubeindex] & 2048)) {
vertlist[11] = interpolatePoint(p3, p7, vertex_values[3], vertex_values[7]);
}
/* Create the triangle */
for (i = 0; TRIANGLE_TABLE[cubeindex][i] != -1; i += 3) {
TriangularFacet face = new TriangularFacet(new Vertex(vertlist[TRIANGLE_TABLE[cubeindex][i + 2]][0], vertlist[TRIANGLE_TABLE[cubeindex][i + 2]][1], vertlist[TRIANGLE_TABLE[cubeindex][i + 2]][2]), new Vertex(vertlist[TRIANGLE_TABLE[cubeindex][i + 1]][0], vertlist[TRIANGLE_TABLE[cubeindex][i + 1]][1], vertlist[TRIANGLE_TABLE[cubeindex][i + 1]][2]), new Vertex(vertlist[TRIANGLE_TABLE[cubeindex][i]][0], vertlist[TRIANGLE_TABLE[cubeindex][i]][1], vertlist[TRIANGLE_TABLE[cubeindex][i]][2]));
face.getArea();
output.addFace(face);
}
}
}
return output;
}
Aggregations