Search in sources :

Example 6 with Patch

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;
}
Also used : Loader(ini.trakem2.persistence.Loader) ImagePlus(ij.ImagePlus)

Example 7 with Patch

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;
}
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)

Example 8 with Patch

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

Example 9 with Patch

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);
    }
}
Also used : Layer(ini.trakem2.display.Layer) Patch(ini.trakem2.display.Patch) HashSet(java.util.HashSet)

Example 10 with Patch

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();
    }
}
Also used : Displayable(ini.trakem2.display.Displayable) HashMap(java.util.HashMap) Layer(ini.trakem2.display.Layer) NoninvertibleModelException(mpicbg.models.NoninvertibleModelException) NoninvertibleTransformException(java.awt.geom.NoninvertibleTransformException) ExecutorService(java.util.concurrent.ExecutorService) Future(java.util.concurrent.Future) Patch(ini.trakem2.display.Patch) TransformMesh(mpicbg.trakem2.transform.TransformMesh) HashSet(java.util.HashSet)

Aggregations

Patch (ini.trakem2.display.Patch)69 ArrayList (java.util.ArrayList)46 Layer (ini.trakem2.display.Layer)39 ImagePlus (ij.ImagePlus)34 Rectangle (java.awt.Rectangle)28 Point (mpicbg.models.Point)26 HashSet (java.util.HashSet)24 Displayable (ini.trakem2.display.Displayable)23 AffineTransform (java.awt.geom.AffineTransform)20 Loader (ini.trakem2.persistence.Loader)15 File (java.io.File)15 Future (java.util.concurrent.Future)15 NotEnoughDataPointsException (mpicbg.models.NotEnoughDataPointsException)15 PointMatch (mpicbg.models.PointMatch)14 Worker (ini.trakem2.utils.Worker)13 HashMap (java.util.HashMap)13 ExecutorService (java.util.concurrent.ExecutorService)12 ImageProcessor (ij.process.ImageProcessor)11 AffineModel2D (mpicbg.models.AffineModel2D)11 GenericDialog (ij.gui.GenericDialog)10