19. August 2016

Using the Orbit API




compile 'com.actelion.research:orbit-image-analysis:3.15'

Orbit has a versatile API which allows you to do things like classification, cell segmentation and so on.

Here is a small example in Groovy how to iterate over a set of images and apply a classification model to each:

import com.actelion.research.mapReduceGeneric.utils.KeyValue
import com.actelion.research.orbit.imageAnalysis.dal.DALConfig
import com.actelion.research.orbit.imageAnalysis.models.OrbitModel
import com.actelion.research.orbit.imageAnalysis.utils.ClassificationResult
import com.actelion.research.orbit.imageAnalysis.utils.OrbitHelper
import com.actelion.research.orbit.imageAnalysis.utils.OrbitLogAppender
import com.actelion.research.orbit.imageAnalysis.utils.ScaleoutMode
import groovyx.gpars.GParsPool
 * Perform image classifications using an Orbit model. Images are processed multithreaded.
 * Replace model id, image search, optional: authentificate with username and password if needed.
OrbitLogAppender.GUI_APPENDER = false; // no GUI (error) popups
DALConfig.getImageProvider().authenticateUser("root", "omero"); // optional: otherwise the scaleout user defined in OrbitOmero.conf is used
OrbitModel model = OrbitModel.LoadFromOrbit(2229122); // the model to load - to be replaced
rdfList = OrbitHelper.searchImages("livers"); // search string - to be replaced
StringBuilder sb = new StringBuilder();
GParsPool.withPool {
   rdfList.eachParallel { // process each image parallel
       println "image: " + it
       ClassificationResult res = OrbitHelper.Classify(it.rawDataFileId, model);
       String resStr = it.fileName;
       List<KeyValue<String, Double>> norm = res.normalizeRatio();
       (0..model.getClassShapes().size()-1) {
       resStr += "\t" + norm.get(it).value;
 sb.append(resStr + "\n"); // append the result
println sb.toString(); // output the result
DALConfig.getImageProvider().close(); // close image provider connection

Btw: You (or your users!) can run those scripts directly in Orbit via the Tools -> Script Editor.

More examples can be found here.

API Calls

A good starting point to find out how to access the Orbit API is to have a look on the OrbitHelper class. This allows you to do classification or object segmentation programmatically in an easy way.

More advanced Orbit tasks are implemented as MapReduce steps. The Map-Step does something per tile, the reduce step aggregates the tile results. All map reduce tasks can be executed locally (multi-threaded) or via scaleout infrastructure, e.g. Spark, without further effort from your side.

Have a look on the com.actelion.research.orbit.imageAnalysis.tasks.* classes, e.g. how the ClassificationMapReduce class is implemented.