Search in sources :

Example 1 with Position

use of net.imagej.Position in project imagej-ui-swing by imagej.

the class DefaultJHotDrawAdapter method updateFigure.

@Override
public void updateFigure(final OverlayView overlay, final ImageFigure figure) {
    super.updateFigure(overlay, figure);
    // Override the base: set the fill color to transparent.
    figure.set(AttributeKeys.FILL_COLOR, new Color(0, 0, 0, 0));
    final RegionOfInterest roi = overlay.getData().getRegionOfInterest();
    if (roi != null) {
        final long minX = (long) Math.floor(roi.realMin(0));
        final long maxX = (long) Math.ceil(roi.realMax(0)) + 1;
        final long minY = (long) Math.floor(roi.realMin(1));
        final long maxY = (long) Math.ceil(roi.realMax(1)) + 1;
        final ColorRGB color = overlay.getData().getFillColor();
        final IndexColorModel cm = new IndexColorModel(1, 2, new byte[] { 0, (byte) color.getRed() }, new byte[] { 0, (byte) color.getGreen() }, new byte[] { 0, (byte) color.getBlue() }, new byte[] { 0, (byte) overlay.getData().getAlpha() });
        final int w = (int) (maxX - minX);
        final int h = (int) (maxY - minY);
        final BufferedImage img = new BufferedImage(w, h, BufferedImage.TYPE_BYTE_INDEXED, cm);
        final SampleModel sm = new SinglePixelPackedSampleModel(DataBuffer.TYPE_BYTE, w, h, new int[] { 1 });
        final DataBuffer dbuncast = sm.createDataBuffer();
        assert dbuncast instanceof DataBufferByte;
        final DataBufferByte db = (DataBufferByte) dbuncast;
        final byte[] bankData = db.getData();
        final RealRandomAccess<BitType> ra = roi.realRandomAccess();
        final Position planePos = overlay.getPlanePosition();
        for (int i = 0; i < planePos.numDimensions(); i++) {
            final long position = planePos.getLongPosition(i);
            ra.setPosition(position, i + 2);
        }
        int index = 0;
        for (int j = 0; j < h; j++) {
            ra.setPosition(minY + j, 1);
            for (int i = 0; i < w; i++) {
                ra.setPosition(minX + i, 0);
                if (ra.get().get())
                    bankData[index] = -1;
                index++;
            }
        }
        final Raster raster = Raster.createRaster(sm, db, new java.awt.Point(0, 0));
        img.setData(raster);
        figure.setBounds(new Rectangle2D.Double(minX, minY, w, h));
        figure.setBufferedImage(img);
    }
}
Also used : RegionOfInterest(net.imglib2.roi.RegionOfInterest) Position(net.imagej.Position) Color(java.awt.Color) Raster(java.awt.image.Raster) SinglePixelPackedSampleModel(java.awt.image.SinglePixelPackedSampleModel) Rectangle2D(java.awt.geom.Rectangle2D) DataBufferByte(java.awt.image.DataBufferByte) BufferedImage(java.awt.image.BufferedImage) SampleModel(java.awt.image.SampleModel) SinglePixelPackedSampleModel(java.awt.image.SinglePixelPackedSampleModel) ColorRGB(org.scijava.util.ColorRGB) BitType(net.imglib2.type.logic.BitType) IndexColorModel(java.awt.image.IndexColorModel) DataBuffer(java.awt.image.DataBuffer)

Example 2 with Position

use of net.imagej.Position in project imagej-plugins-commands by imagej.

the class XYFlipper method process.

/**
 * Fills the output image from the input image doing coordinate
 * transformations as needed
 */
@Override
public boolean process() {
    final Img<? extends RealType<?>> inputImage = dataset.getImgPlus();
    inputAccessor = inputImage.randomAccess();
    outputAccessor = outputImage.randomAccess();
    final long width = inputDimensions[0];
    final long height = inputDimensions[1];
    long rx, ry, rw, rh;
    if (flipper.isShapePreserving() && (bounds.width > 0) && (bounds.height > 0)) {
        rx = (long) bounds.x;
        ry = (long) bounds.y;
        rw = (long) bounds.width;
        rh = (long) bounds.height;
    } else {
        rx = 0;
        ry = 0;
        rw = width;
        rh = height;
    }
    final long[] planeDims = new long[inputImage.numDimensions() - 2];
    for (int i = 0; i < planeDims.length; i++) planeDims[i] = inputDimensions[i + 2];
    final Extents extents = new Extents(planeDims);
    final Position planePos = extents.createPosition();
    if (planeDims.length == 0) {
        // 2d Dataset
        processPlane(planePos, rx, ry, rw, rh);
    } else {
        // more than two dimensions
        while (planePos.hasNext()) {
            planePos.fwd();
            processPlane(planePos, rx, ry, rw, rh);
        }
    }
    return true;
}
Also used : Position(net.imagej.Position) Extents(net.imagej.Extents)

Example 3 with Position

use of net.imagej.Position in project imagej-plugins-commands by imagej.

the class ShowLUTAsTable method run.

// -- Command methods --
@Override
public void run() {
    final DatasetView view = imgDispService.getActiveDatasetView(display);
    final List<ColorTable> colorTables = view.getColorTables();
    final Position planePos = view.getPlanePosition();
    long pos = planePos.getIndex();
    if (pos < 0 || pos >= colorTables.size())
        pos = 0;
    final ColorTable colorTable = colorTables.get((int) pos);
    final int rowCount = colorTable.getLength();
    final int componentCount = colorTable.getComponentCount();
    final int colCount = componentCount + 1;
    table = new DefaultResultsTable(colCount, rowCount);
    table.setColumnHeader(0, "Index");
    // use here.
    for (int x = 0; x < componentCount; x++) {
        table.setColumnHeader(x + 1, "CH" + x);
    }
    // fill in values
    for (int y = 0; y < rowCount; y++) {
        table.setValue(0, y, y);
        for (int x = 0; x < componentCount; x++) {
            final double value = colorTable.get(x, y);
            table.setValue(x + 1, y, value);
        }
    }
}
Also used : DatasetView(net.imagej.display.DatasetView) DefaultResultsTable(net.imagej.table.DefaultResultsTable) Position(net.imagej.Position) ColorTable(net.imglib2.display.ColorTable)

Example 4 with Position

use of net.imagej.Position in project imagej-plugins-commands by imagej.

the class AddNoiseToDataValues method run.

// -- public interface --
@Override
public void run() {
    Dataset dataset = displayService.getActiveDataset(display);
    Overlay overlay = overlayService.getActiveOverlay(display);
    DatasetView view = displayService.getActiveDatasetView(display);
    Position planePos = (allPlanes) ? null : view.getPlanePosition();
    NoiseAdder<T> noiseAdder = new NoiseAdder<T>(dataset, overlay, planePos);
    noiseAdder.setStdDev(25.0);
    noiseAdder.run();
}
Also used : DatasetView(net.imagej.display.DatasetView) Position(net.imagej.Position) Dataset(net.imagej.Dataset) Overlay(net.imagej.overlay.Overlay)

Example 5 with Position

use of net.imagej.Position in project imagej-plugins-commands by imagej.

the class AddSpecifiedNoiseToDataValues method run.

// -- public interface --
@Override
public void run() {
    Dataset dataset = displayService.getActiveDataset(display);
    Overlay overlay = overlayService.getActiveOverlay(display);
    DatasetView view = displayService.getActiveDatasetView(display);
    Position planePos = (allPlanes) ? null : view.getPlanePosition();
    NoiseAdder<T> noiseAdder = new NoiseAdder<T>(dataset, overlay, planePos);
    noiseAdder.setStdDev(stdDev);
    noiseAdder.run();
}
Also used : DatasetView(net.imagej.display.DatasetView) Position(net.imagej.Position) Dataset(net.imagej.Dataset) Overlay(net.imagej.overlay.Overlay)

Aggregations

Position (net.imagej.Position)11 Extents (net.imagej.Extents)5 DatasetView (net.imagej.display.DatasetView)4 Overlay (net.imagej.overlay.Overlay)3 Dataset (net.imagej.Dataset)2 Color (java.awt.Color)1 Rectangle2D (java.awt.geom.Rectangle2D)1 BufferedImage (java.awt.image.BufferedImage)1 DataBuffer (java.awt.image.DataBuffer)1 DataBufferByte (java.awt.image.DataBufferByte)1 IndexColorModel (java.awt.image.IndexColorModel)1 Raster (java.awt.image.Raster)1 SampleModel (java.awt.image.SampleModel)1 SinglePixelPackedSampleModel (java.awt.image.SinglePixelPackedSampleModel)1 Random (java.util.Random)1 DefaultResultsTable (net.imagej.table.DefaultResultsTable)1 ColorTable (net.imglib2.display.ColorTable)1 UVInsideRoiCondition (net.imglib2.ops.condition.UVInsideRoiCondition)1 RegionOfInterest (net.imglib2.roi.RegionOfInterest)1 BitType (net.imglib2.type.logic.BitType)1