Returns an 8-bit binary (foreground=255, background=0) ROI or overlay mask that has the same dimensions as this image. Creates an ROI mask If the image has both both an ROI and an overlay. Set the threshold of the mask to 255. @see #createThresholdMask @see ij.gui.Roi#getMask
()
| 1141 | * @see ij.gui.Roi#getMask |
| 1142 | */ |
| 1143 | public ByteProcessor createRoiMask() { |
| 1144 | Roi roi2 = getRoi(); |
| 1145 | Overlay overlay2 = getOverlay(); |
| 1146 | if (roi2==null && overlay2==null) |
| 1147 | throw new IllegalArgumentException("ROI or overlay required"); |
| 1148 | ByteProcessor mask = new ByteProcessor(getWidth(),getHeight()); |
| 1149 | mask.setColor(255); |
| 1150 | if (roi2!=null) |
| 1151 | mask.fill(roi2); |
| 1152 | else if (overlay2!=null) { |
| 1153 | if (overlay2.size()==1 && (overlay2.get(0) instanceof ImageRoi)) { |
| 1154 | ImageRoi iRoi = (ImageRoi)overlay2.get(0); |
| 1155 | ImageProcessor ip = iRoi.getProcessor(); |
| 1156 | if (ip.getWidth()!=mask.getWidth() || ip.getHeight()!=mask.getHeight()) |
| 1157 | return mask; |
| 1158 | for (int i=0; i<ip.getPixelCount(); i++) { |
| 1159 | if (ip.get(i)!=0) |
| 1160 | mask.set(i, 255); |
| 1161 | } |
| 1162 | } else { |
| 1163 | for (int i=0; i<overlay2.size(); i++) |
| 1164 | mask.fill(overlay2.get(i)); |
| 1165 | } |
| 1166 | } |
| 1167 | mask.setThreshold(255, 255, ImageProcessor.NO_LUT_UPDATE); |
| 1168 | return mask; |
| 1169 | } |
| 1170 | |
| 1171 | /** Returns an 8-bit binary threshold mask |
| 1172 | * (foreground=255, background=0) |
no test coverage detected