Search in sources :

Example 61 with Point

use of com.forstudy.efjava.ch03.item10.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));
}
Also used : Point(effectivejava.chapter3.item10.Point)

Example 62 with Point

use of com.forstudy.efjava.ch03.item10.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;
}
Also used : Point(net.imglib2.Point) AffineTransform3D(net.imglib2.realtransform.AffineTransform3D)

Example 63 with Point

use of com.forstudy.efjava.ch03.item10.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;
}
Also used : ArrayList(java.util.ArrayList) Point(net.imglib2.Point)

Example 64 with Point

use of com.forstudy.efjava.ch03.item10.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;
}
Also used : Point(net.imglib2.Point) AffineTransform3D(net.imglib2.realtransform.AffineTransform3D)

Example 65 with Point

use of com.forstudy.efjava.ch03.item10.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;
}
Also used : Point(net.imglib2.Point) RealPoint(net.imglib2.RealPoint) Point(net.imglib2.Point) RealPoint(net.imglib2.RealPoint) FloatType(net.imglib2.type.numeric.real.FloatType) DetectionCreator(org.mastodon.tracking.detection.DetectionCreatorFactory.DetectionCreator) DogDetection(net.imglib2.algorithm.dog.DogDetection) RealPoint(net.imglib2.RealPoint) FinalInterval(net.imglib2.FinalInterval) RefinedPeak(net.imglib2.algorithm.localextrema.RefinedPeak) RandomAccessibleInterval(net.imglib2.RandomAccessibleInterval) FinalInterval(net.imglib2.FinalInterval) Interval(net.imglib2.Interval) AffineTransform3D(net.imglib2.realtransform.AffineTransform3D)

Aggregations

Point (net.imglib2.Point)33 ArrayList (java.util.ArrayList)16 FloatType (net.imglib2.type.numeric.real.FloatType)11 Test (org.junit.Test)9 List (java.util.List)8 Point (com.google.monitoring.v3.Point)7 Point (hr.fer.oop.recap2.task2.Point)7 FinalInterval (net.imglib2.FinalInterval)7 RealPoint (net.imglib2.RealPoint)7 TimeSeries (com.google.monitoring.v3.TimeSeries)6 Point (de.micromata.opengis.kml.v_2_2_0.Point)6 Interval (net.imglib2.Interval)6 RandomAccessibleInterval (net.imglib2.RandomAccessibleInterval)6 HyperSphere (net.imglib2.algorithm.region.hypersphere.HyperSphere)6 AffineTransform3D (net.imglib2.realtransform.AffineTransform3D)6 HashMap (java.util.HashMap)5 Metric (com.google.api.Metric)4 TimeInterval (com.google.monitoring.v3.TimeInterval)4 TypedValue (com.google.monitoring.v3.TypedValue)4 Map (java.util.Map)4