- Direct Known Subclasses:
ScalarAccessor
,VectorAccessor
An 'image accessor' is a wrapper around some ImageProcessor
object to allow unified (read and write) access
to its pixels values. This abstract class defines unified access functionality to all 4 types of images available in
ImageJ: 8-bit, 16-bit, float, and color images. All pixel values are of type float[]
, either containing a
single element (for scalar-valued images) or three elements (for color images).
A generic ImageAccessor
is created, e.g., by create(ImageProcessor)
, which returns an instance of
ByteAccessor
, ShortAccessor
, FloatAccessor
or RgbAccessor
. ImageAccessor
itself can access any ImageJ image using the methods getPix(int, int)
, getPix(double, double)
for
retrieving pixel values and setPix(int, int, float[])
to modify pixel values.
In addition, the accessors for scalar-valued images (ByteAccessor
, ShortAccessor
,
FloatAccessor
) provide the methods ScalarAccessor.getVal(int, int)
,
ScalarAccessor.getVal(double, double)
and ScalarAccessor.setVal(int, int, float)
to read and write
scalar-valued pixels passed as single float
values.
The methods getPix(double, double)
and
ScalarAccessor.getVal(double, double)
perform interpolation at non-integer coordinates using the specified
InterpolationMethod
.
A related concept for providing unified access to images is PixelPack
, which copies all pixel data to
internal float
arrays. In contrast to PixelPack
, ImageAccessor
does not duplicate any data
but reads and writes the original ImageProcessor
pixel data directly.
- Version:
- 2020/12/27
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final InterpolationMethod
The default pixel interpolation method (seeInterpolationMethod
).static final OutOfBoundsStrategy
The default out-of-bounds strategy (seeOutOfBoundsStrategy
).protected final float
protected final int
protected final GridIndexer2D
protected final InterpolationMethod
protected final ImageProcessor
protected final OutOfBoundsStrategy
protected final int
-
Method Summary
Modifier and TypeMethodDescriptionstatic final ImageAccessor
create
(ImageProcessor ip) Creates a newImageAccessor
instance for the given image, using the default out-of-bounds strategy and interpolation method.static ImageAccessor
create
(ImageProcessor ip, OutOfBoundsStrategy obs, InterpolationMethod ipm) Creates a newImageAccessor
instance for the given image, using the specified out-of-bounds strategy and interpolation method.abstract ScalarAccessor
getComponentAccessor
(int k) Returns theImageAccessor
for the k-th component; the result is a sub-type ofScalarAccessor
.abstract int
getDepth()
Returns the depth (number of components) of this image accessor.int
Returns the height of the associated image.Returns theInterpolationMethod
specified for thisImageAccessor
.Returns theOutOfBoundsStrategy
specified for thisImageAccessor
.abstract float[]
getPix
(double x, double y) Returns the interpolated pixel value for the specified floating-point position as afloat[]
with either 1 element for scalar-valued images and or more elements (e.g., 3 for for RGB images).abstract float[]
getPix
(int u, int v) Returns the pixel value for the specified floating-point position as afloat[]
with either 1 element for scalar-valued images and or more elements (e.g., 3 for for RGB images).Returns the sourceImageProcessor
associated with thisImageAccessor
.abstract float
getVal
(double x, double y, int k) Returns the interpolated value of the pixel's k-th component at the specified position.abstract float
getVal
(int u, int v, int k) Returns the value of the pixel's k-th component at the specified position.int
getWidth()
Returns the width of the associated image.abstract void
setPix
(int u, int v, float[] val) Sets the pixel value at the specified integer position.abstract void
setVal
(int u, int v, int k, float val) Sets the value of the pixel's k-th component at the specified position.
-
Field Details
-
DefaultOutOfBoundsStrategy
The default out-of-bounds strategy (seeOutOfBoundsStrategy
). -
DefaultInterpolationMethod
The default pixel interpolation method (seeInterpolationMethod
). -
defaultValue
- See Also:
-
ip
-
width
-
height
-
indexer
-
outOfBoundsStrategy
-
interpolationMethod
-
-
Method Details
-
create
Creates a newImageAccessor
instance for the given image, using the default out-of-bounds strategy and interpolation method. The concrete type of the returned instance depends on the specified image.- Parameters:
ip
- the source image- Returns:
- a new
ImageAccessor
instance
-
create
public static ImageAccessor create(ImageProcessor ip, OutOfBoundsStrategy obs, InterpolationMethod ipm) Creates a newImageAccessor
instance for the given image, using the specified out-of-bounds strategy and interpolation method. The concrete type of the returned instance depends on the specified image.- Parameters:
ip
- the source imageobs
- the out-of-bounds strategy (usenull
for default settings)ipm
- the interpolation method (usenull
for default settings)- Returns:
- a new
ImageAccessor
instance
-
getWidth
Returns the width of the associated image.- Returns:
- the image width.
-
getHeight
Returns the height of the associated image.- Returns:
- the image height.
-
getProcessor
Returns the sourceImageProcessor
associated with thisImageAccessor
.- Returns:
- the image processor
-
getDepth
Returns the depth (number of components) of this image accessor. 1 is returned if the image is scalar-valued.- Returns:
- the image depth.
-
getOutOfBoundsStrategy
Returns theOutOfBoundsStrategy
specified for thisImageAccessor
.- Returns:
- the out-of-bounds strategy
-
getInterpolationMethod
Returns theInterpolationMethod
specified for thisImageAccessor
.- Returns:
- the interpolation method
-
getPix
Returns the pixel value for the specified floating-point position as afloat[]
with either 1 element for scalar-valued images and or more elements (e.g., 3 for for RGB images).- Parameters:
u
- the x-coordinatev
- the y-coordinate- Returns:
- the pixel value (
float[]
)
-
getPix
Returns the interpolated pixel value for the specified floating-point position as afloat[]
with either 1 element for scalar-valued images and or more elements (e.g., 3 for for RGB images). Interpolation is used non-integer coordinates.- Parameters:
x
- the x-coordinatey
- the y-coordinate- Returns:
- the interpolated pixel value (
float[]
)
-
setPix
Sets the pixel value at the specified integer position. The new value must be provided asfloat[]
with 1 element for scalar-valued images or 3 elements for RGB images.- Parameters:
u
- the x-coordinatev
- the y-coordinateval
- the new pixel value (float[]
)
-
getVal
Returns the value of the pixel's k-th component at the specified position. If the associated image is scalar-valued, this is equivalent to component 0. See alsogetDepth()
.- Parameters:
u
- the x-coordinatev
- the y-coordinatek
- the component index- Returns:
- the component value (
float
)
-
getVal
Returns the interpolated value of the pixel's k-th component at the specified position. If the associated image is scalar-valued, this is equivalent to component 0. See alsogetDepth()
.- Parameters:
x
- the x-coordinatey
- the y-coordinatek
- the component index- Returns:
- the interpolated component value (
float[]
)
-
setVal
Sets the value of the pixel's k-th component at the specified position. If the associated image is scalar-valued, this is equivalent to component 0. See alsogetDepth()
.- Parameters:
u
- the x-coordinatev
- the y-coordinatek
- the component indexval
- the new component value
-
getComponentAccessor
Returns theImageAccessor
for the k-th component; the result is a sub-type ofScalarAccessor
. In the case of a scalar-valued image, THIS object is returned.- Parameters:
k
- the component index- Returns:
- the component accessor.
-