List of usage examples for org.apache.commons.math3.analysis.function Abs Abs
Abs
From source file:edu.stanford.cfuller.colocalization3d.correction.PositionCorrector.java
/** * Applies an existing correction to the positions of a set of objects, using a specified reference * and correction channel.//from w ww.j ava 2 s. c om * * @param imageObjects A Vector containing all the ImageObjects to be corrected. * @param c The Correction object to be used, which could have been generated with determineCorrection, or loaded from disk. * @return A RealVector with one entry per ImageObject, containing the corrected scalar distance between the object in the reference channel and the channel being corrected. */ public RealVector applyCorrection(Correction c, java.util.List<ImageObject> imageObjects) { int referenceChannel = this.parameters.getIntValueForKey(REF_CH_PARAM); int channelToCorrect = this.parameters.getIntValueForKey(CORR_CH_PARAM); RealVector diffs = new ArrayRealVector(imageObjects.size(), 0.0); RealVector averageVectorDiffs = null; for (int i = 0; i < imageObjects.size(); i++) { diffs.setEntry(i, imageObjects.get(i).getScalarDifferenceBetweenChannels(referenceChannel, channelToCorrect, this.pixelToDistanceConversions)); if (i == 0) { averageVectorDiffs = imageObjects.get(i) .getVectorDifferenceBetweenChannels(referenceChannel, channelToCorrect).copy(); } else { averageVectorDiffs = averageVectorDiffs.add(imageObjects.get(i) .getVectorDifferenceBetweenChannels(referenceChannel, channelToCorrect).map(new Abs())); } } averageVectorDiffs.mapDivideToSelf(imageObjects.size()); averageVectorDiffs = averageVectorDiffs.ebeMultiply(this.pixelToDistanceConversions); java.util.logging.Logger.getLogger("edu.stanford.cfuller.colocalization3d") .info("mean separation uncorrected = " + diffs.getL1Norm() / diffs.getDimension()); java.util.logging.Logger.getLogger("edu.stanford.cfuller.colocalization3d") .info("mean separation components uncorrected = " + averageVectorDiffs.toString()); RealVector newDiffs = new ArrayRealVector(imageObjects.size(), 0.0); if (this.parameters.getBooleanValueForKey("correct_images")) { for (int i = 0; i < imageObjects.size(); i++) { try { newDiffs.setEntry(i, this.correctSingleObjectVectorDifference(c, imageObjects.get(i), referenceChannel, channelToCorrect).getNorm()); imageObjects.get(i).setCorrectionSuccessful(true); } catch (UnableToCorrectException e) { newDiffs.setEntry(i, -1.0 * Double.MAX_VALUE); imageObjects.get(i).setCorrectionSuccessful(false); } } java.util.logging.Logger.getLogger("edu.stanford.cfuller.colocalization3d") .info("mean separation corrected = " + newDiffs.getL1Norm() / newDiffs.getDimension()); } else { newDiffs = diffs; } return newDiffs; }