MCPcopy Create free account
hub / github.com/AstroImageJ/astroimagej / getMask

Method getMask

ij/src/main/java/ij/gui/ShapeRoi.java:1034–1060  ·  view source on GitHub ↗

Returns this ROI's mask pixels as a ByteProcessor with pixels "in" the mask set to white (255) and pixels "outside" the mask set to black (0). Takes into account the usual ImageJ convention of 0.5 pxl shift between the outline and pixel coordinates; e.g., pixel (0,0) is surrounded by the rectangl

()

Source from the content-addressed store, hash-verified

1032 * with the lower (higher) y.
1033 * */
1034 public ImageProcessor getMask() {
1035 if (shape==null)
1036 return null;
1037 ImageProcessor mask = cachedMask;
1038 if (mask!=null && mask.getPixels()!=null && mask.getWidth()==width && mask.getHeight()==height)
1039 return mask;
1040 /* The following code using Graphics2D.fill would in principle work, but is very inaccurate
1041 * at least with Oracle Java 8 or OpenJDK Java 10.
1042 * For near-vertical polgon edges of 1000 pixels length, the deviation can be >0.8 pixels in x.
1043 * Thus, approximating the shape by a polygon and using the PolygonFiller is more accurate
1044 * (and roughly equally fast). --ms Jan 2018 */
1045 /*BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_GRAY);
1046 Graphics2D g2d = bi.createGraphics();
1047 g2d.setColor(Color.white);
1048 g2d.transform(AffineTransform.getTranslateInstance(-0.48, -0.49994)); //very inaccurate, only reasonable with "-0.48"
1049 g2d.fill(shape);
1050 Raster raster = bi.getRaster();
1051 DataBufferByte buffer = (DataBufferByte)raster.getDataBuffer();
1052 byte[] mask = buffer.getData();
1053 cachedMask = new ByteProcessor(width, height, mask, null);
1054 cachedMask.setThreshold(255,255,ImageProcessor.NO_LUT_UPDATE);*/
1055 FloatPolygon fpoly = getFloatPolygon(FILL_FLATNESS, true, false, false);
1056 PolygonFiller pf = new PolygonFiller(fpoly.xpoints, fpoly.ypoints, fpoly.npoints, (float)(getXBase()-x), (float)(getYBase()-y));
1057 mask = pf.getMask(width, height);
1058 cachedMask = mask;
1059 return mask;
1060 }
1061
1062 /**Returns a reference to the Shape object encapsulated by this ShapeRoi. */
1063 public Shape getShape() {

Callers 1

roiToShapeMethod · 0.45

Calls 7

getPixelsMethod · 0.95
getWidthMethod · 0.95
getHeightMethod · 0.95
getFloatPolygonMethod · 0.95
getMaskMethod · 0.95
getXBaseMethod · 0.80
getYBaseMethod · 0.80

Tested by

no test coverage detected