imagej / imagej-ops

ImageJ Ops: "Write once, run anywhere" image processing
https://imagej.net/libs/imagej-ops
BSD 2-Clause "Simplified" License
89 stars 42 forks source link

Create ops subproject leveraging Apache Commons Math 3? #429

Open ctrueden opened 8 years ago

ctrueden commented 8 years ago

Apache Commons Math 3 has lots of neat statistics functions. We should glance over them, and decide whether it makes sense to wrap any of them as ops. They all operate on double[] objects.

Here is an example script from @BishopWolf:

from ij import IJ

from org.apache.commons.math3.stat.descriptive.rank import Min, Max, Median, Percentile
from org.apache.commons.math3.stat.descriptive.moment import Mean, Variance, Skewness, Kurtosis

imp = IJ.getImage()
ip = imp.getProcessor().convertToFloat() # as a copy
pixels = ip.getPixels()
newpixels = []

print "Image is", imp.title, "of type", imp.type

for pixel in pixels:
    newpixels.append(pixel)

print "1. Minimum is:", Min().evaluate(newpixels)
print "2. Maximum is:", Max().evaluate(newpixels)
print "3. Median is:", Median().evaluate(newpixels)
print "4. Percentile is:", Percentile().evaluate(newpixels)
print "5. Mean is:", Mean().evaluate(newpixels)
print "6. Variance is:", Variance().evaluate(newpixels)
print "7. Skewness is:", Skewness().evaluate(newpixels)
print "8. Kurtosis is:", Kurtosis().evaluate(newpixels)
BishopWolf commented 8 years ago

i'm glad to contribute, the for cicle is to wrap the arrays from float to double, maybe repeating the code for float shall be enough.

dietzc commented 8 years ago

@BishopWolf nice meeting you. Do you know about https://github.com/imagej/imagej-ops/blob/master/src/main/java/net/imagej/ops/stats/StatsNamespace.java?

BishopWolf commented 8 years ago

I didnt know about that, I am currently doing this https://github.com/BishopWolf/NMQC/blob/master/src/main/java/utils/MathUtils.java do you have some advices on that, there we can give users a hint on what is the best practice on this

dietzc commented 8 years ago

If your input is already IterableInterval (e.g. an Img or ImgPlus are IterableIntervals), then you can simply use our implementations e.g. by calling ops().stats().mean(...). We have some more features implemented, like haralick, zernike, 2d, 3d geometric features etc.

BishopWolf commented 8 years ago

That only works for imageJ2, in that case the object is Img or ImgPlus. There is no support there for ImagePlus objects of ImageJ1. So if you are still there my way is the only solution ATM. I think this project shall be extended to include also ImagePlus, since they are used a lot! ImageJ1 is not dead yet ;)

ctrueden commented 8 years ago

There is no support there for ImagePlus objects of ImageJ1.

The Ops framework supports auto-conversion of types. So actually, you should be able to pass ImagePlus objects, which will get auto-converted to Dataset (and vice versa), because we have converters in both directions (1, 2). You just have to use ops().run(...) instead of the type-safe signatures.