use of ij.ImagePlus 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;
}
use of ij.ImagePlus in project TrakEM2 by trakem2.
the class PatchStack method getMask.
public ImageProcessor getMask() {
ImagePlus imp = patch[currentSlice - 1].getProject().getLoader().fetchImagePlus(patch[currentSlice - 1]);
ImageProcessor ip = imp.getProcessor();
Roi roi = getRoi();
if (null == roi) {
ip.resetRoi();
return null;
}
ImageProcessor mask = roi.getMask();
if (null == mask)
return null;
ip.setMask(mask);
ip.setRoi(roi.getBounds());
return mask;
}
use of ij.ImagePlus in project TrakEM2 by trakem2.
the class PatchStack method setRoi.
public void setRoi(Rectangle r) {
if (null == r) {
killRoi();
return;
}
killRoi();
this.roi = new Roi(r.x, r.y, r.width, r.height);
this.roi.setImage(this);
ImagePlus imp = patch[currentSlice - 1].getProject().getLoader().fetchImagePlus(patch[currentSlice - 1]);
ImageProcessor ip = imp.getProcessor();
if (null != ip) {
ip.setMask(null);
ip.setRoi(r);
}
// draw(); // not needed
}
use of ij.ImagePlus in project TrakEM2 by trakem2.
the class PatchStack method trimProcessor.
public synchronized void trimProcessor() {
if (!locked) {
try {
ImagePlus imp = patch[currentSlice - 1].getProject().getLoader().fetchImagePlus(patch[currentSlice - 1]);
imp.trimProcessor();
} catch (Exception e) {
e.printStackTrace();
}
}
}
use of ij.ImagePlus in project TrakEM2 by trakem2.
the class PatchStack method createGray8Copy.
// 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 createGray8Copy() {
final Rectangle box = patch[0].getBoundingBox();
final int width = box.width;
final int height = box.height;
// compute minimum bounding box
ImageStack st = new ImageStack(width, height);
Loader loader = patch[0].getProject().getLoader();
for (int i = 1; i < patch.length; i++) {
loader.releaseToFit(width * height);
st.addSlice(Integer.toString(i), this.stack.getProcessor(i).convertToByte(true));
}
ImagePlus imp = new ImagePlus("byte", st);
imp.setCalibration(patch[0].getLayer().getParent().getCalibrationCopy());
// imp.getCalibration().pixelDepth = patch[0].getLayer().getThickness();
return imp;
}
Aggregations