Search in sources :

Example 11 with Feature

use of mpicbg.imagefeatures.Feature in project TrakEM2 by trakem2.

the class ElasticMontage method extractAndSaveFeatures.

/**
 * Extract SIFT features and save them into the project folder.
 *
 * @param tiles
 * @param siftParam
 * @param clearCache
 * @throws Exception
 */
protected static final void extractAndSaveFeatures(final List<AbstractAffineTile2D<?>> tiles, final FloatArray2DSIFT.Param siftParam, final boolean clearCache) throws Exception {
    final ExecutorService exec = Executors.newFixedThreadPool(p.maxNumThreads);
    /* extract features for all slices and store them to disk */
    final AtomicInteger counter = new AtomicInteger(0);
    final ArrayList<Future<ArrayList<Feature>>> siftTasks = new ArrayList<Future<ArrayList<Feature>>>();
    for (int i = 0; i < tiles.size(); ++i) {
        final int tileIndex = i;
        siftTasks.add(exec.submit(new Callable<ArrayList<Feature>>() {

            @Override
            public ArrayList<Feature> call() {
                final AbstractAffineTile2D<?> tile = tiles.get(tileIndex);
                final String patchName = patchName(tile.getPatch());
                IJ.showProgress(counter.getAndIncrement(), tiles.size() - 1);
                ArrayList<Feature> fs = null;
                if (!clearCache)
                    fs = mpicbg.trakem2.align.Util.deserializeFeatures(tile.getPatch().getProject(), siftParam, null, tile.getPatch().getId());
                if (null == fs) {
                    final FloatArray2DSIFT sift = new FloatArray2DSIFT(siftParam);
                    final SIFT ijSIFT = new SIFT(sift);
                    fs = new ArrayList<Feature>();
                    final ByteProcessor ip = tile.createMaskedByteImage();
                    ijSIFT.extractFeatures(ip, fs);
                    Utils.log(fs.size() + " features extracted for " + patchName);
                    if (!mpicbg.trakem2.align.Util.serializeFeatures(tile.getPatch().getProject(), siftParam, null, tile.getPatch().getId(), fs))
                        Utils.log("FAILED to store serialized features for " + patchName);
                } else
                    Utils.log(fs.size() + " features loaded for " + patchName);
                return fs;
            }
        }));
    }
    /* join */
    for (final Future<ArrayList<Feature>> fu : siftTasks) fu.get();
    siftTasks.clear();
    exec.shutdown();
}
Also used : ByteProcessor(ij.process.ByteProcessor) SIFT(mpicbg.ij.SIFT) FloatArray2DSIFT(mpicbg.imagefeatures.FloatArray2DSIFT) ArrayList(java.util.ArrayList) Feature(mpicbg.imagefeatures.Feature) Point(mpicbg.models.Point) Callable(java.util.concurrent.Callable) FloatArray2DSIFT(mpicbg.imagefeatures.FloatArray2DSIFT) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ExecutorService(java.util.concurrent.ExecutorService) Future(java.util.concurrent.Future)

Aggregations

Feature (mpicbg.imagefeatures.Feature)11 ArrayList (java.util.ArrayList)10 SIFT (mpicbg.ij.SIFT)8 FloatArray2DSIFT (mpicbg.imagefeatures.FloatArray2DSIFT)8 Patch (ini.trakem2.display.Patch)6 Point (mpicbg.models.Point)6 Layer (ini.trakem2.display.Layer)5 Rectangle (java.awt.Rectangle)5 AffineTransform (java.awt.geom.AffineTransform)5 AbstractAffineModel2D (mpicbg.models.AbstractAffineModel2D)5 AffineModel2D (mpicbg.models.AffineModel2D)5 NotEnoughDataPointsException (mpicbg.models.NotEnoughDataPointsException)5 PointMatch (mpicbg.models.PointMatch)5 SimilarityModel2D (mpicbg.models.SimilarityModel2D)5 RigidModel2D (mpicbg.trakem2.transform.RigidModel2D)5 TranslationModel2D (mpicbg.trakem2.transform.TranslationModel2D)5 Loader (ini.trakem2.persistence.Loader)3 ExecutorService (java.util.concurrent.ExecutorService)3 Future (java.util.concurrent.Future)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3