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 ConstantsEnum ConstantDescriptionPixelDataTypefor 1-bit per pixel.PixelDataTypefor signed byte.PixelDataTypefor colour packed (UNC).PixelDataTypefor complex (2x32-bit float in real/imaginary interlaced pairs).PixelDataTypefor double (64-bit).PixelDataTypefor double complex (2x64-bit double in real/imaginary interlaced pairs).PixelDataTypefor double double (128-bit) - not implemented.PixelDataTypefor double double complex (2x128-bit double in real/imaginary interlaced pairs) - not implemented.PixelDataTypefor float (32-bit).PixelDataTypefor signed int (32-bit).PixelDataTypefor signed long (64-bit integer).PixelDataTypefor RGB (24-bit) - red plane followed by the green plane followed by the blue plane (non-interlaced).PixelDataTypefor RGB (24-bit) with one red value followed by one blue value followed by one green value, etc.PixelDataTypefor signed short (16-bit).PixelDataTypefor unsigned byte.PixelDataTypefor unsigned int (32-bit).PixelDataTypefor unsigned long (64-bit integer).PixelDataTypefor a type that hasn't been set.PixelDataTypefor signed short (16-bit). -
Method Summary
Modifier and TypeMethodDescriptioncoerce(Object primitiveValues, PixelDataType toType, boolean clipIfNecessary) Coerce pixels of thisPixelDataTypeto a newPixelDataType.coerce(Object primitiveValues, PixelDataType toType, int pixStart, int nPixels, ComplexMode complexMode, boolean clipIfNecessary) Coerce pixels of thisPixelDataTypeto a newPixelDataType.coerce(Object primitiveValues, PixelDataType toType, ComplexMode complexMode, boolean clipIfNecessary) Coerce pixels of thisPixelDataTypeto 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 thisPixelDataTypeto 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.voidFlips an array of pixels in-place about the x-axis (ie, flips top to bottom).voidFlips an array of pixels in-place about the y-axis (ie flips left-right).intReturns the number of array elements of a primitive type needed to store a single pixel value.intReturns 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.doublegetDoubleValue(Object pixelArray, int index) Gets a single pixel value from an array of pixels.doublegetDoubleValue(Object pixelValue, ComplexMode complexMode) Converts a single pixel value to adoublevalue.static shortgetLuminance(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.intgetNPixels(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 offloatvalues.float[]getPixelsAsFloat(Object pixelArray, int pixStart, int nPixels) Returns a set of pixel samples as an array offloatvalues.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.doubleReturns the maximum value that a pixel of thisPixelDataTypecan take.doubleReturns the minimum value that a pixel of thisPixelDataTypecan take.interpolate(Object pixelValue1, double pixelValue2, double alpha) Interpolates between two pixel intensity values.booleanTests whether thisPixelDataTypespecifies explicitly the red,green,blue colour components to display, rather than needing aColourMappingto display.booleanReturnstrueif thisPixelDataTypeis a complex (real/imaginary) data type.booleanTests whether thisPixelDataTypeis a floating-point (single or double precision) data type.booleanTests whether a sample of thisPixelDataTypecan be represented by a singleintvalue (Note: not integer).booleanisNarrowerThan(PixelDataType type) Tests whether thisPixelDataTypeis not capable of storing all values that can be stored by the suppliedtypewithout clipping.static voidRuns the self-test of this class.voidrotate(Object pixArray, RotationAngle rotationAngle, int nCols, int nRows) Rotates (slice-by-slice) an array of pixels in-place, by multiples of 90 degrees.voidScale pixel intensities "in-place".voidScale pixel intensities "in-place".voidsetColorValue(Object pixelArray, Color color, int index) Sets a single colour pixel value into an array of pixels.voidsetComplexValue(Object pixelArray, Complex cmplx, int index) Sets a single complex pixel value into an array of pixels.voidSets the values of an array of pixel samples, copying the values from another array.voidsetPixelValue(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.voidSets a single pixel value in an array of pixels to the given value.voidAdd a constant factor to pixel intensities "in-place".voidAdd a constant factor to pixel intensities "in-place".static shorttoLuminance(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 aStringdescribing thisPixelDataType.voidTransposes (slice-by-slice) an array of pixels in-place (ie flips top-right to bottom-left).static PixelDataTypeReturns 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
PixelDataTypefor a type that hasn't been set. -
BINARY
PixelDataTypefor 1-bit per pixel. -
BYTE
PixelDataTypefor signed byte. -
UBYTE
PixelDataTypefor unsigned byte. -
SHORT
PixelDataTypefor signed short (16-bit). -
USHORT
PixelDataTypefor signed short (16-bit). -
INT
PixelDataTypefor signed int (32-bit). -
UINT
PixelDataTypefor unsigned int (32-bit). -
FLOAT
PixelDataTypefor float (32-bit). -
DOUBLE
PixelDataTypefor double (64-bit). -
COMPLEX
PixelDataTypefor complex (2x32-bit float in real/imaginary interlaced pairs). -
COLOURPACKED
PixelDataTypefor colour packed (UNC). -
RGB_BY_PLANE
PixelDataTypefor RGB (24-bit) - red plane followed by the green plane followed by the blue plane (non-interlaced). -
RGB_INTERLACED
PixelDataTypefor RGB (24-bit) with one red value followed by one blue value followed by one green value, etc. (interlaced). -
LONG
PixelDataTypefor signed long (64-bit integer). -
ULONG
PixelDataTypefor unsigned long (64-bit integer). -
DOUBLECOMPLEX
PixelDataTypefor double complex (2x64-bit double in real/imaginary interlaced pairs). -
DOUBLEDOUBLE
PixelDataTypefor double double (128-bit) - not implemented. -
DOUBLEDOUBLECOMPLEX
PixelDataTypefor 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 thisPixelDataTypecan take. In the case ofPixelDataTypethat 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 thisPixelDataTypecan take. In the case ofPixelDataTypethat 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 thisPixelDataTypespecifies explicitly the red,green,blue colour components to display, rather than needing aColourMappingto display.- Returns:
trueif thisPixelDataTypespecifies the red,green,blue colour components;falseotherwise.
-
isFloatingPointType
public boolean isFloatingPointType()Tests whether thisPixelDataTypeis a floating-point (single or double precision) data type.- Returns:
trueif thisPixelDataTypeis a floating-point data type.
-
isIntegerType
public boolean isIntegerType()Tests whether a sample of thisPixelDataTypecan be represented by a singleintvalue (Note: not integer). UINT, LONG and ULONG cannot, in general, be represented by an int.- Returns:
trueif thisPixelDataTypecan be represented by a single integer value;falseotherwise.
-
toString
Returns aStringdescribing thisPixelDataType.- Overrides:
toStringin classEnum<PixelDataType>- Returns:
- a
Stringdescribing 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()Returnstrueif thisPixelDataTypeis a complex (real/imaginary) data type.- Returns:
trueif this is a complex data type;falseotherwise.
-
isNarrowerThan
Tests whether thisPixelDataTypeis not capable of storing all values that can be stored by the suppliedtypewithout clipping.- Parameters:
type- thePixelDataTypeagainst which this is to be tested.- Returns:
trueif thisPixelDataTypeis not capable of storing all values that can be stored by thetypewithout clipping;falseotherwise.- 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 thePixelDataTypeis 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 ifdstArrayis 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 ifdstArrayis not of the correct type for thisPixelDataType, or if it is of the wrong length, then a new array will be returned; otherwisedstArrayis 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 thesourceArrayfrom which pixel values are copied. Copying will start from a pointpixelOffsetinto 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:
dstArraycontaining 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 offloatvalues. 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 (
COMPLEXandDOUBLECOMPLEX(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 offloatvalues. 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 (
COMPLEXandDOUBLECOMPLEX(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 thePixelDataTypeis 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 thisPixelDataTypeis 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 adoublevalue. For colour images, the value returned is the luminance of the colour. For complex pixel types, the value returned depends on thecomplexModeargument.- 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 thisPixelDataTypeis 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
Colorvalue at the given index. - Throws:
IllegalArgumentException- if a sample of thisPixelDataTypeis 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 thisPixelDataTypeis 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
Complexvalue at the given index. - Throws:
IllegalArgumentException- if a sample of thisPixelDataTypeis 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 thisPixelDataTypeis 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 complexPixelDataTypes, 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 thepixelArrayis 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- theComplexModefor complex data types.- Returns:
- the minimum and maximum intensity values in an array of length 2.
- Throws:
IllegalArgumentException- if thepixelArrayis 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- theComplexModefor complex data types.- Returns:
- the minimum and maximum intensity values in an array of length 2.
- Throws:
IllegalArgumentException- if thepixelArrayis of wrong primitive type for thisPixelDataType.
-
coerce
public Object coerce(Object primitiveValues, PixelDataType toType, boolean clipIfNecessary) throws IllegalArgumentException Coerce pixels of thisPixelDataTypeto 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.MAGNITUDEis used in the coersion.- Parameters:
primitiveValues- the set of primitive values that are the pixel values to coerce.toType- the newPixelDataTypeof the coerced pixels.clipIfNecessary- a flag to indicate whether clipping should be performed if necessary. IfclipIfNecessaryisfalse, then anInvalidArgumentExceptionwill be thrown should any of the pixels to be coerced have a value outside the range that can be stored in thetoTypePixelDataType.- Returns:
- a new array of primitive values that are the coerced pixel values.
- Throws:
IllegalArgumentException- if thisPixelDataTypecannot be coerced to thetoTypePixelDataType.
-
coerce
public Object coerce(Object primitiveValues, PixelDataType toType, ComplexMode complexMode, boolean clipIfNecessary) throws IllegalArgumentException Coerce pixels of thisPixelDataTypeto 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 newPixelDataTypeof the coerced pixels.complexMode- theComplexModefor 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. IfclipIfNecessaryisfalse, then anInvalidArgumentExceptionwill be thrown should any of the pixels to be coerced have a value outside the range that can be stored in thetoTypePixelDataType.- Returns:
- a new array of primitive values that are the coerced pixel values.
- Throws:
IllegalArgumentException- if thisPixelDataTypecannot be coerced to thetoTypePixelDataType.
-
coerce
public Object coerce(Object primitiveValues, PixelDataType toType, int pixStart, int nPixels, ComplexMode complexMode, boolean clipIfNecessary) throws IllegalArgumentException Coerce pixels of thisPixelDataTypeto 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 newPixelDataTypeof 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- theComplexModefor 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. IfclipIfNecessaryisfalse, then anInvalidArgumentExceptionwill be thrown should any of the pixels to be coerced have a value outside the range that can be stored in thetoTypePixelDataType.- Returns:
- a new array of primitive values that are the coerced pixel values.
- Throws:
IllegalArgumentException- if thisPixelDataTypecannot be coerced to thetoTypePixelDataType.
-
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 thisPixelDataTypeto 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 newPixelDataTypeof the coerced pixel.complexMode- theComplexModeused 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 thisPixelDataTypecannot be coerced to thetoTypePixelDataType.
-
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
classof pixel that is returned is:BINARYimages - java.lang.Boolean.BYTEimages - java.lang.Byte.UBYTEimages - java.lang.Short.RGB_INTERLACEDimages - java.awt.Color.RGB_BY_PLANEimages - java.awt.Color.COLOURPACKEDimages - java.awt.Color.SHORTimages - java.lang.Short.USHORTimages - java.lang.Integer.INTimages - java.lang.Integer.UINTimages - java.lang.Long.FLOATimages - java.lang.Float.COMPLEXimages - com.xinapse.image.Complex.DOUBLEimages - java.lang.Double.DOUBLECOMPLEXimages - 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. Theclassof pixel that must be supplied is:BINARYimages - java.lang.Boolean.BYTEimages - java.lang.Byte.UBYTEimages - java.lang.Short.RGB_INTERLACEDimages - java.awt.Color.RGB_BY_PLANEimages - java.awt.Color.COLOURPACKEDimages - java.awt.Color.SHORTimages - java.lang.Short.USHORTimages - java.lang.Integer.INTimages - java.lang.Integer.UINTimages - java.lang.Long.FLOATimages - java.lang.Float.COMPLEXimages - com.xinapse.image.Complex.DOUBLEimages - java.lang.Double.DOUBLECOMPLEXimages - 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 thisPixelDataTypeis 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.
-