use of net.imglib2.util.ValuePair 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.util.ValuePair in project imagej-ops by imagej.
the class DefaultMinimumFeret method calculate.
@Override
public Pair<RealLocalizable, RealLocalizable> calculate(Polygon2D input) {
final List<? extends RealLocalizable> points = GeomUtils.vertices(function.calculate(input));
double distance = Double.POSITIVE_INFINITY;
RealLocalizable p0 = points.get(0);
RealLocalizable p1 = points.get(0);
double tmpDist = 0;
RealLocalizable tmpP0 = p0;
RealLocalizable tmpP1 = p1;
for (int i = 0; i < points.size() - 2; i++) {
final RealLocalizable lineStart = points.get(i);
final RealLocalizable lineEnd = points.get(i + 1);
tmpDist = 0;
final Line l = new Line(new Vector2D(lineStart.getDoublePosition(0), lineStart.getDoublePosition(1)), new Vector2D(lineEnd.getDoublePosition(0), lineEnd.getDoublePosition(1)), 10e-12);
for (int j = 0; j < points.size(); j++) {
if (j != i && j != i + 1) {
final RealLocalizable ttmpP0 = points.get(j);
final double tmp = l.distance(new Vector2D(ttmpP0.getDoublePosition(0), ttmpP0.getDoublePosition(1)));
if (tmp > tmpDist) {
tmpDist = tmp;
final Vector2D vp = (Vector2D) l.project(new Vector2D(ttmpP0.getDoublePosition(0), ttmpP0.getDoublePosition(1)));
tmpP0 = new RealPoint(vp.getX(), vp.getY());
tmpP1 = ttmpP0;
}
}
}
if (tmpDist < distance) {
distance = tmpDist;
p0 = tmpP0;
p1 = tmpP1;
}
}
final RealLocalizable lineStart = points.get(points.size() - 1);
final RealLocalizable lineEnd = points.get(0);
final Line l = new Line(new Vector2D(lineStart.getDoublePosition(0), lineStart.getDoublePosition(1)), new Vector2D(lineEnd.getDoublePosition(0), lineEnd.getDoublePosition(1)), 10e-12);
tmpDist = 0;
for (int j = 0; j < points.size(); j++) {
if (j != points.size() - 1 && j != 0 + 1) {
final RealLocalizable ttmpP0 = points.get(j);
final double tmp = l.distance(new Vector2D(ttmpP0.getDoublePosition(0), ttmpP0.getDoublePosition(1)));
if (tmp > tmpDist) {
tmpDist = tmp;
final Vector2D vp = (Vector2D) l.project(new Vector2D(ttmpP0.getDoublePosition(0), ttmpP0.getDoublePosition(1)));
tmpP0 = new RealPoint(vp.getX(), vp.getY());
tmpP1 = ttmpP0;
}
}
}
if (tmpDist < distance) {
distance = tmpDist;
p0 = tmpP0;
p1 = tmpP1;
}
return new ValuePair<>(p0, p1);
}
Aggregations