use of net.imglib2.type.numeric.ARGBType in project TrakEM2 by trakem2.
the class LinearIntensityMap method mapARGB.
protected static final <T extends RealType<T>> void mapARGB(final IterableInterval<ARGBType> image, final IterableInterval<RealComposite<T>> coefficients) {
final Cursor<ARGBType> cs = image.cursor();
final Cursor<RealComposite<T>> ct = coefficients.cursor();
while (cs.hasNext()) {
final RealComposite<T> t = ct.next();
final double alpha = t.get(0).getRealDouble();
final double beta = t.get(1).getRealDouble();
final ARGBType s = cs.next();
final int argb = s.get();
final int a = ((argb >> 24) & 0xff);
final double r = ((argb >> 16) & 0xff) * alpha + beta;
final double g = ((argb >> 8) & 0xff) * alpha + beta;
final double b = (argb & 0xff) * alpha + beta;
s.set((a << 24) | ((r < 0 ? 0 : r > 255 ? 255 : (int) (r + 0.5)) << 16) | ((g < 0 ? 0 : g > 255 ? 255 : (int) (g + 0.5)) << 8) | (b < 0 ? 0 : b > 255 ? 255 : (int) (b + 0.5)));
}
}
use of net.imglib2.type.numeric.ARGBType in project TrakEM2 by trakem2.
the class LinearIntensityMap method main.
public static void main(final String[] args) {
new ImageJ();
final double[] coefficients = new double[] { 0, 2, 4, 8, 1, 1, 1, 1, 1, 10, 5, 1, 1, 1, 1, 1, 0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150 };
final LinearIntensityMap<DoubleType> transform = new LinearIntensityMap<DoubleType>(ArrayImgs.doubles(coefficients, 4, 4, 2));
// final ImagePlus imp = new ImagePlus( "http://upload.wikimedia.org/wikipedia/en/2/24/Lenna.png" );
final ImagePlus imp1 = new ImagePlus("http://fly.mpi-cbg.de/~saalfeld/Pictures/norway.jpg");
final ArrayImg<FloatType, FloatArray> image1 = ArrayImgs.floats((float[]) imp1.getProcessor().convertToFloatProcessor().getPixels(), imp1.getWidth(), imp1.getHeight());
final ArrayImg<UnsignedByteType, ByteArray> image2 = ArrayImgs.unsignedBytes((byte[]) imp1.getProcessor().convertToByteProcessor().getPixels(), imp1.getWidth(), imp1.getHeight());
final ArrayImg<UnsignedShortType, ShortArray> image3 = ArrayImgs.unsignedShorts((short[]) imp1.getProcessor().convertToShortProcessor().getPixels(), imp1.getWidth(), imp1.getHeight());
final ArrayImg<ARGBType, IntArray> image4 = ArrayImgs.argbs((int[]) imp1.getProcessor().getPixels(), imp1.getWidth(), imp1.getHeight());
ImageJFunctions.show(ArrayImgs.doubles(coefficients, 4, 4, 2));
transform.run(image1);
transform.run(image2);
transform.run(image3);
transform.run(image4);
ImageJFunctions.show(image1);
ImageJFunctions.show(image2);
ImageJFunctions.show(image3);
ImageJFunctions.show(image4);
}
use of net.imglib2.type.numeric.ARGBType in project TrakEM2 by trakem2.
the class LinearIntensityMap method run.
@SuppressWarnings({ "rawtypes", "unchecked" })
public <S extends NumericType<S>> void run(final RandomAccessibleInterval<S> image) {
assert image.numDimensions() == dimensions.numDimensions() : "Number of dimensions do not match.";
final double[] s = new double[dimensions.numDimensions()];
for (int d = 0; d < s.length; ++d) s[d] = image.dimension(d) / dimensions.dimension(d);
final Scale scale = new Scale(s);
// System.out.println( "translation-n " + translation.numDimensions() );
final RandomAccessibleInterval<RealComposite<T>> stretchedCoefficients = Views.offsetInterval(Views.raster(RealViews.transform(RealViews.transform(coefficients, translation), scale)), image);
/* decide on type which mapping to use */
final S t = image.randomAccess().get();
if (ARGBType.class.isInstance(t))
mapARGB(Views.flatIterable((RandomAccessibleInterval<ARGBType>) image), Views.flatIterable(stretchedCoefficients));
else if (RealComposite.class.isInstance(t))
mapComposite(Views.flatIterable((RandomAccessibleInterval) image), Views.flatIterable(stretchedCoefficients));
else if (RealType.class.isInstance(t)) {
final RealType<?> r = (RealType) t;
if (r.getMinValue() > -Double.MAX_VALUE || r.getMaxValue() < Double.MAX_VALUE)
// TODO Bug in javac does not enable cast from RandomAccessibleInterval< S > to RandomAccessibleInterval< RealType >, remove when fixed
mapCrop(Views.flatIterable((RandomAccessibleInterval<RealType>) (Object) image), Views.flatIterable(stretchedCoefficients));
else
// TODO Bug in javac does not enable cast from RandomAccessibleInterval< S > to RandomAccessibleInterval< RealType >, remove when fixed
map(Views.flatIterable((RandomAccessibleInterval<RealType>) (Object) image), Views.flatIterable(stretchedCoefficients));
}
}
Aggregations