use of ini.trakem2.display.Patch in project TrakEM2 by trakem2.
the class PatchStack method invertLookupTable.
public void invertLookupTable() {
Loader loader = patch[currentSlice - 1].getProject().getLoader();
ImagePlus imp = loader.fetchImagePlus(patch[currentSlice - 1]);
imp.getProcessor().invert();
Display.repaint(patch[currentSlice - 1].getLayer(), patch[currentSlice - 1], 0);
// TODO if the database updates are too much, then one could put a "save" button somewhere that shows as "unsaved" (red?) when there are unsaved changes.
patch[currentSlice - 1].updateInDatabase("tiff_working");
// just saved
imp.changes = false;
}
use of ini.trakem2.display.Patch 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 ini.trakem2.display.Patch 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;
}
use of ini.trakem2.display.Patch in project TrakEM2 by trakem2.
the class Blending method blendLayerWise.
public static final void blendLayerWise(final List<Layer> layers, final boolean respect_current_mask, final Filter<Patch> filter) {
for (final Layer layer : layers) {
final List<Patch> patches = layer.getAll(Patch.class);
final Set<Patch> s = new HashSet<Patch>();
if (null == filter) {
s.addAll(patches);
} else {
for (final Iterator<Patch> it = patches.iterator(); it.hasNext(); ) {
final Patch p = it.next();
if (filter.accept(p))
s.add(p);
}
}
blendPatches(s, respect_current_mask);
}
}
use of ini.trakem2.display.Patch in project TrakEM2 by trakem2.
the class Blending method blendPatches.
public static final void blendPatches(final Set<Patch> patches, final boolean respect_current_mask) {
ExecutorService exe = null;
try {
if (null == patches || patches.size() < 2)
return;
final Layer layer = patches.iterator().next().getLayer();
for (final Patch p : patches) {
if (null != p.getCoordinateTransform()) {
Utils.log("CANNOT blend: at least one image has a coordinate transform.\nBlending of coordinate-transformed images will be enabled in the near future.");
return;
}
if (p.getLayer() != layer) {
Utils.log("CANNOT blend: all images must belong to the same layer!\n Otherwise the overlap cannot be computed.");
return;
}
}
final HashMap<Patch, TransformMesh> meshes = new HashMap<Patch, TransformMesh>();
for (final Patch p : patches) {
meshes.put(p, null == p.getCoordinateTransform() ? null : new TransformMesh(p.getCoordinateTransform(), p.getMeshResolution(), p.getOWidth(), p.getOHeight()));
}
exe = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
final List<Future<?>> futures = Collections.synchronizedList(new ArrayList<Future<?>>());
final List<Future<?>> futures2 = Collections.synchronizedList(new ArrayList<Future<?>>());
// Cache the indices that determine overlap order within the layer
final HashMap<Patch, Integer> indices = new HashMap<Patch, Integer>();
int i = 0;
for (final Displayable d : layer.getDisplayables()) {
if (d.getClass() == Patch.class && patches.contains((Patch) d)) {
indices.put((Patch) d, i);
}
i += 1;
}
for (final Patch p : patches) {
if (Thread.currentThread().isInterrupted())
break;
futures.add(exe.submit(new Runnable() {
@Override
public void run() {
final int pLayerIndex = indices.get(p);
final Set<Patch> overlapping = new HashSet<Patch>();
for (final Patch op : patches) {
if (indices.get(op) < pLayerIndex)
overlapping.add(op);
}
if (setBlendingMask(p, overlapping, meshes, respect_current_mask)) {
futures2.add(p.updateMipMaps());
}
}
}, null));
}
// join all:
Utils.waitIfAlive(futures, false);
Utils.waitIfAlive(futures2, false);
} catch (final Exception e) {
IJError.print(e);
} finally {
if (null != exe)
exe.shutdown();
Display.repaint();
}
}
Aggregations