本文整理汇总了Java中ij.gui.Roi.getMask方法的典型用法代码示例。如果您正苦于以下问题:Java Roi.getMask方法的具体用法?Java Roi.getMask怎么用?Java Roi.getMask使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ij.gui.Roi
的用法示例。
在下文中一共展示了Roi.getMask方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: toShape
import ij.gui.Roi; //导入方法依赖的package包/类
/**
* Convert ImageJ's Roi to Java 3D Shape representation.
*
* @param roi source roi.
* @return translated to Shape.
*/
public static Shape toShape(final Roi roi) {
final Shape result;
if (roi instanceof PointRoi) {
final ByteProcessor mask = (ByteProcessor) roi.getMask();
final byte[] maskPixels = (byte[]) mask.getPixels();
final Rectangle maskBounds = roi.getBounds();
final int maskWidth = mask.getWidth();
final int maskHeight = mask.getHeight();
final Area area = new Area();
for (int y = 0; y < maskHeight; y++) {
final int yOffset = y * maskWidth;
for (int x = 0; x < maskWidth; x++) {
if (maskPixels[x + yOffset] != 0) {
area.add(new Area(new Rectangle(x + maskBounds.x, y + maskBounds.y, 1, 1)));
}
}
}
result = area;
} else {
result = makeShapeFromArray(new ShapeRoi(roi).getShapeAsArray());
}
return result;
}
示例2: extractBorderPixels
import ij.gui.Roi; //导入方法依赖的package包/类
public static ArrayList<VPoint> extractBorderPixels(Roi roi){
ImageProcessor mask = roi.getMask();
ArrayList<VPoint> pixels = new ArrayList<VPoint>();
Rectangle r = roi.getBounds();
for (int x = 0; x < r.width; ++x){
for (int y = 0; y < r.height; ++y){
// int N = 0;
for (int i=0; mask.getPixel(x, y) > 0 && i < n8.length; i += 2) {
if ( mask.getPixel(x + n8[i].x, y + n8[i].y) == 0) {
// System.out.println("border = " + x + "," + y);
pixels.add(new VPoint(x + r.x, y + r.y));
// roi.getImage().getProcessor().putPixel(x + r.x, y + r.y, 255);
// roi.getImage().getProcessor().putPixel(x, y, 255);
break;
}
}
}
}
return pixels;
}
示例3: registerBacteriaRoi
import ij.gui.Roi; //导入方法依赖的package包/类
protected void registerBacteriaRoi(Bacteria b, Roi roi, int frameNo) {
boolean warnOnce = false;
bacteriaRoisBag.put(b.getBactName(), roi);
log.debug("Roi for " + b.getBactName() + " registered. Current roi bag size = " + bacteriaRoisBag.size()
+ " Location is:" + roi.getBounds().x + ", " + roi.getBounds().y);
ImageProcessor mask = roi.getMask();
Rectangle r = roi.getBounds();
for (int x = 0; x < mask.getWidth(); ++x) {
for (int y = 0; y < mask.getHeight(); ++y) {
if (mask.getPixel(x, y) > 0) {
try {
if (selectionsMask[x + r.x][y + r.y] != 0 && selectionsMask[x + r.x][y + r.y] != b.getIdBacteria()) {
log.debug("***************** OVERLAP ERROR (frameNo = " + frameNo + "): " + b.getBactName() + " vs " + selectionsMask[x + r.x][y + r.y]
+ " pixel = " + (x + r.x) + ", " + (y + r.y)
);
if (imp!= null) imp.getProcessor().putPixel(x + r.x, y + r.y, MovieProcessor.colToValue(Color.red));
}
selectionsMask[x + r.x][y + r.y] = b.getIdBacteria();
} catch (ArrayIndexOutOfBoundsException e) {
if (!warnOnce) {
warnOnce = true;
String state = CurrentExperiment.getBacteriaStateAt(b, frameNo);
if (state == null || state.toLowerCase().indexOf("ignore") == -1 ){
ControlPanel.addStatusMessage("Error registering bacteria " + b.getBactName() + ". Is it leaving the window? You should ignore it.");
}
}
}
}
}
}
}
示例4: registerBacteriaRoi
import ij.gui.Roi; //导入方法依赖的package包/类
protected void registerBacteriaRoi(Bacteria b, Roi roi, int frameNo) {
boolean warnOnce = false;
bacteriaRoisBag.put(b.getBactName(), roi);
ImageProcessor mask = roi.getMask();
Rectangle r = roi.getBounds();
for (int x = 0; x < mask.getWidth(); ++x) {
for (int y = 0; y < mask.getHeight(); ++y) {
if (mask.getPixel(x, y) > 0) {
try {
if (selectionsMask[x + r.x][y + r.y] != 0 && selectionsMask[x + r.x][y + r.y] != b.getIdBacteria()) {
log.debug("***************** OVERLAP ERROR (frameNo = " + frameNo + "): " + b.getBactName() + " vs " + selectionsMask[x + r.x][y + r.y]
+ " pixel = " + (x + r.x) + ", " + (y + r.y)
);
if (imp!= null) imp.getProcessor().putPixel(x + r.x, y + r.y, MovieProcessor.colToValue(Color.red));
}
selectionsMask[x + r.x][y + r.y] = b.getIdBacteria();
} catch (ArrayIndexOutOfBoundsException e) {
if (!warnOnce) {
warnOnce = true;
String state = CurrentExperiment.getBacteriaStateAt(b, frameNo);
if (state == null || state.toLowerCase().indexOf("ignore") == -1 ){
ControlPanel.addStatusMessage("Error registering bacteria " + b.getBactName() + ". Is it leaving the window? You should ignore it.");
}
}
}
}
}
}
}
示例5: createMasksAndRois
import ij.gui.Roi; //导入方法依赖的package包/类
/**
* Creates appropriate data structures from the ROI information
* passed. If an irregular ROI is found, it will be put into a
* frame of its bounding box size and put into an {@code Image<T>}.
*
* In the end the members ROIs, masks and maskBBs will be
* filled if ROIs or masks were found. They will be null
* otherwise.
*/
protected void createMasksAndRois(final Roi[] rois, final int width,
final int height)
{
// create empty list
masks.clear();
for (final Roi r : rois) {
final MaskInfo mi = new MaskInfo();
// add it to the list of masks/ROIs
masks.add(mi);
// get the ROIs/masks bounding box
final Rectangle rect = r.getBounds();
mi.roi = new BoundingBox(new long[] { rect.x, rect.y }, new long[] {
rect.width, rect.height });
final ImageProcessor ipMask = r.getMask();
// check if we got a regular ROI and return if so
if (ipMask == null) {
continue;
}
// create a mask processor of the same size as a slice
final ImageProcessor ipSlice = ipMask.createProcessor(width, height);
// fill the new slice with black
ipSlice.setValue(0.0);
ipSlice.fill();
// position the mask on the new mask processor
ipSlice.copyBits(ipMask, (int) mi.roi.offset[0], (int) mi.roi.offset[1],
Blitter.COPY);
// create an Image<T> out of it
final ImagePlus maskImp = new ImagePlus("Mask", ipSlice);
// and remember it and the masks bounding box
mi.mask = ImagePlusAdapter.<T> wrap(maskImp);
}
}