Class ModelSimpleImage

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable

    public class ModelSimpleImage
    extends ModelSerialCloneable
    This is very simple class to store a float type image of up to four dimensions. For speed all class variables are public. This class is used extensively in Registration algorithms where we needs many copies of the image where the data does not need to be visible to the UserInterface. With the data array as public speed is achieved but at a cost that the buffer is always of the type float.
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      float cMassX
      X coordinate value of the center of mass for the image.
      float cMassY
      Y coordinate value of the center of mass for the image.
      float cMassZ
      Z coordinate value of the center of mass for the image.
      float[] data
      Data buffer that is used to store the image.
      int dataSize
      Size of the data buffer (number of pixels in image).
      int[] extents
      The dimensionality of the dataset.
      boolean isColor
      Indicates whether is image is a color image or not.
      float max
      Maximum intensity values of image.
      float maxB
      Maximum intensity values of image.
      float maxG
      Maximum intensity values of image.
      float maxR
      Maximum intensity values of image.
      float min
      Minimum intensity values of image.
      float minB
      Minimum intensity values of image.
      float minG
      Minimum intensity values of image.
      float minR
      Minimum intensity values of image.
      java.lang.String name
      add simple image name for AAM model only.
      int nDims
      Number of dimensions of the image.
      float[] resolutions
      Voxel resolutions (typically x,y,z(slice spacing),t).
      private static long serialVersionUID
      Use serialVersionUID for interoperability.
      int tDim
      Number of volumes in the dataset.
      float tRes
      Resolution in the time dimension.
      int xDim
      Number of pixels in x dimension.
      float xRes
      X pixel resolution.
      int yDim
      Number of pixels in y dimension.
      float yRes
      Y pixel resolution.
      int zDim
      Number of pixels in z dimension.
      float zRes
      Z voxel resolution.
    • Constructor Summary

      Constructors 
      Constructor Description
      ModelSimpleImage()
      Add the empty default contructor.
      ModelSimpleImage​(int[] dimExtents)
      Creates a class to hold the minimum information about an image - the extents with the resolutions defaulted to 1.
      ModelSimpleImage​(int[] dimExtents, float[] voxRes)
      Creates a class to hold the minimum information about an image - the extents and the resolutions.
      ModelSimpleImage​(int[] dimExtents, float[] voxRes, boolean isColor)
      Creates a class to hold the minimum information about an image - the extents, the resolutions.
      ModelSimpleImage​(int[] dimExtents, float[] voxRes, ModelImage image)
      Creates a class to hold the minimum information about an image - the extents, the resolutions, and optionally, the image data.
      ModelSimpleImage​(int[] dimExtents, float[] voxRes, ModelImage image, int timeSlice)
      Creates a class to hold the minimum information about an image - the extents, the resolutions, and the image data.
      ModelSimpleImage​(ModelImage image)
      Creates a class to hold the minimum information about an image - the extents, the resolutions, and optionall, the image data.
      ModelSimpleImage​(ModelImage image, int timeSlice)
      Creates a class to hold the minimum information about an image - the extents, the resolutions, and the image data.
    • Field Detail

      • serialVersionUID

        private static final long serialVersionUID
        Use serialVersionUID for interoperability.
        See Also:
        Constant Field Values
      • cMassX

        public float cMassX
        X coordinate value of the center of mass for the image.
      • cMassY

        public float cMassY
        Y coordinate value of the center of mass for the image.
      • cMassZ

        public float cMassZ
        Z coordinate value of the center of mass for the image.
      • data

        public float[] data
        Data buffer that is used to store the image.
      • dataSize

        public int dataSize
        Size of the data buffer (number of pixels in image).
      • extents

        public int[] extents
        The dimensionality of the dataset.
      • isColor

        public boolean isColor
        Indicates whether is image is a color image or not.
      • max

        public float max
        Maximum intensity values of image.
      • maxR

        public float maxR
        Maximum intensity values of image.
      • maxG

        public float maxG
        Maximum intensity values of image.
      • maxB

        public float maxB
        Maximum intensity values of image.
      • min

        public float min
        Minimum intensity values of image.
      • minR

        public float minR
        Minimum intensity values of image.
      • minG

        public float minG
        Minimum intensity values of image.
      • minB

        public float minB
        Minimum intensity values of image.
      • nDims

        public int nDims
        Number of dimensions of the image.
      • resolutions

        public float[] resolutions
        Voxel resolutions (typically x,y,z(slice spacing),t).
      • tDim

        public int tDim
        Number of volumes in the dataset. Typically t represents time.
      • tRes

        public float tRes
        Resolution in the time dimension.
      • xDim

        public int xDim
        Number of pixels in x dimension.
      • xRes

        public float xRes
        X pixel resolution.
      • yDim

        public int yDim
        Number of pixels in y dimension.
      • yRes

        public float yRes
        Y pixel resolution.
      • zDim

        public int zDim
        Number of pixels in z dimension.
      • zRes

        public float zRes
        Z voxel resolution.
      • name

        public java.lang.String name
        add simple image name for AAM model only.
    • Constructor Detail

      • ModelSimpleImage

        public ModelSimpleImage()
        Add the empty default contructor. AAM appearance model needs to call the default one for local image processing.
      • ModelSimpleImage

        public ModelSimpleImage​(ModelImage image)
        Creates a class to hold the minimum information about an image - the extents, the resolutions, and optionall, the image data.
        Parameters:
        image - ModelImage structure where the input image data is stored. In this particular constructor, this parameter must not be null as the extents and resolutions are derived from the input image.
      • ModelSimpleImage

        public ModelSimpleImage​(int[] dimExtents)
        Creates a class to hold the minimum information about an image - the extents with the resolutions defaulted to 1. A data array of float type will be allocated where the size is defined by the dimExtents[].
        Parameters:
        dimExtents - Extents of the image; must be non null.
      • ModelSimpleImage

        public ModelSimpleImage​(ModelImage image,
                                int timeSlice)
        Creates a class to hold the minimum information about an image - the extents, the resolutions, and the image data. A data array of float type will be allocated where the size is defined by the ModelImage. Used for a 4D image to make a 3D ModelSimpleImage.
        Parameters:
        image - ModelImage Structure where the input image data is stored. In this particular call, this parameter must not be null as the extents and resolutions are derived from the input image.
        timeSlice - Time slice to export.
      • ModelSimpleImage

        public ModelSimpleImage​(int[] dimExtents,
                                float[] voxRes)
        Creates a class to hold the minimum information about an image - the extents and the resolutions. A data array of float type will be allocated where the size is defined by the dimExtents[].
        Parameters:
        dimExtents - Extents of the image; must be non null.
        voxRes - Resolutions of the image; must be non null.
      • ModelSimpleImage

        public ModelSimpleImage​(int[] dimExtents,
                                float[] voxRes,
                                ModelImage image)
        Creates a class to hold the minimum information about an image - the extents, the resolutions, and optionally, the image data. A data array of float type will be allocated where the size is defined by the dimExtents[].
        Parameters:
        dimExtents - Extents of the image; must be non null.
        voxRes - Resolutions of the image; must be non null.
        image - Structure where image data is stored; can be null. If it is null, the buffer associated with this class will be empty. The ModelImage is not otherwise saved or referenced within this class.
      • ModelSimpleImage

        public ModelSimpleImage​(int[] dimExtents,
                                float[] voxRes,
                                boolean isColor)
        Creates a class to hold the minimum information about an image - the extents, the resolutions. A data array of float type will be allocated where the size is defined by the dimExtents[].
        Parameters:
        dimExtents - Extents of the image; must be non null.
        voxRes - Resolutions of the image; must be non null.
        isColor - If true, indicates that this image is a color image (i.e. ARGB).
      • ModelSimpleImage

        public ModelSimpleImage​(int[] dimExtents,
                                float[] voxRes,
                                ModelImage image,
                                int timeSlice)
        Creates a class to hold the minimum information about an image - the extents, the resolutions, and the image data. A data array of float type will be allocated where the size is defined by the dimExtents[]. Used for a 4D image to make a 3D ModelSimpleImage.
        Parameters:
        dimExtents - Extents of the image; must be non null.
        voxRes - Resolutions of the image; must be non null.
        image - Structure where image data is stored; can be null. If it is null, the buffer associated with this class will be empty. The ModelImage is not otherwise saved within this class.
        timeSlice - Time slice to export into the 3D data array.
    • Method Detail

      • calcMinMax

        public void calcMinMax()
        Calculates the min and max values for the image array.
      • calculateCenterOfMass2D

        public void calculateCenterOfMass2D​(boolean voxelResol)
        Calculates the center of mass (gravity) of a 2D image using the intensity of each pixel as a weighting value.
        Parameters:
        voxelResol - if true multiply the center of mass by voxel resolutions.
      • calculateCenterOfMass3D

        public void calculateCenterOfMass3D​(boolean voxelResol)
        Calculates the center of mass (gravity) of a 3D image. In image space where the upper left hand corner of the image is 0,0,0. The x axis goes left to right, y axis goes top to bottom and z axis goes into the screen. (i.e. the right hand rule). The intensity of each voxel is used as a weighting value.
        Parameters:
        voxelResol - if true multiply the center of mass by voxel resolutions.
      • createIntensityImage

        public ModelSimpleImage createIntensityImage()
        Create a new image with the same dimensions as this image which contains the intensity value from this image if it is a color image or which contains the same values if the image is already an intensity image. Scale factors are equally weighted for each of the RGB channels.
        Returns:
        ModelSimpleImage New instance created with intensity values only.
      • createIntensityImage

        public ModelSimpleImage createIntensityImage​(float fScaleR,
                                                     float fScaleG,
                                                     float fScaleB)
        Create a new image with the same dimensions as this image which contains the intensity value from this image if it is a color image or which contains the same values if the image is already an intensity image. Scale factors are specified for how to compute the intensity image as a linear combination of the RGB channels.
        Parameters:
        fScaleR - Scale factor to apply to the red color channel.
        fScaleG - Scale factor to apply to the green color channel.
        fScaleB - Scale factor to apply to the blue color channel.
        Returns:
        ModelSimpleImage New instance created with intensity values only.
      • createMappedImage2d

        public ModelSimpleImage createMappedImage2d​(ModelSimpleImage kImageMapX,
                                                    ModelSimpleImage kImageMapY)
        Create a mapping of this image. The mapping is defined by a set of floating point coordinates for each sample in the image. The coordinates are actually stored in separate images, one for each dimension. The number dimensions and the resolutions of these coordinate images must be the same so that either one can be used to determine the dimensions and resolutions of the new image where the mapped source image values will be stored using bilinear interpolation.
        Parameters:
        kImageMapX - ModelSimpleImage Image contains the x coordinate for the mapping. Each value in the image must be in the range [0,1].
        kImageMapY - ModelSimpleImage Image contains the y coordinate for the mapping. Each value in the image must be in the range [0,1].
        Returns:
        ModelSimpleImage A new instance created with the mapping of this image.
      • createMappedImage3d

        public ModelSimpleImage createMappedImage3d​(ModelSimpleImage kImageMapX,
                                                    ModelSimpleImage kImageMapY,
                                                    ModelSimpleImage kImageMapZ)
        Create a mapping of this image. The mapping is defined by a set of floating point coordinates for each sample in the image. The coordinates are actually stored in separate images, one for each dimension. The number dimensions and the resolutions of these coordinate images must be the same so that either one can be used to determine the dimensions and resolutions of the new image where the mapped source image values will be stored using trilinear interpolation.
        Parameters:
        kImageMapX - ModelSimpleImage Image contains the x coordinate for the mapping. Each value in the image must be in the range [0,1].
        kImageMapY - ModelSimpleImage Image contains the y coordinate for the mapping. Each value in the image must be in the range [0,1].
        kImageMapZ - ModelSimpleImage Image contains the z coordinate for the mapping. Each value in the image must be in the range [0,1].
        Returns:
        ModelSimpleImage A new instance created with the mapping of this image.
      • disposeLocal

        public void disposeLocal​(boolean gcFlag)
        Nulls the data fields so that memory can be recovered.
        Parameters:
        gcFlag - if true the garbage collector is called.
      • exportData

        public void exportData​(float[] buffer,
                               int start,
                               int end)
        Simple accessor to copy data from this class's data buffer.
        Parameters:
        buffer - destination buffer
        start - the starting pointer where data is to be copy from the source buffer
        end - the ending pointer where in the source buffer
      • getValue

        public final float getValue​(int x,
                                    int y)
        Get the value at the x, y position of the data array.
        Parameters:
        x - input x pixel coordinate
        y - input y pixel coordinate
        Returns:
        data value at the given position.
      • setValue

        public final void setValue​(int x,
                                   int y,
                                   float value)
        Set the value at the x, y position of the data array.
        Parameters:
        x - input x pixel coordinate.
        y - input y pixel coordinate
        value - data value.
      • getBiLinear

        public final float getBiLinear​(float x,
                                       float y)
        Version of get that performs bi-linear interpoloation. Note - does NOT perform bounds checking
        Parameters:
        x - input x coordinate
        y - input y coordinate
        Returns:
        the bilinear interpolated value for x,y.
      • getTriLinear

        public final float getTriLinear​(float x,
                                        float y,
                                        float z)
        Version of get that performs tri-linear interpoloation. Note - does NOT perform bounds checking
        Parameters:
        x - x coordinate
        y - y coordinate
        z - z coordinate
        Returns:
        the trilinear interpolated value for x,y,z.
      • subSample2dBy2

        public ModelSimpleImage subSample2dBy2()
        Takes a simple image and subsamples it by 2. Linear interpolation is used.
        Returns:
        Subsampled image.
      • subSample2dBy2

        public ModelSimpleImage subSample2dBy2​(boolean isColor)
        Takes a simple image and subsamples it by 2. Linear interpolation is used.
        Parameters:
        isColor - If true, indicates that this image is a color image (i.e. ARGB).
        Returns:
        Subsampled image.
      • subSample2dBy2

        public ModelSimpleImage subSample2dBy2​(ModelSimpleImage resultImage)
        Takes a simple image and subsamples it by 2. Linear interpolation is used.
        Parameters:
        resultImage - The subsampled data will be stored in this object.
        Returns:
        Subsampled image.
      • subSample2dBy2

        public ModelSimpleImage subSample2dBy2​(ModelSimpleImage resultImage,
                                               boolean isColor)
        Takes a simple image and subsamples it by 2. Linear interpolation is used.
        Parameters:
        resultImage - The subsampled data will be stored in this object.
        isColor - If true, indicates that this image is a color image (i.e. ARGB).
        Returns:
        Subsampled image.
      • subsample3dBy2

        public ModelSimpleImage subsample3dBy2()
        Takes a simple image and subsamples it by 2. Linear interpolation is used.
        Returns:
        Subsampled image.
      • subsample3dBy2

        public ModelSimpleImage subsample3dBy2​(boolean isColor)
        Takes a simple 3D image and subsamples it by 2. Linear interpolation is used.
        Parameters:
        isColor - If true, indicates that this image is a color image (i.e. ARGB).
        Returns:
        Subsampled image.
      • subsample3dBy2XY

        public ModelSimpleImage subsample3dBy2XY()
        Takes a simple 3D image and subsamples each image plane (XY) by 2. Linear interpolation is used.
        Returns:
        Subsampled image.
      • subsample3dBy2XY

        public ModelSimpleImage subsample3dBy2XY​(boolean isColor)
        Takes a simple 3D image and subsamples each image plane (XY) by 2. Linear interpolation is used.
        Parameters:
        isColor - If true, indicates that this image is a color image (i.e. ARGB).
        Returns:
        Subsampled image.
      • subSample3dBy2XY

        public ModelSimpleImage subSample3dBy2XY​(ModelSimpleImage resultImage)
        Takes a simple image and subsamples XY by 2, interpolating so that the new XY values are averages.
        Parameters:
        resultImage - The subsampled data will be stored in this object.
        Returns:
        Subsampled image.
      • subSample3dBy2XY

        public ModelSimpleImage subSample3dBy2XY​(ModelSimpleImage resultImage,
                                                 boolean isColor)
        Takes a simple image and subsamples XY by 2, interpolating so that the new XY values are averages.
        Parameters:
        resultImage - The subsampled data will be stored in this object.
        isColor - If true, indicates that this image is a color image (i.e. ARGB).
        Returns:
        Subsampled image.
      • toString

        public java.lang.String toString()
        Returns a readable representation of this simple image.
        Overrides:
        toString in class java.lang.Object
        Returns:
        Representation containing extents and resolutions.
      • finalize

        protected void finalize()
                         throws java.lang.Throwable
        Calls disposeLocal of this class to ensure this class nulls the references to global class variables so that memory will be recovered.
        Overrides:
        finalize in class java.lang.Object
        Throws:
        java.lang.Throwable - Throws an error if there is a problem with the finalization of this object.
      • Width

        public int Width()
        Used by AAM appearance model to get dimension
        Returns:
        x dimension
      • Height

        public int Height()
        Used by AAM appearance model to get dimension
        Returns:
        y dimension
      • Depth

        public int Depth()
        Used by AAM appearance model to get dimension
        Returns:
        z dimension
      • CB

        public void CB​(double y1,
                       double y2,
                       double d,
                       double[] result)
        Binary interpolation call
        Parameters:
        y1 -
        y2 -
        d -
        result -
      • Pixel1

        public double Pixel1​(float x,
                             float y)
        Used by AAM appearance model to get bilinear interpolation.
        Returns:
        interpolation value.
      • SetName

        public void SetName​(java.lang.String _name)
        Set the simple image name
        Parameters:
        _name -
      • getName

        public java.lang.String getName()
        Get the simple image name
        Returns:
      • FillPixels

        public final void FillPixels​(float value)
        In model simple image, fill pixel with given intensity value.
        Parameters:
        value -
      • importData

        public void importData​(float[] buffer,
                               int start,
                               int end)
        For AAM model only, import buffer to the simple image data.
        Parameters:
        buffer -
        start -
        end -
      • ReadBandedFile

        public ModelSimpleImage ReadBandedFile​(java.lang.String szFilename)
        Temporary function to handle AAM image file IO for AAM own testing cases. Lately this function will be removed.
        Parameters:
        szFilename -
        Returns:
      • ReadFile

        public ModelSimpleImage ReadFile​(java.lang.String szFileName)
        Temporary function to handle AAM image file IO for AAM own testing cases. Lately this function will be removed.
        Parameters:
        szFilename -
        Returns: