use of ij.process.MedianCut in project TrakEM2 by trakem2.
the class PatchStack method createColor256Copy.
// WARNING This method will fail if the stack has slices of different dimensions
/**
* Does not respect local transform of the patches, this is intended for confocal stacks.
*/
public ImagePlus createColor256Copy() {
final Rectangle box = patch[0].getBoundingBox();
final int width = box.width;
final int height = box.height;
Loader loader = patch[0].getProject().getLoader();
// the montage, in RGB
patch[0].getProject().getLoader().releaseToFit(4 * patch.length * width * height);
final ColorProcessor montage = new ColorProcessor(width * patch.length, height);
for (int i = 0; i < patch.length; i++) {
montage.insert(this.stack.getProcessor(i + 1), i * width, 0);
}
final MedianCut mc = new MedianCut(montage);
loader.releaseToFit(patch.length * width * height);
ImageProcessor m2 = mc.convertToByte(256);
final ImageStack st = new ImageStack(width, height);
for (int i = 0; i < patch.length; i++) {
m2.setRoi(i * width, 0, width, height);
loader.releaseToFit(width * height);
st.addSlice(null, m2.crop());
}
ImagePlus imp = new ImagePlus("color256", st);
imp.setCalibration(patch[0].getLayer().getParent().getCalibrationCopy());
// imp.getCalibration().pixelDepth = patch[0].getLayer().getThickness();
return imp;
}
Aggregations