forked from ecos-umons/ImageJ
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ImageStack.java
722 lines (663 loc) · 20.4 KB
/
ImageStack.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
package ij;
import java.awt.*;
import java.awt.image.*;
import ij.process.*;
/**
This class represents an expandable array of images.
@see ImagePlus
*/
public class ImageStack {
static final int INITIAL_SIZE = 25;
static final String outOfRange = "Stack argument out of range: ";
private int bitDepth = 0; //0=unknown
private int nSlices = 0;
private Object[] stack;
private String[] label;
private int width, height;
private Rectangle roi;
private ColorModel cm;
private double min=Double.MAX_VALUE;
private double max;
protected float[] cTable;
private int viewers;
private boolean signedInt;
/** Default constructor. */
public ImageStack() { }
/** Creates a new, empty image stack. */
public ImageStack(int width, int height) {
this(width, height, null);
}
/** Creates a new, empty image stack with a capacity of 'size'. All
'size' slices and labels of this image stack are initially null.*/
public ImageStack(int width, int height, int size) {
this.width = width;
this.height = height;
stack = new Object[size];
label = new String[size];
nSlices = size;
}
/** Creates a new, empty image stack using the specified color model. */
public ImageStack(int width, int height, ColorModel cm) {
this.width = width;
this.height = height;
this.cm = cm;
stack = new Object[INITIAL_SIZE];
label = new String[INITIAL_SIZE];
nSlices = 0;
}
/** Adds an image in the form of a pixel array to the end of the stack. */
public void addSlice(String sliceLabel, Object pixels) {
if (pixels==null)
throw new IllegalArgumentException("'pixels' is null!");
if (!pixels.getClass().isArray())
throw new IllegalArgumentException("'pixels' is not an array");
int size = stack.length;
nSlices++;
if (nSlices>=size) {
Object[] tmp1 = new Object[size*2];
System.arraycopy(stack, 0, tmp1, 0, size);
stack = tmp1;
String[] tmp2 = new String[size*2];
System.arraycopy(label, 0, tmp2, 0, size);
label = tmp2;
}
stack[nSlices-1] = pixels;
this.label[nSlices-1] = sliceLabel;
if (this.bitDepth==0)
setBitDepth(pixels);
}
private void setBitDepth(Object pixels) {
if (pixels==null)
return;
if (pixels instanceof byte[])
this.bitDepth = 8;
else if (pixels instanceof short[])
this.bitDepth = 16;
else if (pixels instanceof float[])
this.bitDepth = 32;
else if (pixels instanceof int[])
this.bitDepth = 24;
}
/**
* @deprecated
* Short images are always unsigned.
*/
public void addUnsignedShortSlice(String sliceLabel, Object pixels) {
addSlice(sliceLabel, pixels);
}
/** Adds the image in 'ip' to the end of the stack. */
public void addSlice(ImageProcessor ip) {
addSlice(null, ip);
}
/** Adds the image in 'ip' to the end of the stack, setting
the string 'sliceLabel' as the slice metadata. */
public void addSlice(String sliceLabel, ImageProcessor ip) {
ip = convertType(ip);
if (ip.getWidth()!=this.width || ip.getHeight()!=this.height) {
if (this.width==0 && this.height==0)
init(ip.getWidth(), ip.getHeight());
else {
ImageProcessor ip2 = ip.createProcessor(this.width,this.height);
ip2.insert(ip, 0, 0);
ip = ip2;
}
}
if (nSlices==0) {
cm = ip.getColorModel();
min = ip.getMin();
max = ip.getMax();
}
addSlice(sliceLabel, ip.getPixels());
}
private void init(int width, int height) {
this.width = width;
this.height = height;
stack = new Object[INITIAL_SIZE];
label = new String[INITIAL_SIZE];
}
private ImageProcessor convertType(ImageProcessor ip) {
int newBitDepth = ip.getBitDepth();
if (this.bitDepth==0)
this.bitDepth = newBitDepth;
if (this.bitDepth!=newBitDepth) {
switch (this.bitDepth) {
case 8: ip=ip.convertToByte(true); break;
case 16: ip=ip.convertToShort(true); break;
case 24: ip=ip.convertToRGB(); break;
case 32: ip=ip.convertToFloat(); break;
}
}
return ip;
}
/** Adds the image in 'ip' to the stack following slice 'n'. Adds
the slice to the beginning of the stack if 'n' is zero. */
public void addSlice(String sliceLabel, ImageProcessor ip, int n) {
if (n<0 || n>nSlices)
throw new IllegalArgumentException(outOfRange+n);
addSlice(sliceLabel, ip);
Object tempSlice = stack[nSlices-1];
String tempLabel = label[nSlices-1];
int first = n>0?n:1;
for (int i=nSlices-1; i>=first; i--) {
stack[i] = stack[i-1];
label[i] = label[i-1];
}
stack[n] = tempSlice;
label[n] = tempLabel;
}
/** Deletes the specified slice, where {@literal 1<=n<=nslices}. */
public void deleteSlice(int n) {
if (n<1 || n>nSlices)
throw new IllegalArgumentException(outOfRange+n);
if (nSlices<1)
return;
for (int i=n; i<nSlices; i++) {
stack[i-1] = stack[i];
label[i-1] = label[i];
}
stack[nSlices-1] = null;
label[nSlices-1] = null;
nSlices--;
}
/** Deletes the last slice in the stack. */
public void deleteLastSlice() {
if (nSlices>0)
deleteSlice(nSlices);
}
public int getWidth() {
return width;
}
public int getHeight() {
return height;
}
public void setRoi(Rectangle roi) {
this.roi = roi;
}
public Rectangle getRoi() {
if (roi==null)
return new Rectangle(0, 0, width, height);
else
return(roi);
}
/** Updates this stack so its attributes, such as min, max,
calibration table and color model, are the same as 'ip'. */
public void update(ImageProcessor ip) {
if (ip!=null) {
min = ip.getMin();
max = ip.getMax();
cTable = ip.getCalibrationTable();
cm = ip.getColorModel();
}
}
/** Returns the pixel array for the specified slice, where {@literal 1<=n<=nslices}. */
public Object getPixels(int n) {
if (n<1 || n>nSlices)
throw new IllegalArgumentException(outOfRange+n);
return stack[n-1];
}
/** Assigns a pixel array to the specified slice, where {@literal 1<=n<=nslices}. */
public void setPixels(Object pixels, int n) {
if (n<1 || n>nSlices)
throw new IllegalArgumentException(outOfRange+n);
stack[n-1] = pixels;
if (this.bitDepth==0)
setBitDepth(pixels);
}
/** Returns the stack as an array of 1D pixel arrays. Note
that the size of the returned array may be greater than
the number of slices currently in the stack, with
unused elements set to null. */
public Object[] getImageArray() {
return stack;
}
/** Returns the number of slices in this stack. */
public int size() {
return getSize();
}
public int getSize() {
return nSlices;
}
/** Returns the slice labels as an array of Strings. Note
that the size of the returned array may be greater than
the number of slices currently in the stack. Returns null
if the stack is empty or the label of the first slice is null. */
public String[] getSliceLabels() {
if (nSlices==0)
return null;
else
return label;
}
/** Returns the label of the specified slice, where {@literal 1<=n<=nslices}.
Returns null if the slice does not have a label or 'n';
is out of range. For DICOM and FITS stacks, labels may
contain header information.
*/
public String getSliceLabel(int n) {
if (n<1 || n>nSlices)
return null;
else
return label[n-1];
}
/** Returns a shortened version (up to the first 60 characters
* or first newline), with the extension removed, of the specified
* slice label, or null if the slice does not have a label.
*/
public String getShortSliceLabel(int n) {
return getShortSliceLabel(n, 60);
}
/** Returns a shortened version (up to the first 'max' characters
* or first newline), with the extension removed, of the specified
* slice label, or null if the slice does not have a label.
*/
public String getShortSliceLabel(int n, int max) {
String shortLabel = getSliceLabel(n);
if (shortLabel==null) return null;
int newline = shortLabel.indexOf('\n');
if (newline==0) return null;
if (newline>0)
shortLabel = shortLabel.substring(0, newline);
int len = shortLabel.length();
if (len>4 && shortLabel.charAt(len-4)=='.' && !Character.isDigit(shortLabel.charAt(len-1)))
shortLabel = shortLabel.substring(0,len-4);
if (shortLabel.length()>max)
shortLabel = shortLabel.substring(0, max);
return shortLabel;
}
/** Sets the label of the specified slice, where {@literal 1<=n<=nslices}. */
public void setSliceLabel(String label, int n) {
if (n<1 || n>nSlices)
throw new IllegalArgumentException(outOfRange+n);
this.label[n-1] = label;
}
/** Returns an ImageProcessor for the specified slice,
* where {@literal 1<=n<=nslices}.
* Returns null if the stack is empty.
*/
public ImageProcessor getProcessor(int n) {
ImageProcessor ip;
if (n<1 || n>nSlices)
throw new IllegalArgumentException(outOfRange+n);
if (nSlices==0)
return null;
if (stack[n-1]==null)
throw new IllegalArgumentException("Pixel array is null");
if (stack[n-1] instanceof byte[])
ip = new ByteProcessor(width, height, null, cm);
else if (stack[n-1] instanceof short[])
ip = new ShortProcessor(width, height, null, cm);
else if (stack[n-1] instanceof int[]) {
if (signedInt)
ip = new IntProcessor(width, height);
else
ip = new ColorProcessor(width, height, null);
} else if (stack[n-1] instanceof float[])
ip = new FloatProcessor(width, height, null, cm);
else
throw new IllegalArgumentException("Unknown stack type");
ip.setPixels(stack[n-1]);
if (min!=Double.MAX_VALUE && ip!=null && !(ip instanceof ColorProcessor))
ip.setMinAndMax(min, max);
if (cTable!=null)
ip.setCalibrationTable(cTable);
return ip;
}
/** Assigns the pixel array of an ImageProcessor to the specified slice,
* where {@literal 1<=n<=nslices}.
*/
public void setProcessor(ImageProcessor ip, int n) {
if (n<1 || n>nSlices)
throw new IllegalArgumentException(outOfRange+n);
ip = convertType(ip);
if (ip.getWidth()!=width || ip.getHeight()!=height)
throw new IllegalArgumentException("Wrong dimensions for this stack");
stack[n-1] = ip.getPixels();
}
/** Assigns a new color model to this stack. */
public void setColorModel(ColorModel cm) {
this.cm = cm;
}
/** Returns this stack's color model. May return null. */
public ColorModel getColorModel() {
return cm;
}
/** Returns true if this is a 3-slice, 8-bit RGB stack. */
public boolean isRGB() {
return nSlices==3 && (stack[0] instanceof byte[]) && getSliceLabel(1)!=null && getSliceLabel(1).equals("Red");
}
/** Returns true if this is a 3-slice HSB stack. */
public boolean isHSB() {
return nSlices==3 && bitDepth==8 && getSliceLabel(1)!=null && getSliceLabel(1).equals("Hue");
}
/** Returns true if this is a 3-slice 32-bit HSB stack. */
public boolean isHSB32() {
return nSlices==3 && bitDepth==32 && getSliceLabel(1)!=null && getSliceLabel(1).equals("Hue");
}
/** Returns true if this is a Lab stack. */
public boolean isLab() {
return nSlices==3 && getSliceLabel(1)!=null && getSliceLabel(1).equals("L*");
}
/** Returns true if this is a virtual (disk resident) stack.
This method is overridden by the VirtualStack subclass. */
public boolean isVirtual() {
return false;
}
/** Frees memory by deleting a few slices from the end of the stack. */
public void trim() {
int n = (int)Math.round(Math.log(nSlices)+1.0);
for (int i=0; i<n; i++) {
deleteLastSlice();
System.gc();
}
}
public String toString() {
String v = isVirtual()?"(V)":"";
return ("stack["+getWidth()+"x"+getHeight()+"x"+size()+v+"]");
}
/** Returns, as a double, the value of the specified voxel.
* Throws an IndexOutOfBoundsException if x, y or z are
* beyond the stack limits. Use the ImagePlus.getStackIndex()
* method to convert a C,Z,T hyperstack position (one-based)
* into a z index (zero-based).
* @see ij.ImagePlus#getStackIndex
*/
public final double getVoxel(int x, int y, int z) {
if (x>=0 && x<width && y>=0 && y<height && z>=0 && z<nSlices) {
switch (bitDepth) {
case 8:
byte[] bytes = (byte[])stack[z];
return bytes[y*width+x]&0xff;
case 16:
short[] shorts = (short[])stack[z];
return shorts[y*width+x]&0xffff;
case 32:
float[] floats = (float[])stack[z];
return floats[y*width+x];
case 24:
int[] ints = (int[])stack[z];
return ints[y*width+x]&0xffffffff;
default: return Double.NaN;
}
} else
throw new IndexOutOfBoundsException();
}
/* Sets the value of the specified voxel. */
public final void setVoxel(int x, int y, int z, double value) {
if (x>=0 && x<width && y>=0 && y<height && z>=0 && z<nSlices) {
switch (bitDepth) {
case 8:
byte[] bytes = (byte[])stack[z];
if (value>255.0)
value = 255.0;
else if (value<0.0)
value = 0.0;
bytes[y*width+x] = (byte)(value+0.5);
break;
case 16:
short[] shorts = (short[])stack[z];
if (value>65535.0)
value = 65535.0;
else if (value<0.0)
value = 0.0;
shorts[y*width+x] = (short)(value+0.5);
break;
case 32:
float[] floats = (float[])stack[z];
floats[y*width+x] = (float)value;
break;
case 24:
int[] ints = (int[])stack[z];
ints[y*width+x] = (int)value;
break;
}
}
}
public float[] getVoxels(int x0, int y0, int z0, int w, int h, int d, float[] voxels) {
boolean inBounds = x0>=0 && x0+w<=width && y0>=0 && y0+h<=height && z0>=0 && z0+d<=nSlices;
if (voxels==null || voxels.length!=w*h*d)
voxels = new float[w*h*d];
int i = 0;
int offset;
for (int z=z0; z<z0+d; z++) {
for (int y=y0; y<y0+h; y++) {
if (inBounds) {
switch (bitDepth) {
case 8:
byte[] bytes = (byte[])stack[z];
for (int x=x0; x<x0+w; x++)
voxels[i++] = bytes[y*width+x]&0xff;
break;
case 16:
short[] shorts = (short[])stack[z];
for (int x=x0; x<x0+w; x++)
voxels[i++] = shorts[y*width+x]&0xffff;
break;
case 32:
float[] floats = (float[])stack[z];
for (int x=x0; x<x0+w; x++)
voxels[i++] = floats[y*width+x];
break;
case 24:
int[] ints = (int[])stack[z];
for (int x=x0; x<x0+w; x++)
voxels[i++] = ints[y*width+x]&0xffffffff;
break;
default:
for (int x=x0; x<x0+w; x++)
voxels[i++] = 0f;
}
} else {
for (int x=x0; x<x0+w; x++)
voxels[i++] = (float)getVoxel(x, y, z);
}
}
}
return voxels;
}
public float[] getVoxels(int x0, int y0, int z0, int w, int h, int d, float[] voxels, int channel) {
if (bitDepth!=24)
return getVoxels(x0, y0, z0, w, h, d, voxels);
boolean inBounds = x0>=0 && x0+w<=width && y0>=0 && y0+h<=height && z0>=0 && z0+d<=nSlices;
if (voxels==null || voxels.length!=w*h*d)
voxels = new float[w*h*d];
int i = 0;
for (int z=z0; z<z0+d; z++) {
int[] ints = (int[])stack[z];
for (int y=y0; y<y0+h; y++) {
for (int x=x0; x<x0+w; x++) {
int value = inBounds?ints[y*width+x]&0xffffffff:(int)getVoxel(x, y, z);
switch (channel) {
case 0: value=(value&0xff0000)>>16; break;
case 1: value=(value&0xff00)>>8; break;
case 2: value=value&0xff;; break;
}
voxels[i++] = (float)value;
}
}
}
return voxels;
}
/** Experimental */
public void setVoxels(int x0, int y0, int z0, int w, int h, int d, float[] voxels) {
boolean inBounds = x0>=0 && x0+w<=width && y0>=0 && y0+h<=height && z0>=0 && z0+d<=nSlices;
if (voxels==null || voxels.length!=w*h*d)
;
int i = 0;
float value;
for (int z=z0; z<z0+d; z++) {
for (int y=y0; y<y0+h; y++) {
if (inBounds) {
switch (bitDepth) {
case 8:
byte[] bytes = (byte[])stack[z];
for (int x=x0; x<x0+w; x++) {
value = voxels[i++];
if (value>255f)
value = 255f;
else if (value<0f)
value = 0f;
bytes[y*width+x] = (byte)(value+0.5f);
}
break;
case 16:
short[] shorts = (short[])stack[z];
for (int x=x0; x<x0+w; x++) {
value = voxels[i++];
if (value>65535f)
value = 65535f;
else if (value<0f)
value = 0f;
shorts[y*width+x] = (short)(value+0.5f);
}
break;
case 32:
float[] floats = (float[])stack[z];
for (int x=x0; x<x0+w; x++) {
value = voxels[i++];
floats[y*width+x] = value;
}
break;
case 24:
int[] ints = (int[])stack[z];
for (int x=x0; x<x0+w; x++) {
value = voxels[i++];
ints[y*width+x] = (int)value;
}
break;
}
} else {
for (int x=x0; x<x0+w; x++)
setVoxel(x, y, z, voxels[i++]);
}
}
}
}
/** Experimental */
public void setVoxels(int x0, int y0, int z0, int w, int h, int d, float[] voxels, int channel) {
if (bitDepth!=24) {
setVoxels(x0, y0, z0, w, h, d, voxels);
return;
}
boolean inBounds = x0>=0 && x0+w<=width && y0>=0 && y0+h<=height && z0>=0 && z0+d<=nSlices;
if (voxels==null || voxels.length!=w*h*d)
;
int i = 0;
for (int z=z0; z<z0+d; z++) {
int[] ints = (int[])stack[z];
for (int y=y0; y<y0+h; y++) {
for (int x=x0; x<x0+w; x++) {
int value = inBounds?ints[y*width+x]&0xffffffff:(int)getVoxel(x, y, z);
int color = (int)voxels[i++];
switch (channel) {
case 0: value=(value&0xff00ffff) | ((color&0xff)<<16); break;
case 1: value=(value&0xffff00ff) | ((color&0xff)<<8); break;
case 2: value=(value&0xffffff00) | (color&0xff); break;
}
if (inBounds)
ints[y*width+x] = value;
else
setVoxel(x, y, z, value);
}
}
}
}
/** Experimental */
public void drawSphere(double radius, int xc, int yc, int zc) {
int diameter = (int)Math.round(radius*2);
double r = radius;
int xmin=(int)(xc-r+0.5), ymin=(int)(yc-r+0.5), zmin=(int)(zc-r+0.5);
int xmax=xmin+diameter, ymax=ymin+diameter, zmax=zmin+diameter;
double r2 = r*r;
r -= 0.5;
double xoffset=xmin+r, yoffset=ymin+r, zoffset=zmin+r;
double xx, yy, zz;
for (int x=xmin; x<=xmax; x++) {
for (int y=ymin; y<=ymax; y++) {
for (int z=zmin; z<=zmax; z++) {
xx = x-xoffset; yy = y-yoffset; zz = z-zoffset;
if (xx*xx+yy*yy+zz*zz<=r2)
setVoxel(x, y, z, 255);
}
}
}
}
/** Returns the bit depth (8=byte, 16=short, 24=RGB, 32=float). */
public int getBitDepth() {
if (this.bitDepth==0 && stack!=null && stack.length>0)
setBitDepth(stack[0]);
return this.bitDepth;
}
/** Sets the bit depth (8=byte, 16=short, 24=RGB, 32=float). */
public void setBitDepth(int depth) {
if (size()==0 && (depth==8||depth==16||depth==24||depth==32))
this.bitDepth = depth;
}
/** Creates a new ImageStack.
* @param width width in pixels
* @param height height in pixels
* @param depth number of images
* @param bitdepth 8, 16, 32 (float) or 24 (RGB)
*/
public static ImageStack create(int width, int height, int depth, int bitdepth) {
ImageStack stack = IJ.createImage("", width, height, depth, bitdepth).getStack();
if (bitdepth==16 || bitdepth==32) {
stack.min = Double.MAX_VALUE;
stack.max = 0.0;
}
return stack;
}
/** Creates an ImageStack from an ImagePlus array. */
public static ImageStack create(ImagePlus[] images) {
int w = 0;
int h = 0;
for (int i=0; i<images.length; i++) {
if (images[i].getWidth()>w) w=images[i].getWidth();
if (images[i].getHeight()>h) h=images[i].getHeight();
}
ImageStack stack = new ImageStack(w, h);
stack.init(w, h);
for (int i=0; i<images.length; i++) {
stack.addSlice(images[i].getProcessor());
}
int depth = images[0].getBitDepth();
if (depth==16 || depth==32) {
stack.min = Double.MAX_VALUE;
stack.max = 0.0;
}
return stack;
}
/** Duplicates this stack. */
public ImageStack duplicate() {
return crop(0, 0, 0, width, height, size());
}
/** Creates a new stack by cropping this one. */
public ImageStack crop(int x, int y, int z, int width, int height, int depth) {
if (x<0||y<0||z<0||x+width>this.width||y+height>this.height||z+depth>size())
throw new IllegalArgumentException("Argument out of range");
ImageStack stack2 = new ImageStack(width, height, getColorModel());
for (int i=z; i<z+depth; i++) {
ImageProcessor ip2 = this.getProcessor(i+1);
ip2.setRoi(x, y, width, height);
ip2 = ip2.crop();
stack2.addSlice(this.getSliceLabel(i+1), ip2);
}
return stack2;
}
/** Creates a float version of this stack. */
public ImageStack convertToFloat() {
ImageStack stack2 = new ImageStack(width, height, getColorModel());
for (int i=1; i<=size(); i++) {
ImageProcessor ip2 = this.getProcessor(i);
ip2 = ip2.convertToFloat();
stack2.addSlice(this.getSliceLabel(i), ip2);
}
return stack2;
}
int viewers(int inc) {
viewers += inc;
return viewers;
}
public void setOptions(String options) {
if (options==null) return;
signedInt = options.contains("32-bit int");
}
}