Search in sources :

Example 1 with MedianCut

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;
}
Also used : ImageProcessor(ij.process.ImageProcessor) ColorProcessor(ij.process.ColorProcessor) ImageStack(ij.ImageStack) Rectangle(java.awt.Rectangle) Loader(ini.trakem2.persistence.Loader) MedianCut(ij.process.MedianCut) ImagePlus(ij.ImagePlus)

Aggregations

ImagePlus (ij.ImagePlus)1 ImageStack (ij.ImageStack)1 ColorProcessor (ij.process.ColorProcessor)1 ImageProcessor (ij.process.ImageProcessor)1 MedianCut (ij.process.MedianCut)1 Loader (ini.trakem2.persistence.Loader)1 Rectangle (java.awt.Rectangle)1