Creates an unsigned short image.
(String title, int width, int height, int slices, int options)
| 270 | |
| 271 | /** Creates an unsigned short image. */ |
| 272 | public static ImagePlus createShortImage(String title, int width, int height, int slices, int options) { |
| 273 | int fill = getFill(options); |
| 274 | int size = getSize(width, height); |
| 275 | if (size<0) return null; |
| 276 | short[] pixels = new short[size]; |
| 277 | ImageProcessor ip = new ShortProcessor(width, height, pixels, null); |
| 278 | switch (fill) { |
| 279 | case FILL_WHITE: case FILL_BLACK: |
| 280 | break; |
| 281 | case FILL_RAMP: |
| 282 | short[] ramp = new short[width]; |
| 283 | for (int i=0; i<width; i++) |
| 284 | ramp[i] = (short)(((i*65536.0)/width)+0.5); |
| 285 | int offset; |
| 286 | for (int y=0; y<height; y++) { |
| 287 | offset = y*width; |
| 288 | for (int x=0; x<width; x++) |
| 289 | pixels[offset++] = ramp[x]; |
| 290 | } |
| 291 | break; |
| 292 | case FILL_NOISE: |
| 293 | fillNoiseShort(ip); |
| 294 | break; |
| 295 | } |
| 296 | if (fill==FILL_WHITE) |
| 297 | ip.invertLut(); |
| 298 | ImagePlus imp = new ImagePlus(title, ip); |
| 299 | if (slices>1) { |
| 300 | boolean ok = createStack(imp, ip, slices, GRAY16, options); |
| 301 | if (!ok) imp = null; |
| 302 | } |
| 303 | imp.getProcessor().setMinAndMax(0, 65535); // default display range |
| 304 | return imp; |
| 305 | } |
| 306 | |
| 307 | private static void fillNoiseShort(ImageProcessor ip) { |
| 308 | ip.add(32767); |
no test coverage detected