- java.lang.Object
-
- ij.ImageStack
-
- Direct Known Subclasses:
VirtualStack
public class ImageStack extends java.lang.Object
This class represents an expandable array of images.- See Also:
ImagePlus
-
-
Field Summary
Fields Modifier and Type Field Description protected float[]
cTable
-
Constructor Summary
Constructors Constructor Description ImageStack()
Default constructor.ImageStack(int width, int height)
Creates a new, empty image stack.ImageStack(int width, int height, int size)
Creates a new, empty image stack with a capacity of 'size'.ImageStack(int width, int height, java.awt.image.ColorModel cm)
Creates a new, empty image stack using the specified color model.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
addSlice(ImageProcessor ip)
Adds the image in 'ip' to the end of the stack.void
addSlice(java.lang.String sliceLabel, ImageProcessor ip)
Adds the image in 'ip' to the end of the stack, setting the string 'sliceLabel' as the slice metadata.void
addSlice(java.lang.String sliceLabel, ImageProcessor ip, int n)
Adds the image in 'ip' to the stack following slice 'n'.void
addSlice(java.lang.String sliceLabel, java.lang.Object pixels)
Adds an image in the form of a pixel array to the end of the stack.void
addUnsignedShortSlice(java.lang.String sliceLabel, java.lang.Object pixels)
Deprecated.Short images are always unsigned.ImageStack
convertToFloat()
Creates a float version of this stack.static ImageStack
create(int width, int height, int depth, int bitdepth)
Creates a new ImageStack.static ImageStack
create(ImagePlus[] images)
Creates an ImageStack from an ImagePlus array.ImageStack
crop(int x, int y, int z, int width, int height, int depth)
Creates a new stack by cropping this one.void
deleteLastSlice()
Deletes the last slice in the stack.void
deleteSlice(int n)
Deletes the specified slice, where 1<=n<=nslices.void
drawSphere(double radius, int xc, int yc, int zc)
ExperimentalImageStack
duplicate()
Duplicates this stack.int
getBitDepth()
Returns the bit depth (8=byte, 16=short, 24=RGB, 32=float).java.awt.image.ColorModel
getColorModel()
Returns this stack's color model.int
getHeight()
java.lang.Object[]
getImageArray()
Returns the stack as an array of 1D pixel arrays.java.lang.Object
getPixels(int n)
Returns the pixel array for the specified slice, where 1<=n<=nslices.ImageProcessor
getProcessor(int n)
Returns an ImageProcessor for the specified slice, where 1<=n<=nslices.java.awt.Rectangle
getRoi()
java.lang.String
getShortSliceLabel(int n)
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.java.lang.String
getShortSliceLabel(int n, int max)
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.int
getSize()
java.lang.String
getSliceLabel(int n)
Returns the label of the specified slice, where 1<=n<=nslices.java.lang.String[]
getSliceLabels()
Returns the slice labels as an array of Strings.double
getVoxel(int x, int y, int z)
Returns, as a double, the value of the specified voxel.float[]
getVoxels(int x0, int y0, int z0, int w, int h, int d, float[] voxels)
float[]
getVoxels(int x0, int y0, int z0, int w, int h, int d, float[] voxels, int channel)
int
getWidth()
boolean
isHSB()
Returns true if this is a 3-slice HSB stack.boolean
isHSB32()
Returns true if this is a 3-slice 32-bit HSB stack.boolean
isLab()
Returns true if this is a Lab stack.boolean
isRGB()
Returns true if this is a 3-slice, 8-bit RGB stack.boolean
isVirtual()
Returns true if this is a virtual (disk resident) stack.void
setBitDepth(int depth)
Sets the bit depth (8=byte, 16=short, 24=RGB, 32=float).void
setColorModel(java.awt.image.ColorModel cm)
Assigns a new color model to this stack.void
setOptions(java.lang.String options)
void
setPixels(java.lang.Object pixels, int n)
Assigns a pixel array to the specified slice, where 1<=n<=nslices.void
setProcessor(ImageProcessor ip, int n)
Assigns the pixel array of an ImageProcessor to the specified slice, where 1<=n<=nslices.void
setRoi(java.awt.Rectangle roi)
void
setSliceLabel(java.lang.String label, int n)
Sets the label of the specified slice, where 1<=n<=nslices.void
setVoxel(int x, int y, int z, double value)
void
setVoxels(int x0, int y0, int z0, int w, int h, int d, float[] voxels)
Experimentalvoid
setVoxels(int x0, int y0, int z0, int w, int h, int d, float[] voxels, int channel)
Experimentalint
size()
Returns the number of slices in this stack.java.lang.String
toString()
void
trim()
Frees memory by deleting a few slices from the end of the stack.void
update(ImageProcessor ip)
Updates this stack so its attributes, such as min, max, calibration table and color model, are the same as 'ip'.
-
-
-
Constructor Detail
-
ImageStack
public ImageStack()
Default constructor.
-
ImageStack
public ImageStack(int width, int height)
Creates a new, empty image stack.
-
ImageStack
public ImageStack(int width, int height, int size)
Creates a new, empty image stack with a capacity of 'size'. All 'size' slices and labels of this image stack are initially null.
-
ImageStack
public ImageStack(int width, int height, java.awt.image.ColorModel cm)
Creates a new, empty image stack using the specified color model.
-
-
Method Detail
-
addSlice
public void addSlice(java.lang.String sliceLabel, java.lang.Object pixels)
Adds an image in the form of a pixel array to the end of the stack.
-
addUnsignedShortSlice
public void addUnsignedShortSlice(java.lang.String sliceLabel, java.lang.Object pixels)
Deprecated.Short images are always unsigned.
-
addSlice
public void addSlice(ImageProcessor ip)
Adds the image in 'ip' to the end of the stack.
-
addSlice
public void addSlice(java.lang.String sliceLabel, ImageProcessor ip)
Adds the image in 'ip' to the end of the stack, setting the string 'sliceLabel' as the slice metadata.
-
addSlice
public void addSlice(java.lang.String sliceLabel, ImageProcessor ip, int n)
Adds the image in 'ip' to the stack following slice 'n'. Adds the slice to the beginning of the stack if 'n' is zero.
-
deleteSlice
public void deleteSlice(int n)
Deletes the specified slice, where 1<=n<=nslices.
-
deleteLastSlice
public void deleteLastSlice()
Deletes the last slice in the stack.
-
getWidth
public int getWidth()
-
getHeight
public int getHeight()
-
setRoi
public void setRoi(java.awt.Rectangle roi)
-
getRoi
public java.awt.Rectangle getRoi()
-
update
public void update(ImageProcessor ip)
Updates this stack so its attributes, such as min, max, calibration table and color model, are the same as 'ip'.
-
getPixels
public java.lang.Object getPixels(int n)
Returns the pixel array for the specified slice, where 1<=n<=nslices.
-
setPixels
public void setPixels(java.lang.Object pixels, int n)
Assigns a pixel array to the specified slice, where 1<=n<=nslices.
-
getImageArray
public java.lang.Object[] getImageArray()
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.
-
size
public int size()
Returns the number of slices in this stack.
-
getSize
public int getSize()
-
getSliceLabels
public java.lang.String[] getSliceLabels()
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.
-
getSliceLabel
public java.lang.String getSliceLabel(int n)
Returns the label of the specified slice, where 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.
-
getShortSliceLabel
public java.lang.String getShortSliceLabel(int n)
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.
-
getShortSliceLabel
public java.lang.String getShortSliceLabel(int n, int max)
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.
-
setSliceLabel
public void setSliceLabel(java.lang.String label, int n)
Sets the label of the specified slice, where 1<=n<=nslices.
-
getProcessor
public ImageProcessor getProcessor(int n)
Returns an ImageProcessor for the specified slice, where 1<=n<=nslices. Returns null if the stack is empty.
-
setProcessor
public void setProcessor(ImageProcessor ip, int n)
Assigns the pixel array of an ImageProcessor to the specified slice, where 1<=n<=nslices.
-
setColorModel
public void setColorModel(java.awt.image.ColorModel cm)
Assigns a new color model to this stack.
-
getColorModel
public java.awt.image.ColorModel getColorModel()
Returns this stack's color model. May return null.
-
isRGB
public boolean isRGB()
Returns true if this is a 3-slice, 8-bit RGB stack.
-
isHSB
public boolean isHSB()
Returns true if this is a 3-slice HSB stack.
-
isHSB32
public boolean isHSB32()
Returns true if this is a 3-slice 32-bit HSB stack.
-
isLab
public boolean isLab()
Returns true if this is a Lab stack.
-
isVirtual
public boolean isVirtual()
Returns true if this is a virtual (disk resident) stack. This method is overridden by the VirtualStack subclass.
-
trim
public void trim()
Frees memory by deleting a few slices from the end of the stack.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
getVoxel
public final double getVoxel(int x, int y, int z)
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 Also:
ImagePlus.getStackIndex(int, int, int)
-
setVoxel
public final void setVoxel(int x, int y, int z, double value)
-
getVoxels
public float[] getVoxels(int x0, int y0, int z0, int w, int h, int d, float[] voxels)
-
getVoxels
public float[] getVoxels(int x0, int y0, int z0, int w, int h, int d, float[] voxels, int channel)
-
setVoxels
public void setVoxels(int x0, int y0, int z0, int w, int h, int d, float[] voxels)
Experimental
-
setVoxels
public void setVoxels(int x0, int y0, int z0, int w, int h, int d, float[] voxels, int channel)
Experimental
-
drawSphere
public void drawSphere(double radius, int xc, int yc, int zc)
Experimental
-
getBitDepth
public int getBitDepth()
Returns the bit depth (8=byte, 16=short, 24=RGB, 32=float).
-
setBitDepth
public void setBitDepth(int depth)
Sets the bit depth (8=byte, 16=short, 24=RGB, 32=float).
-
create
public static ImageStack create(int width, int height, int depth, int bitdepth)
Creates a new ImageStack.- Parameters:
width
- width in pixelsheight
- height in pixelsdepth
- number of imagesbitdepth
- 8, 16, 32 (float) or 24 (RGB)
-
create
public static ImageStack create(ImagePlus[] images)
Creates an ImageStack from an ImagePlus array.
-
duplicate
public ImageStack duplicate()
Duplicates this stack.
-
crop
public ImageStack crop(int x, int y, int z, int width, int height, int depth)
Creates a new stack by cropping this one.
-
convertToFloat
public ImageStack convertToFloat()
Creates a float version of this stack.
-
setOptions
public void setOptions(java.lang.String options)
-
-