本文整理汇总了Java中ij.gui.PolygonRoi类的典型用法代码示例。如果您正苦于以下问题:Java PolygonRoi类的具体用法?Java PolygonRoi怎么用?Java PolygonRoi使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PolygonRoi类属于ij.gui包,在下文中一共展示了PolygonRoi类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: labelsToFilledROIs
import ij.gui.PolygonRoi; //导入依赖的package包/类
/**
* Convert a labelled image into a list of PolygonRois by tracing.
* Note that labels are assumed not to contain any holes or nested ROIs; ROIs produced by this command will not contain holes.
* Some entries in the resulting array may be null if this is not the case, or if not all labels are found.
* Otherwise, pixels with the integer label L will belong to the Roi in the output array at entry L-1
*
* @param ipLabels
* @param n - maximum number of labels
* @return
*/
public static PolygonRoi[] labelsToFilledROIs(ImageProcessor ipLabels, int n) {
PolygonRoi[] rois = new PolygonRoi[n];
int w = ipLabels.getWidth();
int h = ipLabels.getHeight();
ByteProcessor bpCompleted = new ByteProcessor(w, h);
bpCompleted.setValue(255);
for (int y = 0; y < h; y++) {
for (int x = 0; x < w; x++) {
if (bpCompleted.get(x, y) != 0)
continue;
float val = ipLabels.getf(x, y);
if (val > 0 && val <= n) {
Wand wand = new Wand(ipLabels);
wand.autoOutline(x, y, val, val, Wand.EIGHT_CONNECTED);
PolygonRoi roi = wandToRoi(wand);
rois[(int)val-1] = roi;
bpCompleted.fill(roi);
}
}
}
return rois;
}
示例2: labelsToFilledRoiList
import ij.gui.PolygonRoi; //导入依赖的package包/类
/**
* Convert a labelled image into a list of PolygonRois by tracing.
*
* Unlike labelsToFilledROIs, the order in which ROIs are returned is arbitrary.
*
* Also, the multiple Rois may be created for the same label, if unconnected regions are used.
*
* @param ipLabels
* @param n - maximum number of labels
* @return
*/
public static List<PolygonRoi> labelsToFilledRoiList(final ImageProcessor ipLabels, final boolean conn8) {
List<PolygonRoi> rois = new ArrayList<>();
int w = ipLabels.getWidth();
int h = ipLabels.getHeight();
ByteProcessor bpCompleted = new ByteProcessor(w, h);
bpCompleted.setValue(255);
for (int y = 0; y < h; y++) {
for (int x = 0; x < w; x++) {
if (bpCompleted.get(x, y) != 0)
continue;
float val = ipLabels.getf(x, y);
if (val > 0) {
Wand wand = new Wand(ipLabels);
wand.autoOutline(x, y, val, val, conn8 ? Wand.EIGHT_CONNECTED : Wand.FOUR_CONNECTED);
PolygonRoi roi = wandToRoi(wand);
rois.add(roi);
bpCompleted.fill(roi);
}
}
}
return rois;
}
示例3: convertToPathROI
import ij.gui.PolygonRoi; //导入依赖的package包/类
/**
* Create a ROI from an ImageJ Roi.
*
* @param pathROI
* @param pathImage
* @return
*/
public static ROI convertToPathROI(Roi roi, Calibration cal, double downsampleFactor, final int c, final int z, final int t) {
// if (roi.getType() == Roi.POLYGON || roi.getType() == Roi.TRACED_ROI)
// return convertToPolygonROI((PolygonRoi)roi, cal, downsampleFactor);
if (roi.getType() == Roi.RECTANGLE && roi.getCornerDiameter() == 0)
return getRectangleROI(roi, cal, downsampleFactor, c, z, t);
if (roi.getType() == Roi.OVAL)
return convertToEllipseROI(roi, cal, downsampleFactor, c, z, t);
if (roi instanceof Line)
return convertToLineROI((Line)roi, cal, downsampleFactor, c, z, t);
if (roi instanceof PointRoi)
return convertToPointROI((PolygonRoi)roi, cal, downsampleFactor, c, z, t);
// if (roi instanceof ShapeRoi)
// return convertToAreaROI((ShapeRoi)roi, cal, downsampleFactor);
// // Shape ROIs should be able to handle most eventualities
if (roi instanceof ShapeRoi)
return convertToAreaROI((ShapeRoi)roi, cal, downsampleFactor, c, z, t);
if (roi.isArea())
return convertToPolygonOrAreaROI(roi, cal, downsampleFactor, c, z, t);
// TODO: Integrate ROI not supported exception...?
return null;
}
示例4: writeOverlay
import ij.gui.PolygonRoi; //导入依赖的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());
}
示例5: writePolygonRoi
import ij.gui.PolygonRoi; //导入依赖的package包/类
/** Write a PolygonRoi */
private void writePolygonRoi(
final XMLStreamWriter xsw,
final PolygonRoi roi)
throws SlideSetException {
final FloatPolygon fp = roi.getFloatPolygon();
try {
if(roi.getType() == Roi.POLYGON)
xsw.writeStartElement("polygon");
else
xsw.writeStartElement("polyline");
xsw.writeAttribute("class", "roi PolygonRoi");
String coords = "";
for(int i=0; i < fp.npoints; i++) {
coords += String.valueOf(
fp.xpoints[i]) +
"," + String.valueOf(
fp.ypoints[i]) + " ";
}
xsw.writeAttribute("points", coords);
applyDefaultStyles(xsw);
xsw.writeEndElement();
} catch(Exception e) {
throw new SlideSetException(e);
}
}
示例6: parsePolyline
import ij.gui.PolygonRoi; //导入依赖的package包/类
/** Generate an ROI from a {@code polyline} element */
private PolygonRoi parsePolyline(Element n) throws SVGParseException {
if(!"polyline".equals(n.getTagName()))
throw new SVGParseException("\'polyline\' expected, but \'" + n.getLocalName() + "\' found.");
String points = n.getAttribute("points");
ArrayList<double[]> pts;
try {
pts = parseListOfPoints(points);
} catch(NumberFormatException e) {
throw new SVGParseException("Bad list of points in polyline: " + points, e);
}
if(pts.isEmpty())
return null;
final float[] xs = new float[pts.size()];
final float[] ys = new float[pts.size()];
double[] pt = transformToDocumentSpace(pts.get(0), n);
xs[0] = (float) pt[0];
ys[0] = (float) pt[1];
for(int i = 1; i < pts.size(); i++) {
pt = transformToDocumentSpace(pts.get(i), n);
xs[i] = (float) pt[0];
ys[i] = (float) pt[1];
}
return new PolygonRoi(xs, ys, PolygonRoi.POLYLINE);
}
示例7: parsePolygon
import ij.gui.PolygonRoi; //导入依赖的package包/类
/** Generate an ROI from a {@code polygon} element */
private PolygonRoi parsePolygon(Element n) throws SVGParseException {
if(!"polygon".equals(n.getTagName()))
throw new SVGParseException("\'polygon\' expected, but \'" + n.getLocalName() + "\' found.");
String points = n.getAttribute("points");
ArrayList<double[]> pts;
try {
pts = parseListOfPoints(points);
} catch(NumberFormatException e) {
throw new SVGParseException("Bad points list: " + points, e);
}
if(pts.isEmpty())
return null;
final float[] xs = new float[pts.size()];
final float[] ys = new float[pts.size()];
double[] pt = transformToDocumentSpace(pts.get(0), n);
xs[0] = (float) pt[0];
ys[0] = (float) pt[1];
for(int i = 1; i < pts.size(); i++) {
pt = transformToDocumentSpace(pts.get(i), n);
xs[i] = (float) pt[0];
ys[i] = (float) pt[1];
}
return new PolygonRoi(xs, ys, PolygonRoi.POLYGON);
}
示例8: createRoi
import ij.gui.PolygonRoi; //导入依赖的package包/类
private Roi createRoi(ConvexHull hull, boolean forcePolygon)
{
// Convert the Hull to the correct image scale.
float[] x2 = hull.x.clone();
float[] y2 = hull.y.clone();
for (int i = 0; i < x2.length; i++)
{
x2[i] = image.mapX(x2[i]);
y2[i] = image.mapY(y2[i]);
}
// Note: The hull can be a single point or a line
if (!forcePolygon)
{
if (x2.length == 1)
return new PointRoi(x2[0], y2[0]);
if (x2.length == 2)
return new Line(x2[0], y2[0], x2[1], y2[1]);
}
return new PolygonRoi(x2, y2, Roi.POLYGON);
}
示例9: setup
import ij.gui.PolygonRoi; //导入依赖的package包/类
public int setup(String arg, ImagePlus imp)
{
UsageTracker.recordPlugin(this.getClass(), arg);
if (imp == null)
{
return DONE;
}
if (imp.getRoi() == null || imp.getRoi().getType() != ij.gui.PolygonRoi.POINT)
{
IJ.error("Please select a centre point using the ROI tool");
return DONE;
}
this.imp = imp;
kernels = null;
roi = (PointRoi) imp.getRoi();
xpoints = roi.getPolygon().xpoints;
ypoints = roi.getPolygon().ypoints;
return flags;
}
示例10: DifferentiableEllipticalFitFunction
import ij.gui.PolygonRoi; //导入依赖的package包/类
/**
* @param roi
* The polygon to fit
* @param weightMap
*/
public DifferentiableEllipticalFitFunction(PolygonRoi roi, FloatProcessor weightMap)
{
// These methods try to minimise the difference between a target value and your model value.
// The target value is the polygon outline. The model is currently an elliptical path.
this.weightMap = weightMap;
nPoints = roi.getNCoordinates();
xPoints = Arrays.copyOf(roi.getXCoordinates(), nPoints);
yPoints = Arrays.copyOf(roi.getYCoordinates(), nPoints);
Rectangle bounds = roi.getBounds();
for (int i = 0; i < nPoints; i++)
{
xPoints[i] += bounds.x;
yPoints[i] += bounds.y;
}
}
示例11: findRoiPointIndex
import ij.gui.PolygonRoi; //导入依赖的package包/类
private int findRoiPointIndex(PointRoi roi, int ox, int oy)
{
Polygon p = ((PolygonRoi) roi).getNonSplineCoordinates();
int n = p.npoints;
Rectangle bounds = roi.getBounds();
for (int i = 0; i < n; i++)
{
int x = bounds.x + p.xpoints[i];
int y = bounds.y + p.ypoints[i];
if (x == ox && y == oy)
return i;
}
return -1;
}
示例12: generateVisualizationRoisFromTrack
import ij.gui.PolygonRoi; //导入依赖的package包/类
public static ArrayList<Roi> generateVisualizationRoisFromTrack(Subtrajectory t, Color c, boolean showID, double pixelsize){
ArrayList<Roi> proi = new ArrayList<Roi>();
FloatPolygon p = new FloatPolygon();
double sumx = 0;
double sumy = 0;
TextRoi.setFont("TimesRoman", 5, Font.PLAIN);
for(int i = 0; i < t.getParent().size(); i++){
int to = t.size();
if(i< t.size()){
sumx += t.get(i).x/pixelsize;
sumy += t.get(i).y/pixelsize;
p.addPoint(t.get(i).x/pixelsize, t.get(i).y/pixelsize);
to = i+1;
}
PolygonRoi pr = new PolygonRoi(new FloatPolygon(p.xpoints, p.ypoints,to), PolygonRoi.POLYLINE);
pr.setStrokeColor(c);
pr.setPosition(t.getRelativeStartTimepoint()+i+1);
proi.add(pr);
if(showID){
long parentID = t.getParent().getID();
TextRoi troi = new TextRoi(sumx/to, sumy/to," "+parentID+":"+t.getID()+" ");
troi.setPosition(t.getRelativeStartTimepoint()+i+1);
troi.setFillColor(Color.BLACK);
troi.setStrokeColor(c);
troi.setAntialiased(true);
proi.add(troi);
}
}
return proi;
}
示例13: smoothPolygonRoi
import ij.gui.PolygonRoi; //导入依赖的package包/类
private static PolygonRoi smoothPolygonRoi(PolygonRoi r) {
FloatPolygon poly = r.getFloatPolygon();
FloatPolygon poly2 = new FloatPolygon();
int nPoints = poly.npoints;
for (int i = 0; i < nPoints; i += 2) {
int iMinus = (i + nPoints - 1) % nPoints;
int iPlus = (i + 1) % nPoints;
poly2.addPoint((poly.xpoints[iMinus] + poly.xpoints[iPlus] + poly.xpoints[i])/3,
(poly.ypoints[iMinus] + poly.ypoints[iPlus] + poly.ypoints[i])/3);
}
// return new PolygonRoi(poly2, r.getType());
return new PolygonRoi(poly2, Roi.POLYGON);
}
示例14: getFilledPolygonROIsFromLabels
import ij.gui.PolygonRoi; //导入依赖的package包/类
/**
* Get filled Polygon ROIs using distinct labels, creating a map between labels and ROIs.
* <p>
* Note that discontinuous ROIs are not supported; if labelled regions are discontinuous,
* then ROIs detected earlier will be discarded from the map.
*
* @param ip
* @param wandMode
* @return
*/
public static Map<Float, PolygonRoi> getFilledPolygonROIsFromLabels(ImageProcessor ip, int wandMode) {
// Wand wand = new Wand(ip);
double threshLower = ip.getMinThreshold();
if (threshLower == ImageProcessor.NO_THRESHOLD)
threshLower = Double.NEGATIVE_INFINITY;
double threshHigher = ip.getMaxThreshold();
if (threshHigher == ImageProcessor.NO_THRESHOLD)
threshHigher = Double.POSITIVE_INFINITY;
int w = ip.getWidth();
int h = ip.getHeight();
// List<PolygonRoi> rois = new ArrayList<>();
ByteProcessor bpCompleted = new ByteProcessor(w, h);
bpCompleted.setValue(255);
TreeMap<Float, PolygonRoi> map = new TreeMap<>();
for (int y = 0; y < h; y++) {
for (int x = 0; x < w; x++) {
if (bpCompleted.get(x, y) != 0)
continue;
float val = ip.getf(x, y);
if (val >= threshLower && val <= threshHigher) {
Wand wand = new Wand(ip);
wand.autoOutline(x, y, threshLower, threshHigher, wandMode);
PolygonRoi roi = wandToRoi(wand);
// rois.add(roi);
Float key = val;
if (map.containsKey(key))
logger.warn("Polygon ROI is being inserted twice into map for the same key {}", key);
map.put(val, roi);
bpCompleted.fill(roi);
}
}
}
return map;
}
示例15: getFilledPolygonROIs
import ij.gui.PolygonRoi; //导入依赖的package包/类
public static List<PolygonRoi> getFilledPolygonROIs(ImageProcessor ip, int wandMode) {
// Wand wand = new Wand(ip);
double threshLower = ip.getMinThreshold();
if (threshLower == ImageProcessor.NO_THRESHOLD)
threshLower = Double.NEGATIVE_INFINITY;
double threshHigher = ip.getMaxThreshold();
if (threshHigher == ImageProcessor.NO_THRESHOLD)
threshHigher = Double.POSITIVE_INFINITY;
int w = ip.getWidth();
int h = ip.getHeight();
List<PolygonRoi> rois = new ArrayList<>();
ByteProcessor bpCompleted = new ByteProcessor(w, h);
bpCompleted.setValue(255);
for (int y = 0; y < h; y++) {
for (int x = 0; x < w; x++) {
if (bpCompleted.get(x, y) != 0)
continue;
float val = ip.getf(x, y);
if (val >= threshLower && val <= threshHigher) {
Wand wand = new Wand(ip);
wand.autoOutline(x, y, threshLower, threshHigher, wandMode);
PolygonRoi roi = wandToRoi(wand);
rois.add(roi);
bpCompleted.fill(roi);
}
}
}
return rois;
}