Search in sources :

Example 91 with ByteProcessor

use of ij.process.ByteProcessor in project GDSC-SMLM by aherbert.

the class PulseActivationAnalysis method drawLoop.

private void drawLoop(ImagePlus imp, Roi roi, int number) {
    if (!roi.isArea()) {
        return;
    }
    // Map the ROI to a crop of the results set
    final Rectangle roiBounds = roi.getBounds();
    final Rectangle resultsBounds = results.getBounds(true);
    // @formatter:off
    final Rectangle2D.Double r = new Rectangle2D.Double(resultsBounds.width * (double) roiBounds.x / imp.getWidth(), resultsBounds.height * (double) roiBounds.y / imp.getHeight(), // Since we output pixels map the width/height to the nearest pixel
    Math.ceil(resultsBounds.width * (double) roiBounds.width / imp.getWidth()), Math.ceil(resultsBounds.height * (double) roiBounds.height / imp.getHeight()));
    // @formatter:on
    final double x = r.getX();
    final double y = r.getY();
    final int magnification = getMagnification();
    // For each result set crop out the localisation and construct an overlay
    final Overlay o = new Overlay();
    for (int i = 0; i < output.length; i++) {
        final Color color = Settings.colors[i];
        // The first result is the memory results
        final MemoryPeakResults localResults = (MemoryPeakResults) output[i].getOutput(0);
        localResults.forEach(DistanceUnit.PIXEL, (XyrResultProcedure) (xx, yy, result) -> {
            if (r.contains(xx, yy)) {
                add(o, (xx - x) * magnification, (yy - y) * magnification, color);
            }
        });
    }
    // This results in a change of shape depending on where the roi is positioned
    int width = (int) r.getWidth();
    int height = (int) r.getHeight();
    width *= magnification;
    height *= magnification;
    final ImageProcessor ip = new ByteProcessor(width, height);
    final String loopTitle = imp.getTitle() + " Loop " + number;
    imp = WindowManager.getImage(loopTitle);
    if (imp == null) {
        imp = new ImagePlus(loopTitle, ip);
        imp.show();
    } else {
        imp.setProcessor(ip);
        imp.getWindow().toFront();
    }
    imp.setOverlay(o);
}
Also used : Color(java.awt.Color) Choice(java.awt.Choice) RandomUtils(uk.ac.sussex.gdsc.core.utils.rng.RandomUtils) ByteProcessor(ij.process.ByteProcessor) Calibration(uk.ac.sussex.gdsc.smlm.data.config.CalibrationProtos.Calibration) IdPeakResult(uk.ac.sussex.gdsc.smlm.results.IdPeakResult) ImageProcessor(ij.process.ImageProcessor) Rectangle2D(java.awt.geom.Rectangle2D) ResultsImageSettings(uk.ac.sussex.gdsc.smlm.data.config.ResultsProtos.ResultsImageSettings) ResultsSettings(uk.ac.sussex.gdsc.smlm.data.config.ResultsProtos.ResultsSettings) Future(java.util.concurrent.Future) ImageStatistics(ij.process.ImageStatistics) Pair(org.apache.commons.lang3.tuple.Pair) MemoryPeakResults(uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults) Optional(com.google.common.base.Optional) ContinuousUniformSampler(org.apache.commons.rng.sampling.distribution.ContinuousUniformSampler) ImageJImagePeakResults(uk.ac.sussex.gdsc.smlm.ij.results.ImageJImagePeakResults) PeakResults(uk.ac.sussex.gdsc.smlm.results.PeakResults) DiscreteSampler(org.apache.commons.rng.sampling.distribution.DiscreteSampler) NonBlockingExtendedGenericDialog(uk.ac.sussex.gdsc.core.ij.gui.NonBlockingExtendedGenericDialog) MathUtils(uk.ac.sussex.gdsc.core.utils.MathUtils) EnumSet(java.util.EnumSet) SettingsManager(uk.ac.sussex.gdsc.smlm.ij.settings.SettingsManager) XyrResultProcedure(uk.ac.sussex.gdsc.smlm.results.procedures.XyrResultProcedure) ExtendedGenericDialog(uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog) InputSource(uk.ac.sussex.gdsc.smlm.ij.plugins.ResultsManager.InputSource) PeakResultsList(uk.ac.sussex.gdsc.smlm.results.PeakResultsList) NotImplementedException(uk.ac.sussex.gdsc.core.data.NotImplementedException) DensityCounter(uk.ac.sussex.gdsc.core.clustering.DensityCounter) ResultsImageType(uk.ac.sussex.gdsc.smlm.data.config.ResultsProtos.ResultsImageType) OffsetPointRoi(uk.ac.sussex.gdsc.core.ij.gui.OffsetPointRoi) DistanceUnit(uk.ac.sussex.gdsc.smlm.data.config.UnitProtos.DistanceUnit) Logger(java.util.logging.Logger) ConcurrencyUtils(uk.ac.sussex.gdsc.core.utils.concurrent.ConcurrencyUtils) TextUtils(uk.ac.sussex.gdsc.core.utils.TextUtils) Plot(ij.gui.Plot) Executors(java.util.concurrent.Executors) CentroidMethod(uk.ac.sussex.gdsc.smlm.results.Cluster.CentroidMethod) CalibrationHelper(uk.ac.sussex.gdsc.smlm.data.config.CalibrationHelper) ImagePlus(ij.ImagePlus) SimpleArrayUtils(uk.ac.sussex.gdsc.core.utils.SimpleArrayUtils) SharedStateContinuousSampler(org.apache.commons.rng.sampling.distribution.SharedStateContinuousSampler) ShapeRoi(ij.gui.ShapeRoi) PlugIn(ij.plugin.PlugIn) Roi(ij.gui.Roi) CompositeImage(ij.CompositeImage) IntStream(java.util.stream.IntStream) Rectangle(java.awt.Rectangle) TraceManager(uk.ac.sussex.gdsc.smlm.results.TraceManager) Prefs(ij.Prefs) WindowManager(ij.WindowManager) PeakResult(uk.ac.sussex.gdsc.smlm.results.PeakResult) AtomicReference(java.util.concurrent.atomic.AtomicReference) Level(java.util.logging.Level) PointRoi(ij.gui.PointRoi) AWTEvent(java.awt.AWTEvent) Trace(uk.ac.sussex.gdsc.smlm.results.Trace) UnitSphereSampler(org.apache.commons.rng.sampling.UnitSphereSampler) Molecule(uk.ac.sussex.gdsc.core.clustering.DensityCounter.Molecule) ImagePeakResultsFactory(uk.ac.sussex.gdsc.smlm.ij.results.ImagePeakResultsFactory) GenericDialog(ij.gui.GenericDialog) Overlay(ij.gui.Overlay) ExecutorService(java.util.concurrent.ExecutorService) UniformRandomProvider(org.apache.commons.rng.UniformRandomProvider) ResultsImageSizeMode(uk.ac.sussex.gdsc.smlm.data.config.ResultsProtos.ResultsImageSizeMode) Checkbox(java.awt.Checkbox) Window(java.awt.Window) SplittableUniformRandomProvider(uk.ac.sussex.gdsc.core.utils.rng.SplittableUniformRandomProvider) ResultsImageMode(uk.ac.sussex.gdsc.smlm.data.config.ResultsProtos.ResultsImageMode) Recorder(ij.plugin.frame.Recorder) SamplerUtils(uk.ac.sussex.gdsc.core.utils.rng.SamplerUtils) ActionEvent(java.awt.event.ActionEvent) ImageJUtils(uk.ac.sussex.gdsc.core.ij.ImageJUtils) IJ(ij.IJ) ImageStack(ij.ImageStack) PeakResultStoreList(uk.ac.sussex.gdsc.smlm.results.PeakResultStoreList) NormalizedGaussianSampler(org.apache.commons.rng.sampling.distribution.NormalizedGaussianSampler) LocalList(uk.ac.sussex.gdsc.core.utils.LocalList) UniformRandomProviders(uk.ac.sussex.gdsc.core.utils.rng.UniformRandomProviders) ByteProcessor(ij.process.ByteProcessor) Color(java.awt.Color) Rectangle(java.awt.Rectangle) Rectangle2D(java.awt.geom.Rectangle2D) ImagePlus(ij.ImagePlus) ImageProcessor(ij.process.ImageProcessor) MemoryPeakResults(uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults) Overlay(ij.gui.Overlay)

Example 92 with ByteProcessor

use of ij.process.ByteProcessor in project GDSC-SMLM by aherbert.

the class ImageConverterTest method createData.

private static Object createData(RandomSeed seed) {
    final UniformRandomProvider r = RngUtils.create(seed.getSeed());
    final ByteProcessor bp = new ByteProcessor(w, h);
    final ImageConverterTestData data = new ImageConverterTestData();
    data.bdata = (byte[]) bp.getPixels();
    data.sdata = new short[data.bdata.length];
    data.fdata = new float[data.bdata.length];
    for (int i = 0; i < bp.getPixelCount(); i++) {
        final int value = r.nextInt(256);
        bp.set(i, value);
        data.fdata[i] = data.sdata[i] = (short) value;
    }
    return data;
}
Also used : ByteProcessor(ij.process.ByteProcessor) UniformRandomProvider(org.apache.commons.rng.UniformRandomProvider)

Example 93 with ByteProcessor

use of ij.process.ByteProcessor in project imagingbook-common by imagingbook.

the class KMeansClusteringQuantizerApache method main.

// ----------------------------------------------------------------------
public static void main(String[] args) {
    // String path = "D:/svn-book/Book/img/ch-color-images/alps-01s.png";
    // String path = "D:/svn-book/Book/img/ch-color-images/desaturation-hsv/balls.jpg";
    String path = "C:/_SVN/svn-book/Book/img/ch-color-images/desaturation-hsv/balls.jpg";
    // String path = "D:/svn-book/Book/img/ch-color-images/single-color.png";
    // String path = "D:/svn-book/Book/img/ch-color-images/two-colors.png";
    // String path = "D:/svn-book/Book/img/ch-color-images/random-colors.png";
    // String path = "D:/svn-book/Book/img/ch-color-images/ramp-fire.png";
    int K = 16;
    System.out.println("image = " + path);
    System.out.println("K = " + K);
    ImagePlus im = IJ.openImage(path);
    if (im == null) {
        System.out.println("could not open: " + path);
        return;
    }
    ImageProcessor ip = im.getProcessor();
    ColorProcessor cp = ip.convertToColorProcessor();
    Parameters params = new Parameters();
    params.maxColors = K;
    ColorQuantizer quantizer = new KMeansClusteringQuantizerApache(cp, params);
    quantizer.listColorMap();
    System.out.println("quantizing image");
    ByteProcessor qi = quantizer.quantize(cp);
    System.out.println("showing image");
    (new ImagePlus("quantizez", qi)).show();
}
Also used : ByteProcessor(ij.process.ByteProcessor) ImageProcessor(ij.process.ImageProcessor) ColorProcessor(ij.process.ColorProcessor) ImagePlus(ij.ImagePlus) DoublePoint(org.apache.commons.math3.ml.clustering.DoublePoint)

Example 94 with ByteProcessor

use of ij.process.ByteProcessor in project imagingbook-common by imagingbook.

the class CannyEdgeDetector method detectAndTraceEdges.

private void detectAndTraceEdges() {
    if (Enms == null) {
        nonMaxSuppression();
    }
    Ebin = new ByteProcessor(M, N);
    int color = 255;
    edgeTraces = new ArrayList<>();
    for (int v = 0; v < N; v++) {
        for (int u = 0; u < M; u++) {
            if (Enms.getf(u, v) >= params.hiThr && Ebin.get(u, v) == 0) {
                // unmarked edge point
                EdgeTrace trace = traceAndThreshold(u, v, (float) params.loThr, color);
                edgeTraces.add(trace);
            }
        }
    }
}
Also used : ByteProcessor(ij.process.ByteProcessor) Point(java.awt.Point)

Example 95 with ByteProcessor

use of ij.process.ByteProcessor in project imagingbook-common by imagingbook.

the class ColorQuantizer method quantize.

// ---------------------------------------------------------------
/**
 * Performs color quantization on the given full-color RGB image
 * and creates an indexed color image.
 *
 * @param cp The original full-color RGB image.
 * @return The quantized (indexed color) image.
 */
public default ByteProcessor quantize(ColorProcessor cp) {
    float[][] colormap = this.getColorMap();
    if (colormap.length > 256)
        throw new RuntimeException("cannot index to more than 256 colors");
    int w = cp.getWidth();
    int h = cp.getHeight();
    int[] rgbPixels = (int[]) cp.getPixels();
    byte[] idxPixels = new byte[rgbPixels.length];
    for (int i = 0; i < rgbPixels.length; i++) {
        idxPixels[i] = (byte) findColorIndex(rgbPixels[i], colormap);
    }
    IndexColorModel idxCm = makeIndexColorModel(colormap);
    return new ByteProcessor(w, h, idxPixels, idxCm);
}
Also used : ByteProcessor(ij.process.ByteProcessor) IndexColorModel(java.awt.image.IndexColorModel)

Aggregations

ByteProcessor (ij.process.ByteProcessor)103 ImagePlus (ij.ImagePlus)36 ImageProcessor (ij.process.ImageProcessor)31 FloatProcessor (ij.process.FloatProcessor)23 ShortProcessor (ij.process.ShortProcessor)21 ColorProcessor (ij.process.ColorProcessor)20 ArrayList (java.util.ArrayList)13 Point (java.awt.Point)12 Rectangle (java.awt.Rectangle)11 Roi (ij.gui.Roi)10 AffineTransform (java.awt.geom.AffineTransform)10 ImageStack (ij.ImageStack)9 Patch (ini.trakem2.display.Patch)9 Calibration (ij.measure.Calibration)8 Pair (mpicbg.trakem2.util.Pair)7 Color (java.awt.Color)6 LUT (ij.process.LUT)5 BufferedImage (java.awt.image.BufferedImage)5 IOException (java.io.IOException)5 CoordinateTransformMesh (mpicbg.models.CoordinateTransformMesh)5