- Direct Known Subclasses:
ColorPack
This class defines a generic data container for scalar and vector-valued images, using float-values throughout. Its
primary use is in the GenericFilter framework. A PixelPack may represent images with an arbitrary
number of components. Scalar images (such as ByteProcessor, ShortProcessor and
FloatProcessor) have 1 component, color images (such as ColorProcessor) typically have 3 components.
Conversion methods to and from ImageJ's processor classes are provided, with optional scaling of pixel component
values.
Internally, pixel data are stored as 1-dimensional float arrays, one array for each component. Method
getData() may be used to access the internal data directly. Individual components may be extracted as a
PixelPack.PixelSlice using method getSlice(int).
Methods getPix(int, int) and setPix(int, int, float...) are provided to read and write individual
pixels, which are ALWAYS of type float[] (even if the underlying image is scalar-valued). Pixel values
returned for positions outside the image boundaries depend on the OutOfBoundsStrategy specified by the
constructor (e.g., PixelPack(ImageProcessor, double, OutOfBoundsStrategy)).
Here is a simple usage example:
ColorProcessor ip1 = ... ; // some color image PixelPack pack = new PixelPack(ip1); // process pack: float[] val = pack.getPix(0, 0); pack.setPix(0, 0, 128, 19, 255); ... ColorProcessor ip2 = pack.toColorProcessor();
A related concept for providing unified access to images is ImageAccessor. In contrast to PixelPack,
ImageAccessor does not duplicate any data but reads and writes the original ImageProcessor pixel data
directly.
- Version:
- 2022/09/03
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclassInner class representing a single (scalar-valued) component of a (vector-valued)PixelPack. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final float[][]static final OutOfBoundsStrategyThe default out-of-bounds strategy (seeOutOfBoundsStrategy).protected final intprotected final intprotected final intprotected final int -
Constructor Summary
ConstructorsConstructorDescriptionPixelPack(int width, int height, int depth, OutOfBoundsStrategy obs) Constructor, creates a blank (zero-valued) pack of pixel data.Constructor, creates a pack of pixel data from the givenImageProcessorobject.PixelPack(ImageProcessor ip, double scale, OutOfBoundsStrategy obs) Constructor, reates a pack of pixel data from the givenImageProcessorobject, using the specified out-of-bounds strategy.Constructor, creates a newPixelPackwith the same dimension as the original without copying the contained pixel data (initialized to zero).Constructor, creates a newPixelPackwith the same dimension as the original. -
Method Summary
Modifier and TypeMethodDescriptionvoidCopies the contents of an image processor to an existing pixel pack, which must be compatible w.r.t. size and depth.voidcopyFromImageProcessor(ImageProcessor ip, double scale) Copies the contents of an image processor to an existing pixel pack, which must be compatible w.r.t. size and depth.voidCopies the contents of one pixel pack to another.voidCopies the contents of a pixel pack to an existing image processor.voidcopyToImageProcessor(ImageProcessor ip, double scale) Copies the contents of a pixel pack to an existing image processor.float[][][]get3x3Neighborhood(int uc, int vc, float[][][] nh) Returns the pixel values in the 3x3 neighborhood around the specified position.float[][]getData()Returns a reference to thisPixelPack's internal data array, which is always two-dimensional: dimension 1 is the slice (component) index, dimension 2 is the pixel index (each slice is a 1D array).intgetDepth()Returns the depth (number of slices) of the associated image.Creates and returns a newPixelPack.PixelSlicewith the same dimensions and out-of-bounds strategy as thisPixelPack.getFloatProcessor(int k) Returns theFloatProcessorfor the kth pixel slice.Returns an array ofFloatProcessorinstances for thisPixelPack.intReturns the height of the associated image.Returns the out-of-bounds strategy.float[]getPix(int idx) Returns the pixel data at the specified position as afloat[].voidgetPix(int idx, float[] vals) Reads the pixel data at the specified 1D index.float[]getPix(int u, int v) Returns the pixel data at the specified position as afloat[].voidgetPix(int u, int v, float[] vals) Reads the pixel data at the specified image position.getSlice(int k) Returns the kthPixelPack.PixelSlice.Returns an array ofPixelPack.PixelSliceinstances for thisPixelPack.float[]getVec(int u, int v) Deprecated.float[]getVec(int u, int v, float[] vals) Deprecated.intgetWidth()Returns the width of the associated image.booleanChecks is this pixel pack has the same dimensions as the specifiedImageProcessorinstance, i.e., can be copied to it.booleanisCompatibleTo(PixelPack other) Checks is this pixel pack has the same dimensions as another pixel pack, i.e., can be copied to it.voidsetPix(int idx, float... vals) voidsetPix(int u, int v, float... vals) Sets the pixel data at the specified pixel position.voidsetVec(int u, int v, float... vals) Deprecated.Converts thisPixelPackto a newByteProcessorinstance.toByteProcessor(double scale) Converts thisPixelPackto a newByteProcessorinstance.Converts thisPixelPackto a newColorProcessorinstance.toColorProcessor(double scale) Converts thisPixelPackto a newColorProcessorinstance.Converts thisPixelPackto a newFloatProcessorinstance.toFloatProcessor(double scale) Converts thisPixelPackto a newFloatProcessorinstance.Converts thisPixelPackto a newShortProcessorinstance.toShortProcessor(double scale) Converts thisPixelPackto a newShortProcessorinstance.voidzero()Sets all values of this pixel pack to zero.
-
Field Details
-
DefaultOutOfBoundsStrategy
The default out-of-bounds strategy (seeOutOfBoundsStrategy). -
width
-
height
-
depth
-
data
-
length
-
-
Constructor Details
-
PixelPack
Constructor, creates a blank (zero-valued) pack of pixel data.- Parameters:
width- the image widthheight- the image heightdepth- the number of channels (slices)obs- strategy to be used when reading from out-of-bounds coordinates (passnullfor default)
-
PixelPack
Constructor, creates a pack of pixel data from the givenImageProcessorobject. Does not scale pixel values and usesDefaultOutOfBoundsStrategyas the out-of-bounds strategy (seeOutOfBoundsStrategy).- Parameters:
ip- the source image
-
PixelPack
Constructor, reates a pack of pixel data from the givenImageProcessorobject, using the specified out-of-bounds strategy.- Parameters:
ip- the source imagescale- scale factor applied to pixel componentsobs- strategy to be used when reading from out-of-bounds coordinates (passnullfor default)
-
PixelPack
Constructor, creates a newPixelPackwith the same dimension as the original without copying the contained pixel data (initialized to zero).- Parameters:
orig- the originalPixelPack
-
PixelPack
Constructor, creates a newPixelPackwith the same dimension as the original. Optionally the original pixel data are copied, otherwise they are initialized to zero values.- Parameters:
orig- the originalPixelPackcopyData- set true to copy pixel data
-
-
Method Details
-
getVec
Deprecated. -
getVec
Deprecated. -
setVec
Deprecated. -
getPix
Reads the pixel data at the specified image position. The supplied array is filled. The length of this array must match corresponds the number of slices in this pixel pack. The values returned for out-of-bounds positions depend on this pixel-pack's out-of-bounds strategy.- Parameters:
u- the x-positionv- the y-positionvals- a suitable array of pixel data
-
getPix
Returns the pixel data at the specified position as afloat[]. The values returned for out-of-bounds positions depend on this pixel-pack's out-of-bounds strategy.- Parameters:
u- the x-positionv- the y-position- Returns:
- the array of pixel component values
-
getPix
Reads the pixel data at the specified 1D index. The supplied array is filled. The length of this array must match corresponds the number of slices in this pixel pack. The index is not checked, the corresponding pixel must always be inside the image bounds, otherwise an exception will be thrown.- Parameters:
idx- a valid 1D pixel index (in row-major order)vals- a suitable array of pixel data
-
getPix
Returns the pixel data at the specified position as afloat[]. The index is not checked, the corresponding pixel must always be inside the image bounds, otherwise an exception will be thrown.- Parameters:
idx- a valid 1D pixel index (in row-major order)- Returns:
- the array of pixel component values
-
setPix
Sets the pixel data at the specified pixel position. The length of the value array corresponds to the number of slices (components) in this pixel pack.- Parameters:
u- the x-positionv- the y-positionvals- the pixel's component values (may also be afloat[])
-
setPix
-
copyTo
Copies the contents of one pixel pack to another. The involved pixel packs must have the same dimensions.- Parameters:
other- another pixel pack
-
isCompatibleTo
Checks is this pixel pack has the same dimensions as another pixel pack, i.e., can be copied to it.- Parameters:
other- the other pixel pack- Returns:
- true if both have the same dimensions
-
isCompatibleTo
Checks is this pixel pack has the same dimensions as the specifiedImageProcessorinstance, i.e., can be copied to it.- Parameters:
ip- the image processor instance- Returns:
- true if compatible
-
getSlice
Returns the kthPixelPack.PixelSlice. An exception is thrown if the specified slice does not exist.- Parameters:
k- the slice index (0,...,K-1)- Returns:
- the kth
PixelPack.PixelSlice - Throws:
IllegalArgumentException- if slice with the given index does not exist
-
getEmptySlice
Creates and returns a newPixelPack.PixelSlicewith the same dimensions and out-of-bounds strategy as thisPixelPack.- Returns:
- a new pixel slice
-
getSlices
Returns an array ofPixelPack.PixelSliceinstances for thisPixelPack. All pixel data are shared.- Returns:
- an array of
PixelPack.PixelSlice
-
getFloatProcessor
Returns theFloatProcessorfor the kth pixel slice. An exception is thrown if the specified slice does not exist.- Parameters:
k- the slice index (0,...,K-1)- Returns:
- the kth
FloatProcessor
-
getFloatProcessors
Returns an array ofFloatProcessorinstances for thisPixelPack. All pixel data are shared.- Returns:
- an array of
FloatProcessor
-
getData
Returns a reference to thisPixelPack's internal data array, which is always two-dimensional: dimension 1 is the slice (component) index, dimension 2 is the pixel index (each slice is a 1D array).- Returns:
- the pixel pack's data array
-
getWidth
Returns the width of the associated image.- Returns:
- the image width
-
getHeight
Returns the height of the associated image.- Returns:
- the image height
-
getDepth
Returns the depth (number of slices) of the associated image.- Returns:
- the image depth
-
getOutOfBoundsStrategy
Returns the out-of-bounds strategy.- Returns:
- the out-of-bounds strategy
-
zero
Sets all values of this pixel pack to zero. -
get3x3Neighborhood
Returns the pixel values in the 3x3 neighborhood around the specified position. The returned float-array has the structure[x][y][k], with x,y = 0,...,2 and k is the slice index.- Parameters:
uc- the center x-positionvc- the center x-positionnh- a float array to be filled in (or null)- Returns:
- the neighborhood array
-
copyFromImageProcessor
Copies the contents of an image processor to an existing pixel pack, which must be compatible w.r.t. size and depth. Does not scale pixel values.- Parameters:
ip- the image processor to be copied
-
copyFromImageProcessor
Copies the contents of an image processor to an existing pixel pack, which must be compatible w.r.t. size and depth. Applies the specified scale factor to the pixel component values.- Parameters:
ip- the image processor to be copiedscale- scale factor applied to pixel component values
-
toByteProcessor
Converts thisPixelPackto a newByteProcessorinstance. An exception is thrown if the depth of the pack is not equal 1. Pixel values are rounded, no scale factor is applied.- Returns:
- a new
ByteProcessorinstance
-
toByteProcessor
Converts thisPixelPackto a newByteProcessorinstance. An exception is thrown if the depth of the pack is not equal 1. Applies the specified scale factor to pixel values.- Parameters:
scale- scale factor applied to pixel values (before rounding)- Returns:
- a new
ByteProcessorinstance
-
toShortProcessor
Converts thisPixelPackto a newShortProcessorinstance. An exception is thrown if the depth of the pack is not equal 1. Pixel values are rounded, no scale factor is applied.- Returns:
- a new
ShortProcessorinstance
-
toShortProcessor
Converts thisPixelPackto a newShortProcessorinstance. An exception is thrown if the depth of the pack is not equal 1. Applies the specified scale factor to pixel values.- Parameters:
scale- scale factor applied to pixel values (before rounding)- Returns:
- a new
ShortProcessorinstance
-
toFloatProcessor
Converts thisPixelPackto a newFloatProcessorinstance. An exception is thrown if the depth of the pack is not equal 1. No scale factor is applied to pixel values.- Returns:
- a new
FloatProcessorinstance
-
toFloatProcessor
Converts thisPixelPackto a newFloatProcessorinstance. An exception is thrown if the depth of the pack is not equal 1.- Parameters:
scale- scale factor applied to pixel values- Returns:
- a new
FloatProcessorinstance
-
toColorProcessor
Converts thisPixelPackto a newColorProcessorinstance. An exception is thrown if the depth of the pack is not equal 3. Component values are rounded, no scale factor is applied.- Returns:
- a new
ColorProcessorinstance
-
toColorProcessor
Converts thisPixelPackto a newColorProcessorinstance. An exception is thrown if the depth of the pack is not equal 3.- Parameters:
scale- scale factor applied to component values (before rounding)- Returns:
- a new
ColorProcessorinstance
-
toImageStack
Converts thisPixelPackto a newImageStackwith the same number of slices (seegetDepth()). The stack images are of typeFloatProcessor. The resultingImageStackdoes not share any pixel data with thisPixelPack.- Returns:
- a new
ImageStackinstance
-
copyToImageProcessor
Copies the contents of a pixel pack to an existing image processor. They must be compatible w.r.t. size and depth. Component values are rounded if necessary, no scale factor is applied.- Parameters:
ip- the receiving image processor
-
copyToImageProcessor
Copies the contents of a pixel pack to an existing image processor. They must be compatible w.r.t. size and depth. Component values are rounded if necessary, after the specified scale factor is applied.- Parameters:
ip- the receiving image processorscale- scale factor applied to pixel values
-