本文整理汇总了Java中ij.gui.OvalRoi类的典型用法代码示例。如果您正苦于以下问题:Java OvalRoi类的具体用法?Java OvalRoi怎么用?Java OvalRoi使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
OvalRoi类属于ij.gui包,在下文中一共展示了OvalRoi类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: writeOverlay
import ij.gui.OvalRoi; //导入依赖的package包/类
/** Write an overlay, if supported */
private void writeOverlay(
XMLStreamWriter xsw,
Roi roi)
throws SlideSetException {
if(roi instanceof Line)
writeLine(xsw, (Line) roi);
else if(roi instanceof OvalRoi)
writeOvalRoi(xsw, (OvalRoi) roi);
else if(roi instanceof PointRoi)
writePointRoi(xsw, (PointRoi) roi);
else if(roi instanceof PolygonRoi)
writePolygonRoi(xsw, (PolygonRoi) roi);
else if(roi instanceof ShapeRoi)
writeShapeRoi(xsw, (ShapeRoi) roi);
else if(roi.getType() == Roi.RECTANGLE)
writeRectangle(xsw, roi);
else
throw new UnsupportedOverlayException(
"Unsupported ROI type: "
+ roi.getClass().getName());
}
示例2: writeOvalRoi
import ij.gui.OvalRoi; //导入依赖的package包/类
/** Write an OvalRoi */
private void writeOvalRoi(
final XMLStreamWriter xsw,
final OvalRoi roi)
throws SlideSetException {
final double rx = roi.getFloatWidth()/2;
final double ry = roi.getFloatHeight()/2;
final double x = roi.getXBase();
final double y = roi.getYBase();
try {
xsw.writeStartElement("ellipse");
xsw.writeAttribute("class", "roi OvalRoi");
xsw.writeAttribute("cx",
String.valueOf(x+rx));
xsw.writeAttribute("cy",
String.valueOf(y+ry));
xsw.writeAttribute("rx",
String.valueOf(rx));
xsw.writeAttribute("ry",
String.valueOf(ry));
applyDefaultStyles(xsw);
xsw.writeEndElement();
} catch(Exception e) {
throw new SlideSetException(e);
}
}
示例3: makeEllipseOverlay
import ij.gui.OvalRoi; //导入依赖的package包/类
/** Generate an ROI from parsed ellipse data */
private Roi makeEllipseOverlay(
double cx, double cy,
double rx, double ry, Element element)
throws SVGParseException {
double[] c = {cx, cy};
double[] n = {cx, cy + ry};
double[] e = {cx + rx, cy};
double[] s = {cx, cy - ry};
double[] w = {cx - rx, cy};
c = transformToDocumentSpace(c, element);
n = transformToDocumentSpace(n, element);
e = transformToDocumentSpace(e, element);
s = transformToDocumentSpace(s, element);
w = transformToDocumentSpace(w, element);
if(n[0] != s[0] || e[1] != w[1]
|| Math.abs((4 * c[0]) / (n[0] + e[0] + s[0] + w[0]) - 1) > 2*Math.ulp(c[0])
|| Math.abs((4 * c[1]) / (n[1] + e[1] + s[1] + w[1]) - 1) > 2*Math.ulp(c[1]))
throw new SVGParseException("Can't create ROI from skewed or rotated ellipse");
EllipseOverlay eo = new EllipseOverlay(ij);
return new OvalRoi(w[0], s[1], 2*Math.abs(e[0] - c[0]), 2*Math.abs(n[1] - c[1]));
}
示例4: paint
import ij.gui.OvalRoi; //导入依赖的package包/类
/** Paints an approximation of the pipe into the set of slices. */
static public void paint(final Pipe pipe, final Map<Layer,ImageProcessor> slices, final int value, final float scale) {
final VectorString3D vs = pipe.asVectorString3D();
vs.resample(1); // one pixel
final double[] px = vs.getPoints(0);
final double[] py = vs.getPoints(1);
final double[] pz = vs.getPoints(2);
final double[] pr = vs.getDependent(0);
// For each point
for (int i=0; i<px.length-1; i++) {
final ImageProcessor ip = slices.get(pipe.getLayerSet().getNearestLayer(pz[i]));
if (null == ip) continue;
final OvalRoi ov = new OvalRoi((int)((px[i] - pr[i]) * scale),
(int)((py[i] - pr[i]) * scale),
(int)(pr[i]*2*scale), (int)(pr[i]*2*scale));
ip.setRoi(ov);
ip.setValue(value);
ip.fill(ip.getMask());
}
}
示例5: addToRoiManager
import ij.gui.OvalRoi; //导入依赖的package包/类
/**
* Add series of circular ROIs to the ROI Manager based on the centre and
* radius of a sphere
*
* @param imp Needed for decalibration of calibrated (x,y,z) r values
* @param roiMan Instance of the ROI Manager i.e. RoiManager.getInstance().
* @param sphereDim calibrated centroid (x, y, z) and radius
* @param clearRois empty ROI manager before adding the ROIs.
* @throws IllegalArgumentException if roiMan is null, rather than
* instantiating RoiManager.
*/
public static void addToRoiManager(final ImagePlus imp, final RoiManager roiMan, final double[] sphereDim,
final boolean clearRois) throws IllegalArgumentException {
if (roiMan == null)
throw new IllegalArgumentException("ROI Manager has not been instantiated");
if (clearRois) {
RoiMan.deleteAll(roiMan);
}
final Calibration cal = imp.getCalibration();
final double xs = sphereDim[0];
final int xi = (int) (xs / cal.pixelWidth);
final double ys = sphereDim[1];
final int yi = (int) (ys / cal.pixelHeight);
final double r = sphereDim[3];
final int zc = (int) Math.round(sphereDim[2] / cal.pixelDepth);
final int rz = (int) Math.round(r / cal.pixelDepth);
final int zStart = Math.max(zc - rz, 1);
final int zEnd = Math.min(zc + rz, imp.getImageStackSize());
for (int z = zStart; z <= zEnd; z++) { // iterate through z slices
final double zd = (zc - z) * cal.pixelDepth;
final double rc = Math.sqrt(r * r - zd * zd);
final int wi = (int) (rc / cal.pixelWidth);
final int hi = (int) (rc / cal.pixelHeight);
final OvalRoi ellipse = new OvalRoi(xi - wi, yi - hi, wi * 2, hi * 2);
ellipse.setPosition(z);
roiMan.addRoi(ellipse);
}
}
示例6: makeOval
import ij.gui.OvalRoi; //导入依赖的package包/类
/** Creates an oval selection. Removes any existing
selection if width or height are less than 1. */
public static void makeOval(int x, int y, int width, int height) {
if (width<=0 || height<0)
getImage().killRoi();
else {
ImagePlus img = getImage();
img.setRoi(new OvalRoi(x, y, width, height));
}
}
示例7: parseCircle
import ij.gui.OvalRoi; //导入依赖的package包/类
/** Generate an ROI from a {@code circle} element */
private OvalRoi parseCircle(Element n) throws SVGParseException {
if(!"circle".equals(n.getTagName()))
throw new SVGParseException("\'circle\' expected, but \'" + n.getLocalName() + "\' found.");
double cx, cy, r;
try {
cx = parseLength(n.getAttribute("cx"));
cy = parseLength(n.getAttribute("cy"));
r = parseLength(n.getAttribute("r"));
} catch(NumberFormatException e) {
throw new SVGParseException("Bad number format in ellipse", e);
}
return new OvalRoi(cx, cy, r*2, r*2);
}
示例8: makeBrush
import ij.gui.OvalRoi; //导入依赖的package包/类
/** This method could get tones of improvement, which should be pumped upstream into ImageJ's RoiBrush class which is creating it at every while(true) {} iteration!!!
* The returned area has its coordinates centered around 0,0
*/
static public Area makeBrush(int diameter, double mag) {
if (diameter < 1) return null;
if (mag >= 1) return new Area(new OvalRoi(-diameter/2, -diameter/2, diameter, diameter).getPolygon());
// else, create a smaller brush and transform it up, i.e. less precise, less points to store -but precision matches what the eye sees, and allows for much better storage -less points.
int screen_diameter = (int)(diameter * mag);
if (0 == screen_diameter) return null; // can't paint at this mag with this diameter
Area brush = new Area(new OvalRoi(-screen_diameter/2, -screen_diameter/2, screen_diameter, screen_diameter).getPolygon());
// scale to world coordinates
AffineTransform at = new AffineTransform();
at.scale(1/mag, 1/mag);
return brush.createTransformedArea(at);
// smooth out edges
/*
Polygon pol = new OvalRoi(-diameter/2, -diameter/2, diameter, diameter).getPolygon();
Polygon pol2 = new Polygon();
// cheap and fast: skip every other point, since all will be square angles
for (int i=0; i<pol.npoints; i+=2) {
pol2.addPoint(pol.xpoints[i], pol.ypoints[i]);
}
return new Area(pol2);
// the above works nice, but then the fill and fill-remove don't work properly (there are traces in the edges)
// Needs a workround: before adding/substracting, enlarge the polygon to have square edges
*/
}
示例9: convertToOvalROI
import ij.gui.OvalRoi; //导入依赖的package包/类
public static OvalRoi convertToOvalROI(EllipseROI pathOval, double xOrigin, double yOrigin, double downsampleFactor) {
Rectangle2D bounds = getTransformedBounds(pathOval, xOrigin, yOrigin, downsampleFactor);
return setIJRoiProperties(new OvalRoi(bounds.getX(), bounds.getY(), bounds.getWidth(), bounds.getHeight()), pathOval);
}
示例10: run
import ij.gui.OvalRoi; //导入依赖的package包/类
@Override
public void run(String arg) {
// Open an image
String path = "/home/bene/PhD/brains/template.tif";
ImagePlus imp = IJ.openImage(path);
new StackConverter(imp).convertToGray8();
// Create a universe and show it
Image3DUniverse univ = new Image3DUniverse();
univ.show();
univ.rotateY(30 * Math.PI / 180);
// Add the image as a volume
Content c = univ.addVoltex(imp);
sleep(5);
// Retrieve the VoltexGroup
VoltexGroup voltex = (VoltexGroup)c.getContent();
// Define a ROI
Roi roi = new OvalRoi(240, 220, 70, 50);
// Define a fill color
byte fillValue = (byte)100;
// Fill the part of the volume which results from the
// projection of the polygon onto the volume:
voltex.fillRoi(univ.getCanvas(), roi, fillValue);
sleep(5);
// This can be optimally used for deleting some parts of
// the volume:
fillValue = (byte)0;
roi.setLocation(150, 150);
voltex.fillRoi(univ.getCanvas(), roi, fillValue);
sleep(5);
// The internal image is changed, too:
imp.show();
}