use of mpicbg.imglib.algorithm.integral.IntegralImage in project TrakEM2 by trakem2.
the class IntegralImageMipMaps method createGRAY8.
@SuppressWarnings({ "unused", "unchecked", "null" })
private static final BufferedImage[] createGRAY8(final Patch patch, final ByteProcessor ip, final ByteProcessor mask) {
final int w = ip.getWidth();
final int h = ip.getHeight();
final int[] dims = new int[] { w, h };
final ScaleAreaAveraging2d<LongType, UnsignedByteType> saai, saam;
{
// Integral of the image
final IntegralImage<UnsignedByteType, LongType> oa = new IntegralImage<UnsignedByteType, LongType>(wrap((byte[]) ip.getPixels(), dims), new LongType(), new IntegerTypeConverter<UnsignedByteType, LongType>());
oa.process();
saai = new ScaleAreaAveraging2d<LongType, UnsignedByteType>(oa.getResult(), new UnsignedByteType(), dims);
// Integral of the mask, if any
if (null != mask) {
final IntegralImage<UnsignedByteType, LongType> ma = new IntegralImage<UnsignedByteType, LongType>(wrap((byte[]) mask.getPixels(), dims), new LongType(), new IntegerTypeConverter<UnsignedByteType, LongType>());
ma.process();
saam = new ScaleAreaAveraging2d<LongType, UnsignedByteType>(ma.getResult(), new UnsignedByteType(), dims);
} else {
saam = null;
}
}
// Generate images
final BufferedImage[] bis = new BufferedImage[Loader.getHighestMipMapLevel(patch) + 1];
//
if (null == saam) {
// mask is null
// Save images as grayscale
// sharing the byte[]
bis[0] = ImageSaver.createGrayImage((byte[]) ip.getPixels(), w, h);
for (int i = 1; i < bis.length; i++) {
final int K = (int) Math.pow(2, i), wk = w / K, hk = h / K;
// An image of the scaled size
saai.setOutputDimensions(wk, hk);
saai.process();
bis[i] = ImageSaver.createGrayImage(((Array<UnsignedByteType, ByteArray>) saai.getResult().getContainer()).update(null).getCurrentStorageArray(), wk, hk);
}
} else {
// Save images as RGBA, where all 3 color channels are the same
bis[0] = ImageSaver.createARGBImage(blend((byte[]) ip.getPixels(), (byte[]) mask.getPixels()), w, h);
for (int i = 1; i < bis.length; i++) {
final int K = (int) Math.pow(2, i), wk = w / K, hk = h / K;
// An image of the scaled size
saai.setOutputDimensions(wk, hk);
saai.process();
// A mask of the scaled size
saam.setOutputDimensions(wk, hk);
saam.process();
//
bis[i] = ImageSaver.createARGBImage(blend(((Array<UnsignedByteType, ByteArray>) saai.getResult().getContainer()).update(null).getCurrentStorageArray(), ((Array<UnsignedByteType, ByteArray>) saam.getResult().getContainer()).update(null).getCurrentStorageArray()), wk, hk);
}
}
return bis;
}
use of mpicbg.imglib.algorithm.integral.IntegralImage in project TrakEM2 by trakem2.
the class IntegralImageMipMaps method saa.
private static final ScaleAreaAveraging2d<LongType, UnsignedByteType> saa(final byte[] b, final int[] dims) {
final IntegralImage<UnsignedByteType, LongType> ii = new IntegralImage<UnsignedByteType, LongType>(wrap(b, dims), new LongType(), new IntegerTypeConverter<UnsignedByteType, LongType>());
ii.process();
return new ScaleAreaAveraging2d<LongType, UnsignedByteType>(ii.getResult(), new UnsignedByteType(), dims);
}
Aggregations