package fiji.plugin.filamentdetector.tests;

import org.scijava.Context;
import org.scijava.log.LogService;

import fiji.plugin.filamentdetector.preprocessing.ImagePreprocessors;
import net.imagej.Dataset;
import net.imagej.DatasetService;
import net.imagej.ImageJ;
import net.imagej.axis.CalibratedAxis;
import net.imagej.display.ImageDisplay;
import net.imagej.ops.OpService;
import net.imagej.ops.convert.RealTypeConverter;
import net.imglib2.IterableInterval;
import net.imglib2.img.Img;
import net.imglib2.type.numeric.RealType;
import net.imglib2.type.numeric.real.FloatType;

public class TestPreprocessing {

	public static <T extends RealType<T>> void main(final String... args) throws Exception {
		final ImageJ ij = net.imagej.Main.launch(args);
		Context context = ij.getContext();

		LogService log = ij.log();
		OpService ops = ij.op();
		DatasetService ds = ij.dataset();

		String fpath = "/home/hadim/.doc/Code/Postdoc/ij/testdata/7,5uM_emccd_lapse1-small-8bit.tif";
		Dataset dataset = ij.dataset().open(fpath);
		ij.ui().show(dataset);

		ImageDisplay imd = ij.imageDisplay().getActiveImageDisplay();

//		ImagePreprocessors proc = new ImagePreprocessors(context, imd);
//		proc.setGaussianFilterSize(50);
//		Dataset background = proc.applyGaussianFilter(dataset);
//		ij.ui().show(background);
//
//		// Convert to 32 bits
//		IterableInterval<FloatType> out = (IterableInterval<FloatType>) ops.run("convert.float32",
//				dataset.getImgPlus());
//		IterableInterval<FloatType> original = (IterableInterval<FloatType>) ops.run("convert.float32",
//				dataset.getImgPlus());
//		IterableInterval<FloatType> backgroundFloat = (IterableInterval<FloatType>) ops.run("convert.float32",
//				background.getImgPlus());
//
//		// Do subtraction
//		IterableInterval<FloatType> out2 = (IterableInterval<FloatType>) ops.create().img(out);
//		ops.math().subtract(out2, original, backgroundFloat);
//
//		// Clip intensities
//		Img<T> out3 = (Img<T>) ops.create().img(dataset.getImgPlus());
//		RealTypeConverter op2 = (RealTypeConverter) ops.op("convert.clip", dataset.getImgPlus().firstElement(),
//				out2.firstElement());
//		ops.convert().imageType(out3, out2, op2);
//
//		CalibratedAxis[] axes = new CalibratedAxis[dataset.numDimensions()];
//		for (int i = 0; i != axes.length; i++) {
//			axes[i] = dataset.axis(i);
//		}
//		Dataset output = ds.create(out3);
//		output.setAxes(axes);
//
//		ij.ui().show(output);

	}
}

@@ -152,21 +152,30 @@
 cessing.
-Image
+GaussianFilter
 Preproce
@@ -178,17 +178,16 @@
 rocessor
-s
 ;%0Aimport
@@ -289,300 +289,59 @@
 gej.
-axis.CalibratedAxis;%0Aimport net.imagej.display.ImageDisplay;%0Aimport net.imagej.ops.OpService;%0Aimport net.imagej.ops.convert.RealTypeConverter;%0Aimport net.imglib2.IterableInterval;%0Aimport net.imglib2.img.Img;%0Aimport net.imglib2.type.numeric.RealType;%0Aimport net.imglib2.type.numeric.real.Float
+ops.OpService;%0Aimport net.imglib2.type.numeric.Real
 Type
@@ -822,80 +822,22 @@
 %0A%0A%09%09
-ImageDisplay imd = ij.imageDisplay().getActiveImageDisplay();%0A%0A//%09%09Image
+GaussianFilter
 Prep
@@ -844,17 +844,16 @@
 rocessor
-s
  proc = 
@@ -860,1201 +860,157 @@
 new 
-ImagePreprocessors(context, imd);%0A//%09%09proc.setGaussianFilterSize(50);%0A//%09%09Dataset background = proc.applyGaussianFilter(dataset);%0A//%09%09ij.ui().show(background);%0A//%0A//%09%09// Convert to 32 bits%0A//%09%09IterableInterval%3CFloatType%3E out = (IterableInterval%3CFloatType%3E) ops.run(%22convert.float32%22,%0A//%09%09%09%09dataset.getImgPlus());%0A//%09%09IterableInterval%3CFloatType%3E original = (IterableInterval%3CFloatType%3E) ops.run(%22convert.float32%22,%0A//%09%09%09%09dataset.getImgPlus());%0A//%09%09IterableInterval%3CFloatType%3E backgroundFloat = (IterableInterval%3CFloatType%3E) ops.run(%22convert.float32%22,%0A//%09%09%09%09background.getImgPlus());%0A//%0A//%09%09// Do subtraction%0A//%09%09IterableInterval%3CFloatType%3E out2 = (IterableInterval%3CFloatType%3E) ops.create().img(out);%0A//%09%09ops.math().subtract(out2, original, backgroundFloat);%0A//%0A//%09%09// Clip intensities%0A//%09%09Img%3CT%3E out3 = (Img%3CT%3E) ops.create().img(dataset.getImgPlus());%0A//%09%09RealTypeConverter op2 = (RealTypeConverter) ops.op(%22convert.clip%22, dataset.getImgPlus().firstElement(),%0A//%09%09%09%09out2.firstElement());%0A//%09%09ops.convert().imageType(out3, out2, op2);%0A//%0A//%09%09CalibratedAxis%5B%5D axes = new CalibratedAxis%5Bdataset.numDimensions()%5D;%0A//%09%09for (int i = 0; i != axes.length; i++) %7B%0A//%09%09%09axes%5Bi%5D = dataset.axi
+GaussianFilterPreprocessor(context);%0A%09%09proc.setDoPreprocess(true);%0A%09%09proc.setGaussianFilterSize(20);%0A%0A%09%09proc.setInput(dataset);%0A%09%09proc.preproces
 s(
-i
 );%0A
-//%09%09%7D%0A//
 %09%09Da
@@ -1028,56 +1028,27 @@
 t = 
-ds.create(out3);%0A//%09%09output.setAxes(axes);%0A//%0A//
+proc.getOutput();%0A%0A
 %09%09ij

Clean manual test