- 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 TypeClassDescriptionclass
Inner class representing a single (scalar-valued) component of a (vector-valued)PixelPack
. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final float[][]
static final OutOfBoundsStrategy
The default out-of-bounds strategy (seeOutOfBoundsStrategy
).protected final int
protected final int
protected final int
protected 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 givenImageProcessor
object.PixelPack
(ImageProcessor ip, double scale, OutOfBoundsStrategy obs) Constructor, reates a pack of pixel data from the givenImageProcessor
object, using the specified out-of-bounds strategy.Constructor, creates a newPixelPack
with the same dimension as the original without copying the contained pixel data (initialized to zero).Constructor, creates a newPixelPack
with the same dimension as the original. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Copies the contents of an image processor to an existing pixel pack, which must be compatible w.r.t.void
copyFromImageProcessor
(ImageProcessor ip, double scale) Copies the contents of an image processor to an existing pixel pack, which must be compatible w.r.t.void
Copies the contents of one pixel pack to another.void
Copies the contents of a pixel pack to an existing image processor.void
copyToImageProcessor
(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).int
getDepth()
Returns the depth (number of slices) of the associated image.Creates and returns a newPixelPack.PixelSlice
with the same dimensions and out-of-bounds strategy as thisPixelPack
.getFloatProcessor
(int k) Returns theFloatProcessor
for the kth pixel slice.Returns an array ofFloatProcessor
instances for thisPixelPack
.int
Returns 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[]
.void
getPix
(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[]
.void
getPix
(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.PixelSlice
instances for thisPixelPack
.float[]
getVec
(int u, int v) Deprecated.float[]
getVec
(int u, int v, float[] vals) Deprecated.int
getWidth()
Returns the width of the associated image.boolean
Checks is this pixel pack has the same dimensions as the specifiedImageProcessor
instance, i.e., can be copied to it.boolean
isCompatibleTo
(PixelPack other) Checks is this pixel pack has the same dimensions as another pixel pack, i.e., can be copied to it.void
setPix
(int idx, float... vals) void
setPix
(int u, int v, float... vals) Sets the pixel data at the specified pixel position.void
setVec
(int u, int v, float... vals) Deprecated.Converts thisPixelPack
to a newByteProcessor
instance.toByteProcessor
(double scale) Converts thisPixelPack
to a newByteProcessor
instance.Converts thisPixelPack
to a newColorProcessor
instance.toColorProcessor
(double scale) Converts thisPixelPack
to a newColorProcessor
instance.Converts thisPixelPack
to a newFloatProcessor
instance.toFloatProcessor
(double scale) Converts thisPixelPack
to a newFloatProcessor
instance.Converts thisPixelPack
to a newShortProcessor
instance.toShortProcessor
(double scale) Converts thisPixelPack
to a newShortProcessor
instance.void
zero()
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 (passnull
for default)
-
PixelPack
Constructor, creates a pack of pixel data from the givenImageProcessor
object. Does not scale pixel values and usesDefaultOutOfBoundsStrategy
as the out-of-bounds strategy (seeOutOfBoundsStrategy
).- Parameters:
ip
- the source image
-
PixelPack
Constructor, reates a pack of pixel data from the givenImageProcessor
object, 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 (passnull
for default)
-
PixelPack
Constructor, creates a newPixelPack
with the same dimension as the original without copying the contained pixel data (initialized to zero).- Parameters:
orig
- the originalPixelPack
-
PixelPack
Constructor, creates a newPixelPack
with the same dimension as the original. Optionally the original pixel data are copied, otherwise they are initialized to zero values.- Parameters:
orig
- the originalPixelPack
copyData
- 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 specifiedImageProcessor
instance, 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.PixelSlice
with the same dimensions and out-of-bounds strategy as thisPixelPack
.- Returns:
- a new pixel slice
-
getSlices
Returns an array ofPixelPack.PixelSlice
instances for thisPixelPack
. All pixel data are shared.- Returns:
- an array of
PixelPack.PixelSlice
-
getFloatProcessor
Returns theFloatProcessor
for 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 ofFloatProcessor
instances 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 thisPixelPack
to a newByteProcessor
instance. 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
ByteProcessor
instance
-
toByteProcessor
Converts thisPixelPack
to a newByteProcessor
instance. 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
ByteProcessor
instance
-
toShortProcessor
Converts thisPixelPack
to a newShortProcessor
instance. 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
ShortProcessor
instance
-
toShortProcessor
Converts thisPixelPack
to a newShortProcessor
instance. 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
ShortProcessor
instance
-
toFloatProcessor
Converts thisPixelPack
to a newFloatProcessor
instance. 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
FloatProcessor
instance
-
toFloatProcessor
Converts thisPixelPack
to a newFloatProcessor
instance. 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
FloatProcessor
instance
-
toColorProcessor
Converts thisPixelPack
to a newColorProcessor
instance. 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
ColorProcessor
instance
-
toColorProcessor
Converts thisPixelPack
to a newColorProcessor
instance. 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
ColorProcessor
instance
-
toImageStack
Converts thisPixelPack
to a newImageStack
with the same number of slices (seegetDepth()
). The stack images are of typeFloatProcessor
. The resultingImageStack
does not share any pixel data with thisPixelPack
.- Returns:
- a new
ImageStack
instance
-
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
-