use of com.geophile.z.spatialobject.d2.Point in project wiki by acktsap.
the class CounterPointTest method main.
public static void main(String[] args) {
Point p1 = new Point(1, 0);
Point p2 = new CounterPoint(1, 0);
// Prints true
System.out.println(onUnitCircle(p1));
// Should print true, but doesn't if Point uses getClass-based equals
System.out.println(onUnitCircle(p2));
}
use of com.geophile.z.spatialobject.d2.Point in project mastodon-tracking by mastodon-sc.
the class DetectionUtil method getMipmapTransform.
/**
* Returns the transformation that maps the image coordinates at level 0 to
* the image coordinates at the level specified, for the specified
* time-point, setup id.
* <p>
* If the data does not ship multiple resolution levels, the identity
* transform is returned.
*
* @param sources
* the image data.
* @param timepoint
* the time-point to query.
* @param setup
* the setup id to query.
* @param level
* the resolution level.
* @return a new transform.
*/
public static AffineTransform3D getMipmapTransform(final List<SourceAndConverter<?>> sources, final int timepoint, final int setup, final int level) {
// Get transform at level L -> global coords.
final AffineTransform3D levelL = getTransform(sources, timepoint, setup, level);
// Get transform at level 0 -> global coords.
final AffineTransform3D level0 = getTransform(sources, timepoint, setup, 0);
final AffineTransform3D transform = new AffineTransform3D();
for (int d = 0; d < 3; d++) {
final double scale = Affine3DHelpers.extractScale(levelL, d) / Affine3DHelpers.extractScale(level0, d);
transform.set(scale, d, d);
}
return transform;
}
use of com.geophile.z.spatialobject.d2.Point in project mastodon-tracking by mastodon-sc.
the class DetectionUtil method checkSettingsValidity.
/**
* Checks whether the provided settings map is suitable for use with the
* default detectors.
*
* @param settings
* the map to test.
* @param errorHolder
* a {@link StringBuilder} that will contain an error message if
* the check is not successful.
* @return true if the settings map can be used with the default detectors.
*/
public static final boolean checkSettingsValidity(final Map<String, Object> settings, final StringBuilder errorHolder) {
if (null == settings) {
errorHolder.append("Settings map is null.\n");
return false;
}
boolean ok = true;
// Check proper class.
ok = ok & checkParameter(settings, KEY_SETUP_ID, Integer.class, errorHolder);
ok = ok & checkParameter(settings, KEY_MIN_TIMEPOINT, Integer.class, errorHolder);
ok = ok & checkParameter(settings, KEY_MAX_TIMEPOINT, Integer.class, errorHolder);
ok = ok & checkParameter(settings, KEY_RADIUS, Double.class, errorHolder);
ok = ok & checkParameter(settings, KEY_THRESHOLD, Double.class, errorHolder);
// ok = ok & checkParameter( settings, KEY_ADD_BEHAVIOR, String.class, errorHolder );
// Check key presence.
final List<String> mandatoryKeys = new ArrayList<>();
mandatoryKeys.add(KEY_SETUP_ID);
mandatoryKeys.add(KEY_MIN_TIMEPOINT);
mandatoryKeys.add(KEY_MAX_TIMEPOINT);
mandatoryKeys.add(KEY_RADIUS);
mandatoryKeys.add(KEY_THRESHOLD);
final List<String> optionalKeys = new ArrayList<>();
optionalKeys.add(KEY_ADD_BEHAVIOR);
optionalKeys.add(KEY_ROI);
optionalKeys.add(KEY_DETECTION_TYPE);
ok = ok & checkMapKeys(settings, mandatoryKeys, optionalKeys, errorHolder);
// Check min & max time-point.
final int minTimepoint = (int) settings.get(KEY_MIN_TIMEPOINT);
final int maxTimepoint = (int) settings.get(KEY_MAX_TIMEPOINT);
if (maxTimepoint < minTimepoint) {
ok = false;
errorHolder.append("Min time-point should smaller than or equal to max time-point, be was min = " + minTimepoint + " and max = " + maxTimepoint + "\n");
}
return ok;
}
use of com.geophile.z.spatialobject.d2.Point in project mastodon-tracking by mastodon-sc.
the class DetectionUtil method getPixelSize.
/**
* Returns the pixel sizes of the specified setup at the specified
* resolution level, in units of the global coordinate system.
* <p>
* If the specified spimData does not have multiple resolution level, or if
* the specified resolution level does not exist, then the pixel sizes at
* level 0 is returned.
*
* @param sources
* the image data.
* @param timepoint
* the time-point to query.
* @param setup
* the setup id to query.
* @param level
* the resolution level.
* @return a new <code>double[]</code> array containing the pixel size.
*/
public static double[] getPixelSize(final List<SourceAndConverter<?>> sources, final int timepoint, final int setup, final int level) {
final AffineTransform3D transform = getTransform(sources, timepoint, setup, level);
final double[] pixelSize = new double[numDimensions(sources, setup, timepoint)];
for (int d = 0; d < pixelSize.length; d++) pixelSize[d] = Affine3DHelpers.extractScale(transform, d);
return pixelSize;
}
use of com.geophile.z.spatialobject.d2.Point in project mastodon-tracking by mastodon-sc.
the class DoGDetectorOp method mutate1.
@Override
public void mutate1(final DetectionCreatorFactory detectionCreatorFactory, final List<SourceAndConverter<?>> sources) {
ok = false;
final long start = System.currentTimeMillis();
final StringBuilder str = new StringBuilder();
if (!DetectionUtil.checkSettingsValidity(settings, str)) {
processingTime = System.currentTimeMillis() - start;
statusService.clearStatus();
errorMessage = str.toString();
return;
}
final int minTimepoint = (int) settings.get(KEY_MIN_TIMEPOINT);
final int maxTimepoint = (int) settings.get(KEY_MAX_TIMEPOINT);
final int setup = (int) settings.get(KEY_SETUP_ID);
final double radius = (double) settings.get(KEY_RADIUS);
final double threshold = (double) settings.get(KEY_THRESHOLD);
final Interval roi = (Interval) settings.get(KEY_ROI);
final DetectionType detectionType = DetectionType.getOrDefault((String) settings.get(KEY_DETECTION_TYPE), DetectionType.MINIMA);
statusService.showStatus("DoG detection.");
for (int tp = minTimepoint; tp <= maxTimepoint; tp++) {
statusService.showProgress(tp - minTimepoint + 1, maxTimepoint - minTimepoint + 1);
// Did we get canceled?
if (isCanceled())
break;
// Check if there is some data at this timepoint.
if (!DetectionUtil.isPresent(sources, setup, tp))
continue;
/*
* Determine optimal level for detection.
*/
final int level = DetectionUtil.determineOptimalResolutionLevel(sources, radius, MIN_SPOT_PIXEL_SIZE / 2., tp, setup);
/*
* Load and extends image data.
*/
final RandomAccessibleInterval<?> img = DetectionUtil.getImage(sources, tp, setup, level);
if (!DetectionUtil.isReallyPresent(img))
continue;
// If 2D, the 3rd dimension will be dropped here.
final RandomAccessibleInterval<?> zeroMin = Views.dropSingletonDimensions(Views.zeroMin(img));
@SuppressWarnings({ "unchecked", "rawtypes" }) final RandomAccessible<FloatType> source = DetectionUtil.asExtendedFloat((RandomAccessibleInterval) zeroMin);
/*
* Transform ROI in higher level.
*/
final Interval interval;
if (null == roi) {
interval = zeroMin;
} else {
final double[] minSource = new double[3];
final double[] maxSource = new double[3];
roi.realMin(minSource);
roi.realMax(maxSource);
final double[] minTarget = new double[3];
final double[] maxTarget = new double[3];
final AffineTransform3D mipmapTransform = DetectionUtil.getMipmapTransform(sources, tp, setup, level);
mipmapTransform.applyInverse(minTarget, minSource);
mipmapTransform.applyInverse(maxTarget, maxSource);
// Only take 2D or 3D version of the transformed interval.
final long[] tmin = new long[zeroMin.numDimensions()];
final long[] tmax = new long[zeroMin.numDimensions()];
for (int d = 0; d < zeroMin.numDimensions(); d++) {
tmin[d] = (long) Math.ceil(minTarget[d]);
tmax[d] = (long) Math.floor(maxTarget[d]);
}
final FinalInterval transformedRoi = new FinalInterval(tmin, tmax);
interval = Intervals.intersect(transformedRoi, zeroMin);
}
// Ensure that the interval size is at least 3 in all dimensions.
final long[] min = new long[interval.numDimensions()];
interval.min(min);
final long[] max = new long[interval.numDimensions()];
interval.max(max);
for (int d = 0; d < interval.numDimensions(); d++) if (interval.dimension(d) < 3) {
min[d]--;
max[d]++;
}
final FinalInterval minInterval = new FinalInterval(min, max);
/*
* Process image.
*/
final int stepsPerOctave = 4;
final double k = Math.pow(2.0, 1.0 / stepsPerOctave);
final double sigma = radius / Math.sqrt(zeroMin.numDimensions());
final double sigmaSmaller = sigma;
final double sigmaLarger = k * sigmaSmaller;
final double normalization = ((detectionType == DetectionType.MAXIMA) ? 1.0 : -1.0) / (sigmaLarger / sigmaSmaller - 1.0);
final double[] pixelSize = DetectionUtil.getPixelSize(sources, tp, setup, level);
final DogDetection<FloatType> dog = new DogDetection<>(source, minInterval, pixelSize, sigmaSmaller, sigmaLarger, (detectionType == DetectionType.MAXIMA) ? ExtremaType.MAXIMA : ExtremaType.MINIMA, threshold, true);
dog.setExecutorService(threadService.getExecutorService());
final ArrayList<RefinedPeak<Point>> refinedPeaks = dog.getSubpixelPeaks();
final double[] pos = new double[3];
final RealPoint sp = RealPoint.wrap(pos);
final RealPoint p3d = new RealPoint(3);
final AffineTransform3D transform = DetectionUtil.getTransform(sources, tp, setup, level);
final DetectionCreator detectionCreator = detectionCreatorFactory.create(tp);
detectionCreator.preAddition();
try {
for (final RefinedPeak<Point> p : refinedPeaks) {
final double value = p.getValue();
final double normalizedValue = value * normalization;
/*
* In case p is 2D we pass it to a 3D RealPoint to work
* nicely with the 3D transform.
*/
for (int d = 0; d < p.numDimensions(); d++) p3d.setPosition(p.getDoublePosition(d), d);
transform.apply(p3d, sp);
detectionCreator.createDetection(pos, radius, normalizedValue);
}
} finally {
detectionCreator.postAddition();
}
}
final long end = System.currentTimeMillis();
processingTime = end - start;
statusService.clearStatus();
ok = true;
}
Aggregations