Enum Class PixelDataType
- All Implemented Interfaces:
Serializable
,Comparable<PixelDataType>
,Constable
ReadableImage
.
The class contains many methods for performing operations on pixels of these different data types.
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Enum
Enum.EnumDesc<E extends Enum<E>>
-
Enum Constant Summary
Enum ConstantDescriptionPixelDataType
for 1-bit per pixel.PixelDataType
for signed byte.PixelDataType
for colour packed (UNC).PixelDataType
for complex (2x32-bit float in real/imaginary interlaced pairs).PixelDataType
for double (64-bit).PixelDataType
for double complex (2x64-bit double in real/imaginary interlaced pairs).PixelDataType
for double double (128-bit) - not implemented.PixelDataType
for double double complex (2x128-bit double in real/imaginary interlaced pairs) - not implemented.PixelDataType
for float (32-bit).PixelDataType
for signed int (32-bit).PixelDataType
for signed long (64-bit integer).PixelDataType
for RGB (24-bit) - red plane followed by the green plane followed by the blue plane (non-interlaced).PixelDataType
for RGB (24-bit) with one red value followed by one blue value followed by one green value, etc.PixelDataType
for signed short (16-bit).PixelDataType
for unsigned byte.PixelDataType
for unsigned int (32-bit).PixelDataType
for unsigned long (64-bit integer).PixelDataType
for a type that hasn't been set.PixelDataType
for signed short (16-bit). -
Method Summary
Modifier and TypeMethodDescriptioncoerce
(Object primitiveValues, PixelDataType toType, boolean clipIfNecessary) Coerce pixels of thisPixelDataType
to a newPixelDataType
.coerce
(Object primitiveValues, PixelDataType toType, int pixStart, int nPixels, ComplexMode complexMode, boolean clipIfNecessary) Coerce pixels of thisPixelDataType
to a newPixelDataType
.coerce
(Object primitiveValues, PixelDataType toType, ComplexMode complexMode, boolean clipIfNecessary) Coerce pixels of thisPixelDataType
to a newPixelDataType
.coerceOneValue
(Object value, PixelDataType toType) Coerces a single pixel value to the given PixelDataType.coerceOneValue
(Object value, PixelDataType toType, ComplexMode complexMode) Coerce a single pixel of thisPixelDataType
to a newPixelDataType
.copyPixels
(Object pixelArray) Copies the pixel samples to a new array of the correct type for this type of pixel.copyPixels
(Object sourceArray, int pixelOffset, Object dstArray) Copies the pixel samples to an array of the correct type for this type of pixel.copyPixels
(Object sourceArray, Object dstArray) Copies the pixel samples to an array of the correct type for this type of pixel.copyPixels
(Object sourceArray, Object dstArray, int pixelOffset) Copies the pixel samples to an array of the correct type for this type of pixel.void
Flips an array of pixels in-place about the x-axis (ie, flips top to bottom).void
Flips an array of pixels in-place about the y-axis (ie flips left-right).int
Returns the number of array elements of a primitive type needed to store a single pixel value.int
Returns the number of bits used to store one pixel for this data type.getColorValue
(Object pixelArray, int index) Gets a single colour pixel value from an array of pixels.getComplexValue
(Object pixelArray, int index) Gets a single Complex pixel value from an array of pixels.double
getDoubleValue
(Object pixelArray, int index) Gets a single pixel value from an array of pixels.double
getDoubleValue
(Object pixelValue, ComplexMode complexMode) Converts a single pixel value to adouble
value.static short
getLuminance
(Color color) Returns the luminance value of a Color.double[]
Returns the minimum and maximum intensity values that are present in an array of pixel values.double[]
getMinMax
(Object pixelArray, int fromIndex, int count, ComplexMode complexMode) Returns the minimum and maximum intensity values that are present in subset of an array of pixel values.double[]
getMinMax
(Object pixelArray, ComplexMode complexMode) Returns the minimum and maximum intensity values that are present in an array of pixel values.int
getNPixels
(Object pixelArray) Returns the number of pixels in the supplied array of pixel samples.Gets an array of pixel samples, large enough to hold a specified number of pixels.float[]
getPixelsAsFloat
(Object pixelArray) Returns a set of pixel samples as an array offloat
values.float[]
getPixelsAsFloat
(Object pixelArray, int pixStart, int nPixels) Returns a set of pixel samples as an array offloat
values.getPixelValue
(Object pixelArray, int col, int row, int nCols, int nRows, int offset) Gets the pixel value at a particular (column, row) of an array of pixels of thisPixelDataType
.Returns the Class of primitive used to store pixel values of thisPixelDataType
.double
Returns the maximum value that a pixel of thisPixelDataType
can take.double
Returns the minimum value that a pixel of thisPixelDataType
can take.interpolate
(Object pixelValue1, double pixelValue2, double alpha) Interpolates between two pixel intensity values.boolean
Tests whether thisPixelDataType
specifies explicitly the red,green,blue colour components to display, rather than needing aColourMapping
to display.boolean
Returnstrue
if thisPixelDataType
is a complex (real/imaginary) data type.boolean
Tests whether thisPixelDataType
is a floating-point (single or double precision) data type.boolean
Tests whether a sample of thisPixelDataType
can be represented by a singleint
value (Note: not integer).boolean
isNarrowerThan
(PixelDataType type) Tests whether thisPixelDataType
is not capable of storing all values that can be stored by the suppliedtype
without clipping.static void
Runs the self-test of this class.void
rotate
(Object pixArray, RotationAngle rotationAngle, int nCols, int nRows) Rotates (slice-by-slice) an array of pixels in-place, by multiples of 90 degrees.void
Scale pixel intensities "in-place".void
Scale pixel intensities "in-place".void
setColorValue
(Object pixelArray, Color color, int index) Sets a single colour pixel value into an array of pixels.void
setComplexValue
(Object pixelArray, Complex cmplx, int index) Sets a single complex pixel value into an array of pixels.void
Sets the values of an array of pixel samples, copying the values from another array.void
setPixelValue
(Object pixelArray, int col, int row, int nCols, int nRows, int offset, Object value) Sets the pixel value at a particular (column, row) of an array of pixels of thisPixelDataType
.void
Sets a single pixel value in an array of pixels to the given value.void
Add a constant factor to pixel intensities "in-place".void
Add a constant factor to pixel intensities "in-place".static short
toLuminance
(byte red, byte green, byte blue) Converts three (unsigned) byte values, representing the red, green and blue components of a colour to a luminance.toString()
Returns aString
describing thisPixelDataType
.void
Transposes (slice-by-slice) an array of pixels in-place (ie flips top-right to bottom-left).static PixelDataType
Returns the enum constant of this class with the specified name.static PixelDataType[]
values()
Returns an array containing the constants of this enum class, in the order they are declared.
-
Enum Constant Details
-
UNDEFINED
PixelDataType
for a type that hasn't been set. -
BINARY
PixelDataType
for 1-bit per pixel. -
BYTE
PixelDataType
for signed byte. -
UBYTE
PixelDataType
for unsigned byte. -
SHORT
PixelDataType
for signed short (16-bit). -
USHORT
PixelDataType
for signed short (16-bit). -
INT
PixelDataType
for signed int (32-bit). -
UINT
PixelDataType
for unsigned int (32-bit). -
FLOAT
PixelDataType
for float (32-bit). -
DOUBLE
PixelDataType
for double (64-bit). -
COMPLEX
PixelDataType
for complex (2x32-bit float in real/imaginary interlaced pairs). -
COLOURPACKED
PixelDataType
for colour packed (UNC). -
RGB_BY_PLANE
PixelDataType
for RGB (24-bit) - red plane followed by the green plane followed by the blue plane (non-interlaced). -
RGB_INTERLACED
PixelDataType
for RGB (24-bit) with one red value followed by one blue value followed by one green value, etc. (interlaced). -
LONG
PixelDataType
for signed long (64-bit integer). -
ULONG
PixelDataType
for unsigned long (64-bit integer). -
DOUBLECOMPLEX
PixelDataType
for double complex (2x64-bit double in real/imaginary interlaced pairs). -
DOUBLEDOUBLE
PixelDataType
for double double (128-bit) - not implemented. -
DOUBLEDOUBLECOMPLEX
PixelDataType
for double double complex (2x128-bit double in real/imaginary interlaced pairs) - not implemented.
-
-
Method Details
-
values
Returns an array containing the constants of this enum class, in the order they are declared.- Returns:
- an array containing the constants of this enum class, in the order they are declared
-
valueOf
Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)- Parameters:
name
- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException
- if this enum class has no constant with the specified nameNullPointerException
- if the argument is null
-
getRangeMin
public double getRangeMin()Returns the minimum value that a pixel of thisPixelDataType
can take. In the case ofPixelDataType
that have more than one primitive data element per pixel, (e.g., RGB_BY_PLANE, COMPLEX etc.) this method returns the minimum value for one of the data elements.- Returns:
- the minimum value that a pixel can take.
-
getRangeMax
public double getRangeMax()Returns the maximum value that a pixel of thisPixelDataType
can take. In the case ofPixelDataType
that have more than one primitive data element per pixel, (e.g., RGB_BY_PLANE, COMPLEX etc.) this method returns the maximum value for one of the primitive data elements.- Returns:
- the maximum value that a pixel can take.
-
isColourType
public boolean isColourType()Tests whether thisPixelDataType
specifies explicitly the red,green,blue colour components to display, rather than needing aColourMapping
to display.- Returns:
true
if thisPixelDataType
specifies the red,green,blue colour components;false
otherwise.
-
isFloatingPointType
public boolean isFloatingPointType()Tests whether thisPixelDataType
is a floating-point (single or double precision) data type.- Returns:
true
if thisPixelDataType
is a floating-point data type.
-
isIntegerType
public boolean isIntegerType()Tests whether a sample of thisPixelDataType
can be represented by a singleint
value (Note: not integer). UINT, LONG and ULONG cannot, in general, be represented by an int.- Returns:
true
if thisPixelDataType
can be represented by a single integer value;false
otherwise.
-
toString
Returns aString
describing thisPixelDataType
.- Overrides:
toString
in classEnum<PixelDataType>
- Returns:
- a
String
describing thisPixelDataType
.
-
getBitsPerPixel
public int getBitsPerPixel()Returns the number of bits used to store one pixel for this data type.- Returns:
- the number of bits used to store one pixel of this data type.
-
getArrayElementsPerPixel
public int getArrayElementsPerPixel()Returns the number of array elements of a primitive type needed to store a single pixel value. ForBINARY
, it returns 1.- Returns:
- the number of array elements of a primitive type needed to store a single pixel value of this data type.
-
getPrimitiveClass
Returns the Class of primitive used to store pixel values of thisPixelDataType
.- Returns:
- the Class of primitive used to store pixel values.
- Throws:
IllegalArgumentException
-
isComplex
public boolean isComplex()Returnstrue
if thisPixelDataType
is a complex (real/imaginary) data type.- Returns:
true
if this is a complex data type;false
otherwise.
-
isNarrowerThan
Tests whether thisPixelDataType
is not capable of storing all values that can be stored by the suppliedtype
without clipping.- Parameters:
type
- thePixelDataType
against which this is to be tested.- Returns:
true
if thisPixelDataType
is not capable of storing all values that can be stored by thetype
without clipping;false
otherwise.- Throws:
IllegalArgumentException
-
getNPixels
Returns the number of pixels in the supplied array of pixel samples. The number of pixels is the number of primitive array elements divided by the number of samples per pixel.- Parameters:
pixelArray
- the array of pixel samples.- Returns:
- the number of pixels in the supplied array of pixel samples.
- Throws:
IllegalArgumentException
- if thePixelDataType
is not supported, if the supplied array is not of the correct type for thisPixelDataType
, or if the supplied array is not the right size to hold a whole number of pixels.
-
getPixels
Gets an array of pixel samples, large enough to hold a specified number of pixels. If the source array is null, a new array is created. If the source array is longer than required, it is copied so that the array returned has the required length. Otherwise the sourceArray is returned.- Parameters:
sourceArray
- the array of pixel samples to be re-used, if possible.nPixels
- the number of pixels requested.- Returns:
- either sourceArray (if it is reusable) or a new array of the correct
type for this
PixelDataType
, just long enough to hold the requested number of pixels. - Throws:
IllegalArgumentException
- if the sourceArray is of the wrong data type or is too short.
-
copyPixels
Copies the pixel samples to a new array of the correct type for this type of pixel.- Parameters:
pixelArray
- the array of pixel samples to be copied.- Returns:
- a copy of the array of supplied pixel samples.
- Throws:
IllegalArgumentException
- if the supplied array is not of the correct type for thisPixelDataType
.
-
copyPixels
Copies the pixel samples to an array of the correct type for this type of pixel.- Parameters:
sourceArray
- the array of pixel samples to be copied.dstArray
- the array into which the pixel samples will be copied. If dstArray isnull
, or ifdstArray
is not of the correct type for thisPixelDataType
, or if it is of the wrong length, then a new array will be created.- Returns:
- a copy of the array of supplied pixel samples. If dstArray is
null
, or ifdstArray
is not of the correct type for thisPixelDataType
, or if it is of the wrong length, then a new array will be returned; otherwisedstArray
is returned. - Throws:
IllegalArgumentException
- if the supplied array to be copied is not of the correct type for thisPixelDataType
.
-
copyPixels
public Object copyPixels(Object sourceArray, int pixelOffset, Object dstArray) throws IllegalArgumentException Copies the pixel samples to an array of the correct type for this type of pixel. The number of pixels copied is determined by the size ofdstArray
.- Parameters:
sourceArray
- the array of pixel samples to be copied.pixelOffset
- an offset (in pixels) into thesourceArray
from which pixel values are copied. Copying will start from a pointpixelOffset
into the array (of pixels).dstArray
- the array into which the pixel samples will be copied. The number of pixels copied is determined by the length of this array.- Returns:
dstArray
containing a copy of the array of supplied pixel samples.- Throws:
IllegalArgumentException
- if the supplied array to be copied is not of the correct type for thisPixelDataType
.
-
copyPixels
public Object copyPixels(Object sourceArray, Object dstArray, int pixelOffset) throws IllegalArgumentException Copies the pixel samples to an array of the correct type for this type of pixel.- Parameters:
sourceArray
- the array of pixel samples to be copied.dstArray
- the array into which the pixel samples will be copied. If dstArray isnull
, or if it is of the wrong length, then a new array will be created.pixelOffset
- an offset (in pixels) into the dstArray into which pixel values are copied. Copying will start at a point pixelOffset into the array.- Returns:
- a copy of the array of supplied pixel samples. If dstArray is
null
, then a new array will be returned; otherwise dstArray is returned. - Throws:
IllegalArgumentException
- if the supplied array to be copied is not of the correct type for thisPixelDataType
.
-
setPixels
Sets the values of an array of pixel samples, copying the values from another array. The source and destination array must both be of the same type, and of the same length. The type must be the correct type for thisPixelDataType
.- Parameters:
sourceArray
- an array of pixel values to be copied.dstArray
- an array of pixel data primitives into which the pixel values are to be copied.- Throws:
IllegalArgumentException
- if the souce or destination arrays are of incompatible types, or of incompatible lengths.
-
getPixelsAsFloat
Returns a set of pixel samples as an array offloat
values. The length of the array returned is the number of pixels.For pixel data types where the number of samples per pixel is greater than 1, the following coersions take place:
- Colour data types (
RGB_BY_PLANE
,RGB_INTERLACED
(3 samples per pixel), andCOLOURPACKED
(4 samples per pixel)) images: the colours are converted to luminance values. - Complex (
COMPLEX
andDOUBLECOMPLEX
(2 samples per pixel)): the magnitudes of the complex values are returned.
- Parameters:
pixelArray
- the array of pixels values to be returned as an array offloat
.- Returns:
- a copy of the array of supplied pixel samples, with each pixel sample
converted to a
float
. - Throws:
IllegalArgumentException
- if the supplied array to be copied is not of the correct type for thisPixelDataType
.
- Colour data types (
-
getPixelsAsFloat
public float[] getPixelsAsFloat(Object pixelArray, int pixStart, int nPixels) throws InvalidImageException Returns a set of pixel samples as an array offloat
values. The length of the array returned is the number of pixels.For pixel data types where the number of samples per pixel is greater than 1, the following coersions take place:
- Colour data types (
RGB_BY_PLANE
,RGB_INTERLACED
(3 samples per pixel), andCOLOURPACKED
(4 samples per pixel)) images: the colours are converted to luminance values. - Complex (
COMPLEX
andDOUBLECOMPLEX
(2 samples per pixel)): the magnitudes of the complex values are returned.
- Parameters:
pixelArray
- the array of pixels values to be returned as an array offloat
.pixStart
- the index of the first pixel in the array of pixels that should be converted.nPixels
- the number of pixels to convert.- Returns:
- a copy of the array of supplied pixel samples, with each pixel sample
converted to a
float
. - Throws:
InvalidImageException
- if thePixelDataType
is not supported, or if the supplied array to be copied is not of the correct type for thisPixelDataType
.
- Colour data types (
-
getDoubleValue
Gets a single pixel value from an array of pixels. For colour images, the value returned is luninance. This method does not work for complex pixel types - it will throw an IllegalArgumentException.- Parameters:
pixelArray
- the array of pixels from within which the pixel value will be gotten.index
- the index (offset) to the pixel value to get.- Returns:
- the pixel intensity value at the given index.
- Throws:
IllegalArgumentException
- if thisPixelDataType
is complex, or if the supplied array is of the wrong primitive type for thisPixelDataType
.IndexOutOfBoundsException
- if the supplied index is bad.
-
getDoubleValue
public double getDoubleValue(Object pixelValue, ComplexMode complexMode) throws IllegalArgumentException Converts a single pixel value to adouble
value. For colour images, the value returned is the luminance of the colour. For complex pixel types, the value returned depends on thecomplexMode
argument.- Parameters:
pixelValue
- the single pixe value that will be converted to a double.complexMode
- the CompexMode that determines the value returned for complex pixel types.- Returns:
- the pixel value at the given index.
- Throws:
IllegalArgumentException
- if the supplied array is of the wrong primitive type for thisPixelDataType
.
-
setValue
Sets a single pixel value in an array of pixels to the given value. For colour pixel types, each of the colour channels is set to the supplied value, so that the resulting colour will be monochrome. For complex pixel types, the real component will be set to the value, and the imaginary channel will be set to zero.- Parameters:
pixelArray
- the array of pixels within which the pixel value will be set.index
- the index (offset) to the pixel value to set.value
- the value to set into the array.- Throws:
IllegalArgumentException
- if a sample of thisPixelDataType
is not stored as a single value, or if the supplied array is of the wrong type for thisPixelDataType
.IndexOutOfBoundsException
- if the supplied index is bad.
-
getColorValue
Gets a single colour pixel value from an array of pixels. This method only works with colour pixel types.- Parameters:
pixelArray
- the array of pixels from within which the pixel Color value will be gotten.index
- the index (offset, in pixels) to the pixel value to get.- Returns:
- the pixel
Color
value at the given index. - Throws:
IllegalArgumentException
- if a sample of thisPixelDataType
is not of a colour type or if the supplied array is of the wrong primitive type.IndexOutOfBoundsException
- if the supplied index is bad.
-
setColorValue
public void setColorValue(Object pixelArray, Color color, int index) throws IllegalArgumentException Sets a single colour pixel value into an array of pixels. This method only works with colour pixel types.- Parameters:
pixelArray
- the array of pixels to which the pixel Color value will be put.color
- the Color value to put.index
- the index (offset, in pixels) to the pixel value to put.- Throws:
IllegalArgumentException
- if a sample of thisPixelDataType
is not of a colour type or if the supplied array is of the wrong primitive type.IndexOutOfBoundsException
- if the supplied index is bad.
-
getComplexValue
Gets a single Complex pixel value from an array of pixels. This method only works with Complex pixel types.- Parameters:
pixelArray
- the array of pixels from within which the pixel Complex value will be gotten.index
- the index (offset, in pixels) to the pixel value to get.- Returns:
- the pixel
Complex
value at the given index. - Throws:
IllegalArgumentException
- if a sample of thisPixelDataType
is not of a Complex type or if the supplied array is of the wrong primitive type.IndexOutOfBoundsException
- if the supplied index is bad.
-
setComplexValue
public void setComplexValue(Object pixelArray, Complex cmplx, int index) throws IllegalArgumentException Sets a single complex pixel value into an array of pixels. This method only works with complex pixel types.- Parameters:
pixelArray
- the array of pixels to which the pixel complex value will be put.cmplx
- the complex value to put.index
- the index (offset, in pixels) to the pixel value to put.- Throws:
IllegalArgumentException
- if a sample of thisPixelDataType
is not of a complex type or if the supplied array is of the wrong primitive type.IndexOutOfBoundsException
- if the supplied index is bad.
-
getMinMax
Returns the minimum and maximum intensity values that are present in an array of pixel values. For complexPixelDataType
s, the minimum and maximum magnitudes are returned.- Parameters:
pixelArray
- the array of pixel values.- Returns:
- the minimum and maximum intensity values in an array of length 2.
- Throws:
IllegalArgumentException
- if thepixelArray
is of wrong primitive type for thisPixelDataType
.
-
getMinMax
public double[] getMinMax(Object pixelArray, ComplexMode complexMode) throws IllegalArgumentException Returns the minimum and maximum intensity values that are present in an array of pixel values.- Parameters:
pixelArray
- the array of pixel values.complexMode
- theComplexMode
for complex data types.- Returns:
- the minimum and maximum intensity values in an array of length 2.
- Throws:
IllegalArgumentException
- if thepixelArray
is of wrong primitive type for thisPixelDataType
.
-
getMinMax
public double[] getMinMax(Object pixelArray, int fromIndex, int count, ComplexMode complexMode) throws IllegalArgumentException Returns the minimum and maximum intensity values that are present in subset of an array of pixel values.- Parameters:
pixelArray
- the array of pixel values.fromIndex
- the pixel index at which to start the search for the minimum and maximum intensity values.count
- the number of pixels to search for the minimum and maximum intensity values.complexMode
- theComplexMode
for complex data types.- Returns:
- the minimum and maximum intensity values in an array of length 2.
- Throws:
IllegalArgumentException
- if thepixelArray
is of wrong primitive type for thisPixelDataType
.
-
coerce
public Object coerce(Object primitiveValues, PixelDataType toType, boolean clipIfNecessary) throws IllegalArgumentException Coerce pixels of thisPixelDataType
to a newPixelDataType
.When a colour (R,G,B) data type is coerced to a non-colour data type, the new data type contains the luminance values of the colours, where the luminance is (0.299*red) + (0.587*green) + (0.114*blue). When a non-colour data type is coerced to a colour data types, the colours will always be grey.
If this is a complex data type, then
ComplexMode.MAGNITUDE
is used in the coersion.- Parameters:
primitiveValues
- the set of primitive values that are the pixel values to coerce.toType
- the newPixelDataType
of the coerced pixels.clipIfNecessary
- a flag to indicate whether clipping should be performed if necessary. IfclipIfNecessary
isfalse
, then anInvalidArgumentException
will be thrown should any of the pixels to be coerced have a value outside the range that can be stored in thetoType
PixelDataType
.- Returns:
- a new array of primitive values that are the coerced pixel values.
- Throws:
IllegalArgumentException
- if thisPixelDataType
cannot be coerced to thetoType
PixelDataType
.
-
coerce
public Object coerce(Object primitiveValues, PixelDataType toType, ComplexMode complexMode, boolean clipIfNecessary) throws IllegalArgumentException Coerce pixels of thisPixelDataType
to a newPixelDataType
.When a colour (R,G,B) data type is coerced to a non-colour data type, the new data type contains the luminance values of the colours, where the luminance is (0.299*red) + (0.587*green) + (0.114*blue). When a non-colour data type is coerced to a colour data types, the colours will always be grey.
When a complex data type is coerced to a real data type, the conversion depends on the argument
complexMode
. When a non-complex data type is coerced to a complex data type, the imaginary channel will always be zero.- Parameters:
primitiveValues
- the set of primitive values that are the pixel values to coerce.toType
- the newPixelDataType
of the coerced pixels.complexMode
- theComplexMode
for conversion from complex data types to real data types. Ignored for non-complex data types.clipIfNecessary
- a flag to indicate whether clipping should be performed if necessary. IfclipIfNecessary
isfalse
, then anInvalidArgumentException
will be thrown should any of the pixels to be coerced have a value outside the range that can be stored in thetoType
PixelDataType
.- Returns:
- a new array of primitive values that are the coerced pixel values.
- Throws:
IllegalArgumentException
- if thisPixelDataType
cannot be coerced to thetoType
PixelDataType
.
-
coerce
public Object coerce(Object primitiveValues, PixelDataType toType, int pixStart, int nPixels, ComplexMode complexMode, boolean clipIfNecessary) throws IllegalArgumentException Coerce pixels of thisPixelDataType
to a newPixelDataType
.When a colour (R,G,B) data type is coerced to a non-colour data type, the new data type contains the luminance values of the colours, where the luminance is (0.299*red) + (0.587*green) + (0.114*blue). When a non-colour data type is coerced to a colour data types, the colours will always be grey.
When a complex data type is coerced to a real data type, the conversion depends on the argument
complexMode
. When a non-complex data type is coerced to a complex data type, the imaginary channel will always be zero.- Parameters:
primitiveValues
- the set of primitive values that are the pixel values to coerce.toType
- the newPixelDataType
of the coerced pixels.pixStart
- the index of the first pixel in the array of pixels that should be coerced.nPixels
- the number of pixels to coerce.complexMode
- theComplexMode
for conversion from complex data types to real data types. Ignored for non-complex data types.clipIfNecessary
- a flag to indicate whether clipping should be performed if necessary. IfclipIfNecessary
isfalse
, then anInvalidArgumentException
will be thrown should any of the pixels to be coerced have a value outside the range that can be stored in thetoType
PixelDataType
.- Returns:
- a new array of primitive values that are the coerced pixel values.
- Throws:
IllegalArgumentException
- if thisPixelDataType
cannot be coerced to thetoType
PixelDataType
.
-
coerceOneValue
Coerces a single pixel value to the given PixelDataType.- Parameters:
value
- the single pixel value.toType
- the PixelDataType to which it will be coerced.- Returns:
- the coerced pixel value.
- Throws:
IllegalArgumentException
- if the pixel value cannot be coerced to the specified PixelDataType.
-
coerceOneValue
public Object coerceOneValue(Object value, PixelDataType toType, ComplexMode complexMode) throws IllegalArgumentException Coerce a single pixel of thisPixelDataType
to a newPixelDataType
.When a colour (R,G,B) data type is coerced to a non-colour data type, the new data type contains the luminance values of the colour, where the luminance is (0.299*red) + (0.587*green) + (0.114*blue). When a non-colour data type is coerced to a colour data types, the colour will always be grey.
When a complex data type is coerced to a real data type, the conversion depends on the argument
complexMode
. When a non-complex data type is coerced to a complex data type, the imaginary channel will always be zero.- Parameters:
value
- the pixel value to coerce.toType
- the newPixelDataType
of the coerced pixel.complexMode
- theComplexMode
used when coercing Complex data types to real-valued data types.- Returns:
- a new array of primitive values that are the coerced pixel values.
- Throws:
IllegalArgumentException
- if thisPixelDataType
cannot be coerced to thetoType
PixelDataType
.
-
scale
Scale pixel intensities "in-place". If the rescaled pixel intensities do not fit into the data range for thisPixelDataType
, they will be clipped.- Parameters:
pixelArray
- the set of pixel values to scale.scaleFactor
- the intensity scaling factor.- Throws:
IllegalArgumentException
- if the intensties cannot be rescaled.
-
scale
public void scale(Object pixelArray, double scaleFactor, int pixStart, int nPixels) throws IllegalArgumentException Scale pixel intensities "in-place". If the rescaled pixel intensities do not fit into the data range for thisPixelDataType
, they will be clipped.- Parameters:
pixelArray
- the pixel values to scale.scaleFactor
- the intensity scaling factor.pixStart
- the index of the first pixel in the array of pixels that should be rescaled.nPixels
- the number of pixels to rescale.- Throws:
IllegalArgumentException
- if the intensties cannot be rescaled.
-
shift
Add a constant factor to pixel intensities "in-place". If the shifted pixel intensities do not fit into the data range for thisPixelDataType
, they will be clipped.- Parameters:
pixels
- the set of pixel values to which to add a constant factor.shift
- the constant factor to add.- Throws:
IllegalArgumentException
- if the shift cannot be applied.
-
shift
public void shift(Object pixelArray, double shift, int pixStart, int nPixels) throws IllegalArgumentException Add a constant factor to pixel intensities "in-place". If the shifted pixel intensities do not fit into the data range for thisPixelDataType
, they will be clipped.- Parameters:
pixelArray
- the set of pixel values to which to add a constant factor.shift
- the constant factor to add.pixStart
- the index of the first pixel in the array of pixels that should be shifted.nPixels
- the number of pixels to shift intensity.- Throws:
IllegalArgumentException
- if the shift cannot be applied.
-
toLuminance
public static short toLuminance(byte red, byte green, byte blue) Converts three (unsigned) byte values, representing the red, green and blue components of a colour to a luminance.- Parameters:
red
- the red component of the colour, as an unsigned byte value, stored in a byte.green
- the green component of the colour, as an unsigned byte value, stored in a byte.blue
- the blue component of the colour, as an unsigned byte value, stored in a byte.- Returns:
- the luminance value, which is (0.299*red) + (0.587*green) + (0.114*blue), rounded to a short value.
-
getLuminance
Returns the luminance value of a Color.- Parameters:
color
- the colour for which to return the luminance.- Returns:
- the luminance value, which is (0.299*red) + (0.587*green) + (0.114*blue), rounded to a short value.
-
getPixelValue
Gets the pixel value at a particular (column, row) of an array of pixels of thisPixelDataType
.- Parameters:
pixelArray
- the array of pixel samples.col
- the column number of the pixel.row
- the row number of the pixel.nCols
- the number of columns in the array.nRows
- the number of rows in the array.offset
- an offset (in pixels) into the pixel value array for the starting pixel of the slice.- Returns:
- the pixel value at the column/row. The
class
of pixel that is returned is:BINARY
images - java.lang.Boolean.BYTE
images - java.lang.Byte.UBYTE
images - java.lang.Short.RGB_INTERLACED
images - java.awt.Color.RGB_BY_PLANE
images - java.awt.Color.COLOURPACKED
images - java.awt.Color.SHORT
images - java.lang.Short.USHORT
images - java.lang.Integer.INT
images - java.lang.Integer.UINT
images - java.lang.Long.FLOAT
images - java.lang.Float.COMPLEX
images - com.xinapse.image.Complex.DOUBLE
images - java.lang.Double.DOUBLECOMPLEX
images - com.xinapse.image.DoubleComplex.
-
setPixelValue
public void setPixelValue(Object pixelArray, int col, int row, int nCols, int nRows, int offset, Object value) Sets the pixel value at a particular (column, row) of an array of pixels of thisPixelDataType
.- Parameters:
pixelArray
- the array of pixel values.col
- the column number of the pixel.row
- the row number of the pixel.nCols
- the number of columns in the array.nRows
- the number of rows in the array.offset
- an offset (in pixels) into the pixel value array for the starting pixel of the slice.value
- the pixel value to set. Theclass
of pixel that must be supplied is:BINARY
images - java.lang.Boolean.BYTE
images - java.lang.Byte.UBYTE
images - java.lang.Short.RGB_INTERLACED
images - java.awt.Color.RGB_BY_PLANE
images - java.awt.Color.COLOURPACKED
images - java.awt.Color.SHORT
images - java.lang.Short.USHORT
images - java.lang.Integer.INT
images - java.lang.Integer.UINT
images - java.lang.Long.FLOAT
images - java.lang.Float.COMPLEX
images - com.xinapse.image.Complex.DOUBLE
images - java.lang.Double.DOUBLECOMPLEX
images - com.xinapse.image.DoubleComplex.
-
interpolate
public Object interpolate(Object pixelValue1, double pixelValue2, double alpha) throws IllegalArgumentException Interpolates between two pixel intensity values.- Parameters:
pixelValue1
- the first pixel value.pixelValue2
- the second pixel value.alpha
- the alpha interpolation parameter.- Returns:
- the interpolated pixel intensity value.
- Throws:
IllegalArgumentException
- if a sample of thisPixelDataType
is not stored as a single value, or if the supplied array is of the wrong primitive type for thisPixelDataType
.IndexOutOfBoundsException
- if the supplied index is bad.
-
flipX
Flips an array of pixels in-place about the x-axis (ie, flips top to bottom). The array of pixels is over-written by the flipped pixels.- Parameters:
pixArray
- the array of pixels to flip. This array must contain enough pixel samples for a whole number of slices.nCols
- the number of image columns.nRows
- the number of image rows.- Throws:
InvalidImageException
- if pixels of the supplied type cannot be handled, or if the array does not contain enough pixel samples for a whole number of slices.
-
flipY
Flips an array of pixels in-place about the y-axis (ie flips left-right). The array of pixels is over-written by the flipped pixels.- Parameters:
pixArray
- the array of pixels to flip. This array must contain enough pixel samples for a whole number of image rows.nCols
- the number of image columns.- Throws:
InvalidImageException
- if pixels of the supplied type cannot be handled, or if the array does not contain enough pixel samples for a whole number of rows.
-
transpose
Transposes (slice-by-slice) an array of pixels in-place (ie flips top-right to bottom-left).
N.B. if the number of rows is not equal to the number of columns, then there is an implict interchange of the number of rows and columns in the transposed array.- Parameters:
pixArray
- the array of pixels to transpose. This array must contain enough pixel samples for a whole number of image slices.nCols
- the number of image columns.nRows
- the number of image rows.- Throws:
InvalidImageException
- if pixels of the supplied type cannot be handled, or if the array does not contain enough pixel samples for a whole number of slices.
-
rotate
public void rotate(Object pixArray, RotationAngle rotationAngle, int nCols, int nRows) throws InvalidImageException Rotates (slice-by-slice) an array of pixels in-place, by multiples of 90 degrees.
N.B. if the number of rows is not equal to the number of columns, then there may be an implict interchange of the number of rows and columns in the rotated array (for 90 degree rotations).- Parameters:
pixArray
- the array of pixels to rotate. This array must contain enough pixel samples for a whole number of image slices.rotationAngle
- the rotation angle.nCols
- the number of image columns.nRows
- the number of image rows.- Throws:
InvalidImageException
- if pixels of the supplied type cannot be handled, or if the array does not contain enough pixel samples for a whole number of slices.
-
main
Runs the self-test of this class.- Parameters:
args
- ignored.
-