NOTICE! This is a static HTML version of a legacy ImageJ Trac ticket.

The ImageJ project now uses GitHub Issues for issue tracking.

Please file all new issues there.

Ticket #1384 (closed enhancement: wontfix)

Opened 2012-08-10T18:35:13-05:00

Last modified 2013-12-06T17:45:59-06:00

Create ImageStatistics class

Reported by: aivar Owned by: aivar
Priority: minor Milestone: imagej2-b8-analysis
Component: ImgLib2 Version:
Severity: minor Keywords:
Cc: Blocked By:
Blocking: #794

Description (last modified by aivar)

Need to get statistics on an image with the minimal number of passes through the image.

For example it might include methods:

request certain things ahead of time
doHistogram(int bins);

[or doHistogram(int bins, double min, double max);]


do minimal number of passes through the image

get accumulated results
double[] getMinMax();
long[] getHistogram();
double getMean;

Here if you don't specify a min/max for doHistogram the code has to take an initial pass to get min/max then another to build the histogram using that min/max.

Change History

comment:1 Changed 2012-08-10T18:38:37-05:00 by aivar

  • Blocking 1385 added

comment:2 Changed 2012-08-10T18:40:44-05:00 by aivar

  • Blocking 1385 removed

comment:3 Changed 2012-08-10T18:43:46-05:00 by aivar

  • Blocking 1386 added

comment:4 Changed 2012-08-10T18:47:38-05:00 by aivar

  • Component changed from other to imglib

comment:5 Changed 2012-09-07T12:41:48-05:00 by aivar

  • Description modified

comment:6 Changed 2012-09-07T13:06:01-05:00 by aivar

  • Blocking 1128 added; 1386 removed
  • Milestone changed from imagej-2.0.0-beta4 to imagej-2.0.0-beta5

comment:7 Changed 2012-10-03T16:38:05-05:00 by bdezonia

  • Blocking 794 added

comment:8 Changed 2012-10-12T12:34:34-05:00 by bdezonia

I think using the MeasurmentService all this can be accomplished. We should discuss actual examples so we can try.

(Later edit: I may have misspoke. The MeasurementService is pretty simple. Users need to provide aggregating classes to reuse computations.)

Last edited 2012-10-12T13:01:09-05:00 by bdezonia

comment:9 Changed 2012-10-12T13:28:18-05:00 by aivar

Here's some simplistic pseudo-code for the sort of approach I had in mind:

class MeanFunction extends AbstractBaseFunction {
  double sum;
  int count;
  double mean;

  preprocess() { // called before any pixel processing
    sum = 0.0;
    count = 0;

  processPixel(T pixel) { // processes pixels one by one
    sum += T.getRealDouble();

  postprocess() { // called after all pixel processing
    double mean = sum / count;

  getMean() {
    return mean;

class AbstractBaseFunction implements Function {
  Function next;

  chain(Function next) { // builds a chain of functions = next;

  chainedPreprocess() { // preprocess the chain
     if (null != next) {

  chainedProcessPixel(T pixel) { // process pixel through the chain
    if (null != next) {

  chainedPostprocess() { // postprocess the chain
     if (null != next) {

  abstract preprocess();
  abstract postprocess();
  abstract processPixel();

  // usage
  MeanFunction meanFunction = new MeanFunction();
  MinMaxFunction minMaxFunction = new MinMaxFunction();
  process(iterator, meanFunction);
  System.out.println("Mean is " + meanFunction.getMean());
  System.out.println("Min is " + minMaxFunction.getMin() + " max is " + minMaxFunction.getMax());

  . . .

  void process(PointSetIterator iterator, Function function) {
    while (iterator.hasNext()) {
      point =;
Last edited 2012-10-12T13:32:30-05:00 by aivar

comment:10 Changed 2012-10-12T13:42:36-05:00 by aivar

This doesn't handle re-use of computations. Perhaps the chain could be a doubly-linked list, then in the preprocess( ) method you could look back up the chain for the Function you need results from (using a common helper method). Then in processPixel( ) you can call that Function's getters.

Last edited 2012-10-12T13:47:24-05:00 by aivar

comment:11 Changed 2012-10-17T16:29:06-05:00 by curtis

I think this chaining approach is unnecessarily complex. If you have a computation (we'll call it a "module") that could benefit from the outputs of another module, there are a couple of ways of dealing with that to manage efficiency:

1) Create two modules, one that takes e.g. a Dataset and a Histogram, and computes results based on those.

2) Create one module that takes a required Dataset and an optional Histogram, and uses the Histogram results if present (or if not, just computes what is needed on the fly from the Dataset itself).

comment:12 Changed 2012-10-23T14:34:36-05:00 by bdezonia

I've implemented some ideas in the measure-engine branch of Imlib2.

Related fiji email available at: (!topic/fiji-devel/AnYq_caJA1M)

Note that after posting my email dscho chimed in that the KNIME developers have a good start on a measurement engine that they will release to Imglib.

comment:13 Changed 2013-03-05T12:28:37-06:00 by bdezonia

  • Blocking 1128 removed

(In #1128) I have been doing some work on this for our most recent beta on imglib's histogram-stuff branch. Soon I'll share with others and solicit feedback.

comment:14 Changed 2013-06-07T16:07:52-05:00 by bdezonia

  • Milestone changed from imagej2-b7-ndim-data to imagej2-b8-analysis

comment:15 Changed 2013-12-06T17:45:59-06:00 by aivar

  • Status changed from new to closed
  • Resolution set to wontfix

My original motivation for the 'minimal number of passes' was based on the case of a huge image that is possibly paged in/out. Other situations might require other optimizations.