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