@@ -0,0 +1,1271 @@
+%0Apackage net.restlesscoder.sandbox.imagej;%0A%0Aimport java.io.IOException;%0A%0Aimport net.imagej.Dataset;%0Aimport net.imagej.ImageJ;%0Aimport net.imagej.ImgPlus;%0Aimport net.imglib2.RandomAccessibleInterval;%0Aimport net.imglib2.converter.Converters;%0Aimport net.imglib2.type.numeric.RealType;%0Aimport net.imglib2.type.numeric.integer.UnsignedByteType;%0A%0Apublic class ConvertersClamp %7B%0A%0A%09public static void main(final String... args) throws IOException %7B%0A%09%09final ImageJ ij = new ImageJ();%0A%09%09ij.ui().showUI();%0A%0A%09%09// Load an image of a colorful bird.%0A%09%09final String path = %22/Users/curtis/data/toucan.png%22;%0A%09%09final Dataset toucan = ij.scifio().datasetIO().open(path);%0A%09%09final ImgPlus%3CUnsignedByteType%3E img = toucan.typedImg(new UnsignedByteType());%0A%0A%09%09// Make bird less colorful.%0A%09%09RandomAccessibleInterval%3CUnsignedByteType%3E clamped = clamp(img, 50, 100, new UnsignedByteType());%0A%09%09ij.ui().show(%22Clamped%22, clamped);%0A%09%7D%0A%0A%09public static %3CT extends RealType%3CT%3E%3E RandomAccessibleInterval%3CT%3E clamp(%0A%09%09final RandomAccessibleInterval%3CT%3E image, final double min, final double max, final T type)%0A%09%7B%0A%09%09return Converters.convert(image, (in, out) -%3E %7B%0A%09%09%09double value = in.getRealDouble();%0A%09%09%09if (value %3C min) value = min;%0A%09%09%09else if (value %3E max) value = max;%0A%09%09%09out.setReal(value);%0A%09%09%7D, type);%0A%09%7D%0A%7D%0A

Add example that clamps image values to (min, max)