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();
}
Aggregations