Class MultiSliceImage

java.lang.Object
com.xinapse.multisliceimage.MultiSliceImage
All Implemented Interfaces:
ReadableImage, WritableImage, AutoCloseable, Cloneable
Direct Known Subclasses:
ANZImage, UNCImage

public abstract class MultiSliceImage extends Object implements WritableImage, Cloneable, AutoCloseable
An abstract representation of a multi-dimensional image. This class cannot be instantiated, and sub-classes must implement the abstract methods defined here, and those defined in WritableImage.
  • Field Details

    • PATIENT_NAME_NAME

      public static final String PATIENT_NAME_NAME
      The information field name that is written into image headers to indicate the patient name.
      See Also:
    • PATIENT_ID_NAME

      public static final String PATIENT_ID_NAME
      The information field name that is written into image headers to indicate the patient ID.
      See Also:
    • BIRTH_DATE_NAME

      public static final String BIRTH_DATE_NAME
      The information field name that is written into image headers to indicate the patient's birth date.
      See Also:
    • PATIENT_SEX_NAME

      public static final String PATIENT_SEX_NAME
      The information field name that is written into image headers to indicate the patient's sex.
      See Also:
    • STUDY_ID_NAME

      public static final String STUDY_ID_NAME
      The information field name that is written into image headers to indicate the study ID.
      See Also:
    • SCAN_DATE_NAME

      public static final String SCAN_DATE_NAME
      The information field name that is written into image headers to indicate the scan date.
      See Also:
    • STORAGE_CLASS_UID_NAME

      public static final String STORAGE_CLASS_UID_NAME
      The information field name that is written into image headers to indicate the imaging modality Storage Class UID.
      See Also:
    • MODALITY_NAME

      public static final String MODALITY_NAME
      The information field name that is written into image headers to indicate the imaging modality.
      See Also:
    • BODY_PART_NAME

      public static final String BODY_PART_NAME
      The information field name that is written into image headers to indicate the imaged body part.
      See Also:
    • LATERALITY_NAME

      public static final String LATERALITY_NAME
      The information field name that is written into image headers to indicate the image laterality.
      See Also:
    • PULSE_SEQUENCE_NAME

      public static final String PULSE_SEQUENCE_NAME
      The information field name that is written into image headers to indicate the pulse sequence name.
      See Also:
    • SCANNING_SEQUENCE_NAME

      public static final String SCANNING_SEQUENCE_NAME
      The information field name that is written into image headers to indicate the DICOM scanning sequence.
      See Also:
    • SEQUENCE_VARIANT_NAME

      public static final String SEQUENCE_VARIANT_NAME
      The information field name that is written into image headers to indicate the DICOM scanning sequence variant.
      See Also:
    • SERIES_NUMBER_NAME

      public static final String SERIES_NUMBER_NAME
      The information field name that is written into image headers to indicate the series (scan) number.
      See Also:
    • SERIES_DESCRIPTION_NAME

      public static final String SERIES_DESCRIPTION_NAME
      The information field name that is written into image headers to indicate the series (scan) description.
      See Also:
    • REPETITION_TIME_NAME

      public static final String REPETITION_TIME_NAME
      The information field name that is written into image headers to indicate the scan repetition time.
      See Also:
    • INVERSION_TIME_NAME

      public static final String INVERSION_TIME_NAME
      The information field name that is written into image headers to indicate the scan inversion time.
      See Also:
    • ECHO_TIME_NAME

      public static final String ECHO_TIME_NAME
      The information field name that is written into image headers to indicate the scan echo time.
      See Also:
    • SAT_PULSE_FREQ_OFFSET_PPM_NAME

      public static final String SAT_PULSE_FREQ_OFFSET_PPM_NAME
      The information field name that is written into image headers to indicate the saturation pulse frequency offset.
      See Also:
    • ECHO_TRAIN_LENGTH_NAME

      public static final String ECHO_TRAIN_LENGTH_NAME
      The information field name that is written into image headers to indicate the scan echo train length.
      See Also:
    • FLIP_ANGLE_NAME

      public static final String FLIP_ANGLE_NAME
      The information field name that is written into image headers to indicate the excitation pulse flip angle.
      See Also:
    • DW_B_VALUE_NAME

      public static final String DW_B_VALUE_NAME
      The information field name that is written into image headers to indicate the diffusion-weighting b-value.
      See Also:
    • DW_GRADIENT_VECTOR_NAME

      public static final String DW_GRADIENT_VECTOR_NAME
      The information field name that is written into image headers to indicate the diffusion-weighting gradient vector.
      See Also:
    • DW_B_MATRIX_NAME

      public static final String DW_B_MATRIX_NAME
      The information field name that is written into image headers to indicate the diffusion-weighting B-matrix.
      See Also:
    • TRIGGER_DELAY_NAME

      public static final String TRIGGER_DELAY_NAME
      The information field name that is written into image headers to indicate the trigger delay after the R-wave peak.
      See Also:
    • COLOUR_MAPPING_NAME

      public static final String COLOUR_MAPPING_NAME
      The information field name that is written into image headers to indicate the colour mapping.
      See Also:
    • PIXEL_X_SIZE_NAME

      public static final String PIXEL_X_SIZE_NAME
      The information field name that is written into image headers to indicate the width of an image pixel in mm.
      See Also:
    • PIXEL_Y_SIZE_NAME

      public static final String PIXEL_Y_SIZE_NAME
      The information field name that is written into image headers to indicate the height of an image pixel in mm.
      See Also:
    • PIXEL_Z_SIZE_NAME

      public static final String PIXEL_Z_SIZE_NAME
      The information field name that is written into image headers to indicate the thickness of an image pixel in mm.
      See Also:
    • TIME_BETWEEN_FRAMES_NAME

      public static final String TIME_BETWEEN_FRAMES_NAME
      The information field name that is written into image headers to indicate the time between frames of a multi-frame image.
      See Also:
    • STUDY_INSTANCE_UID_NAME

      public static final String STUDY_INSTANCE_UID_NAME
      The information field name that is written into image headers to indicate the study instance UID.
      See Also:
    • SERIES_INSTANCE_UID_NAME

      public static final String SERIES_INSTANCE_UID_NAME
      The information field name that is written into image headers to indicate the series instance UID.
      See Also:
    • FRAME_OF_REFERENCE_UID_NAME

      public static final String FRAME_OF_REFERENCE_UID_NAME
      The information field name that is written into image headers to indicate the frame of reference UID for the image position/orientation.
      See Also:
    • IMAGE_POSITION_PATIENT_NAME

      public static final String IMAGE_POSITION_PATIENT_NAME
      The information field name that is written into image headers to indicate the location of the first pixel of the image, in patient coordinates.
      See Also:
    • IMAGE_ORIENTATION_PATIENT_NAME

      public static final String IMAGE_ORIENTATION_PATIENT_NAME
      The information field name that is written into image headers to indicate the orientation (direction cosines) of the matrix of image pixels, in patient coordinates.
      See Also:
    • PIXEL_SPACING_NAME

      public static final String PIXEL_SPACING_NAME
      The information field name that is written into image headers to indicate the physical distance in the patient between the center of each pixel.
      See Also:
    • PATIENT_POSITION_NAME

      public static final String PATIENT_POSITION_NAME
      The information field name that is written into image headers to indicate the way in which the patient is positioned in the scanner.
      See Also:
    • SLICE_THICKNESS_NAME

      public static final String SLICE_THICKNESS_NAME
      The information field name that is written into image headers to indicate the thickness of an image slice.
      See Also:
    • INTENSITY_RESCALE_SLOPE_NAME

      public static final String INTENSITY_RESCALE_SLOPE_NAME
      The information field name that is written into image headers to indicate the intensity rescale slope.
      See Also:
    • INTENSITY_RESCALE_INTERCEPT_NAME

      public static final String INTENSITY_RESCALE_INTERCEPT_NAME
      The information field name that is written into image headers to indicate the intensity rescale intercept.
      See Also:
    • INTENSITY_RESCALE_UNITS_NAME

      public static final String INTENSITY_RESCALE_UNITS_NAME
      The information field name that is written into image headers to indicate the intensity rescale units.
      See Also:
    • AUDIT_TRAIL_ACTION_TEXT

      public static final String AUDIT_TRAIL_ACTION_TEXT
      A String used when composing audit trail information.
      See Also:
    • pixArray

      protected PixArray pixArray
      If non-null, pixel data held in this PixArray object.
    • randomAccessFile

      protected RandomAccessFile randomAccessFile
      If non-null, pixel data kept on disk and accessed via this RandomAccessFile. However, it isn't compulory to have access to the pixel data: if all the user wants is the image header info, both could be null.
    • mode

      protected String mode
      The "mode" with which the image was opened, if a disk-file: either "r" or "rw".
  • Constructor Details

    • MultiSliceImage

      protected MultiSliceImage()
      Default constructor for MultiSliceImage for use by sub-classes. MultiSliceImage Objects cannot be directly instantiated.
  • Method Details

    • isModified

      public boolean isModified()
      Tests whether this MultiSliceImage has been modified since instantiation.
      Returns:
      true if the image has been modified; false otherwise.
    • setModified

      public void setModified()
      Sets the "modified" flag for this MultiSliceImage to indicate that it has been modified since instantiation.
    • getSliceDim

      protected int getSliceDim() throws IndexOutOfBoundsException
      Returns the index number to the "slice" dimension of the image.
      Returns:
      the index number to the "slicee" dimension of the image.
      Throws:
      IndexOutOfBoundsException - if this not a 3- (or higher) dimensional image.
    • getFrameDim

      protected int getFrameDim() throws IndexOutOfBoundsException
      Returns the index number to the "frame" dimension of the image.
      Returns:
      the index number to the "frame" dimension of the image.
      Throws:
      IndexOutOfBoundsException - if this not a 4- (or higher) dimensional image.
    • setSuggestedFileName

      public void setSuggestedFileName(String name)
      Sets a suggested file name for in-memory images that might be saved to disk later.
      Specified by:
      setSuggestedFileName in interface WritableImage
      Parameters:
      name - the suggested file name.
    • getSuggestedFileName

      public String getSuggestedFileName()
      Description copied from interface: ReadableImage
      Returns the suggested file name for in-memory images that are to be saved to disk.
      Specified by:
      getSuggestedFileName in interface ReadableImage
      Returns:
      the suggested file name, or null if not set.
    • getByteOrder

      protected abstract ByteOrder getByteOrder()
      Returns the byte order for this image.
      Returns:
      the byte oder for this image, or null if the byte order is not defined yet (in-memory images only).
    • getFileDataOffset

      protected abstract int getFileDataOffset()
      Returns the byte offset into the disk-based file format where pixel data begins.
      Returns:
      the byte offset to the start of pixel data for images that are written to disk.
    • setPixelXSize

      public abstract void setPixelXSize(float width) throws IllegalArgumentException, IOException
      Sets the pixel size in the x (horizontal) direction for this image.
      Parameters:
      width - the width of a pixel.
      Throws:
      IllegalArgumentException - if the pixel width is not positive.
      IOException - if and I/O error occurs.
    • setPixelYSize

      public abstract void setPixelYSize(float height) throws IllegalArgumentException, IOException
      Sets the pixel size in the y (vertical) direction for this image.
      Parameters:
      height - the height of a pixel.
      Throws:
      IllegalArgumentException - if height is not positive.
      IOException - if an I/O error occurs.
      IndexOutOfBoundsException - if the image doesn't have a dimensionality of at least 2.
    • setPixelZSize

      public abstract void setPixelZSize(float thickness) throws IllegalArgumentException, IOException
      Sets the pixel size in the z (slice) direction for this image.
      Parameters:
      thickness - the thickness of a pixel.
      Throws:
      IllegalArgumentException - if thickness is not positive.
      IOException - if an I/O error occurs.
      IndexOutOfBoundsException - if the image doesn't have a dimensionality of at least 3.
    • setTimeBetweenFrames

      public abstract void setTimeBetweenFrames(float deltaT) throws IllegalArgumentException, IOException
      Sets the time between frames in a 4- or higher dimensional image.
      Parameters:
      deltaT - the time between frames (in seconds).
      Throws:
      IllegalArgumentException - if deltaT is negative.
      IOException - if an I/O error occurs.
      IndexOutOfBoundsException - if the image doesn't have a dimensionality of at least 4.
    • setImageOrientationPositionPatient

      public abstract void setImageOrientationPositionPatient(org.jogamp.vecmath.Vector3f[] orientation, org.jogamp.vecmath.Point3f position, boolean force) throws IOException, IndexOutOfBoundsException
      Sets the direction cosines of the row, column and slice directions of the image, the coordinates of the center of the first pixel of the image, in patient (LPS) coordinates.

      N.B. the actual position and orientation set by this method may not be those specified. For example, for NIFTI-1 images, the actual orientation and position may depend on the user Preferences for whether to put pixel values in an order that is compatible with SPM. After using this method, you should use the ReadableImage.getImageOrientationPatient() and ReadableImage.getImagePositionPatient() methods to obtain the real orientation and positions set.

      If the orientation or position cannot be set for this image, this method does not report an error.

      Specified by:
      setImageOrientationPositionPatient in interface WritableImage
      Parameters:
      orientation - the direction cosines of the image row, column and (optionally) slice directions respectively in Left,Posterior,Superior (LPS) coordinates. If orientation is null, this method will attempt to clear any orientation information, if that is supported by the image format.
      position - the Left,Posterior,Superior (LPS) coordinates of the centre of the first pixel in the image data matrix. If position is null, this method will attempt to clear any positional information, if that is supported by the image format.
      force - if true, this method will force the orientation and position to be set as requested, regardless of the user Preferences. This can be useful if you read the orientation from an existing image, and you want to set the orientation exactly the same in a new image.
      Throws:
      IndexOutOfBoundsException - if the orientation array does not have the correct length.
      IOException - if an I/O error occurs.
    • getMostLikePlane

      public MostLikePlane getMostLikePlane()
      Description copied from interface: ReadableImage
      Returns the imaging plane that this image is "most like".
      Specified by:
      getMostLikePlane in interface ReadableImage
      Returns:
      the plane that is "most" like the imaging plane for this image. Returns MostLikePlane.UNKNOWN if the imaging plane cannot be determined, or if the image does not contain a set of parallel slices.
    • setImageOrientationPatient

      public abstract void setImageOrientationPatient(org.jogamp.vecmath.Vector3f[] orientation, int slice) throws IndexOutOfBoundsException
      Sets the direction cosines of the row, column and slice directions (for increasing row, column and slice) of the image, in patient (LPS) coordinates.

      If the orientation cannot be set for this image, this method does nothing.

      Specified by:
      setImageOrientationPatient in interface WritableImage
      Parameters:
      orientation - the direction cosines of the image row, column and (optionally) slice directions respectively in Left,Posterior,Superior (LPS) coordinates.
      slice - the slice for which to set the orientation.
      Throws:
      IndexOutOfBoundsException - if the cosines array does not have the correct dimensions.
    • setIntensityRescale

      public void setIntensityRescale(float[] rescaleSlopeIntercept) throws InvalidImageException, IOException
      Description copied from interface: WritableImage
      Sets the values m and b in the relationship between pixel intensity (I) values and the output units specified in WritableImage.setRescaleUnits(com.xinapse.dicom.RescaleUnits) in the expression:
      Output units = m*I + b.
      Specified by:
      setIntensityRescale in interface WritableImage
      Parameters:
      rescaleSlopeIntercept - an array of length 2, containing the values of m and b in the expression above, in that order.
      Throws:
      InvalidImageException - if rescaling cannot be set for this image.
      IOException - if an I/O error occurs.
    • getModality

      public Modality getModality()
      Description copied from interface: ReadableImage
      Returns the imaging modality with which this image was collected.
      Specified by:
      getModality in interface ReadableImage
      Returns:
      the Modality used to collect this image.
    • setModality

      public void setModality(Modality modality) throws IOException
      Description copied from interface: WritableImage
      Sets the modality with which this image was acquired. No exception occurs if the image format does not support modality recording.
      N.B. For disk-based images, the changes in the modality will not be reflected on disk unless the close() method is called.
      Specified by:
      setModality in interface WritableImage
      Parameters:
      modality - the new imaging modality to be assigned to this image.
      Throws:
      IOException - if modality cannot be set.
    • getFrameOfReferenceUID

      public com.xinapse.dicom.Uid getFrameOfReferenceUID()
      Description copied from interface: ReadableImage
      Returns the frame of reference UID that uniquely identifies the frame of reference for an image.
      Specified by:
      getFrameOfReferenceUID in interface ReadableImage
      Returns:
      the frame of reference UID, or null if this image does not have frame of reference UID.
    • setStudyInstanceUID

      public void setStudyInstanceUID(com.xinapse.dicom.Uid uid)
      Description copied from interface: WritableImage
      Sets the study instance UID for this image.
      N.B. For disk-based images, the changes in the study instance UID will not be reflected on disk unless the close() method is called.
      Specified by:
      setStudyInstanceUID in interface WritableImage
      Parameters:
      uid - the new study instance UID to be assigned to this image.
    • setSeriesInstanceUID

      public void setSeriesInstanceUID(com.xinapse.dicom.Uid uid)
      Description copied from interface: WritableImage
      Sets the series instance UID for this image.
      N.B. For disk-based images, the changes in the series instance UID will not be reflected on disk unless the close() method is called.
      Specified by:
      setSeriesInstanceUID in interface WritableImage
      Parameters:
      uid - the new series instance UID to be assigned to this image.
    • setFrameOfReferenceUID

      public void setFrameOfReferenceUID(com.xinapse.dicom.Uid uid)
      Description copied from interface: WritableImage
      Sets the frame of reference UID that uniquely identifies the frame of reference for an image.
      Specified by:
      setFrameOfReferenceUID in interface WritableImage
      Parameters:
      uid - the frame of reference UID. If uid is null, the frame of reference Uid is removed from the image header.
    • getDateFormat

      public static DateFormat getDateFormat()
      Returns the DateFormat used when this class writes dates.
      Returns:
      the DateFormat used when this class writes dates.
    • getScanDateFormat

      public static DateFormat getScanDateFormat()
      Returns the DateFormat with which a scan date should be formatted.
      Returns:
      the DateFormat with which a scan date should be formatted.
    • getBodyPart

      public com.xinapse.dicom.BodyPart getBodyPart()
      By default, body part recording is not supported, so this method always returns null.
      Specified by:
      getBodyPart in interface ReadableImage
      Returns:
      null.
    • setBodyPart

      public void setBodyPart(com.xinapse.dicom.BodyPart bodyPart) throws IOException
      By default, body part recording is not supported, so this method does nothing.
      Specified by:
      setBodyPart in interface WritableImage
      Parameters:
      bodyPart - body the imaged body part.
      Throws:
      IOException - if body part cannot be set.
    • getLaterality

      public com.xinapse.dicom.Laterality getLaterality()
      By default, laterality recording is not supported, so this method returns Laterality.BOTH.
      Specified by:
      getLaterality in interface ReadableImage
      Returns:
      Laterality.BOTH.
    • setLaterality

      public void setLaterality(com.xinapse.dicom.Laterality laterality) throws IOException
      By default, laterality recording is not supported, so this method does nothing.
      Specified by:
      setLaterality in interface WritableImage
      Parameters:
      laterality - the image laterality.
      Throws:
      IOException - if laterality cannot be set.
    • getPix

      public Object getPix() throws IllegalStateException
      Returns all pixel values from this image. The pixel values are returned in the order in which they are stored internally.
      Specified by:
      getPix in interface ReadableImage
      Returns:
      a one-dimensional array of pixel values of the correct type for this image, cast to an Object.
      Throws:
      IllegalStateException - if an error occurs while accessing the pixel values.
    • getPix

      public Object getPix(boolean radiological) throws IllegalStateException
      Returns all pixel values from this image.
      Specified by:
      getPix in interface ReadableImage
      Parameters:
      radiological - true if a standard radiological orientation of the array of pixels is required. Standard radiological orientation is:
      • For axial images, increasing left coordinate with column number, and increasing posterior coordinate with row number.
      • For coronal images, increasing left coordinate with column number, and increasing inferior coordinate with row number.
      • For sagittal images, increasing posterior coordinate with column number, and increasing inferior coordinate with row number.
      If false, the pixels are returned without any consideration of the orientation.
      Returns:
      a one-dimensional array of pixel values of the correct type for this image, cast to an Object.
      Throws:
      IllegalStateException - if an error occurs while accessing the pixel values.
    • getPix

      public Object getPix(int[] lowIdx, int[] highIdx) throws IllegalStateException
      Description copied from interface: ReadableImage
      Returns pixel values from this image. The lowIdx and highIdx arrays should have at least a number of elements at least equal to the dimensionality of the image, and the elements specifing the pixel number range for each dimension. For example, if an image has 3 dimensions, and dimensions of {5, 256, 256}, then pixels for the middle three slices will be returned by setting lowIdx to {1, 0, 0} and highIdx to {4, 255, 255}.
      Specified by:
      getPix in interface ReadableImage
      Parameters:
      lowIdx - an array of int specifying the low index of pixel values to get.
      highIdx - an array of int specifying the high index of pixel values to get.
      Returns:
      a one-dimensional array of pixel values of the correct type for this image, cast to an Object.
      Throws:
      IllegalStateException
    • getPix

      public Object getPix(Object array, int[] lowIdx, int[] highIdx)
      Description copied from interface: ReadableImage
      Get pixel values from this image into a specified array. array is a 1-dimensional array of the correct type of element for this image into which pixel values will be copied; it must be cast to an Object and must have enough elements to contain all the pixel values requested. The lowIdx and highIdx int arrays should have at least a number of elements at least equal to the dimensionality of the image, and the elements specifing the pixel number range for each dimension. For example, if an image has 3 dimensions, and dimensions of {5, 256, 256}, then pixels for the middle three slices will be returned by setting lowIdx to {1, 0, 0} and highIdx to {4, 255, 255}.
      Specified by:
      getPix in interface ReadableImage
      Parameters:
      array - a 1-dimensional array of length at least enough to contain all the pixel values, and of the correct java primitive data type.
      lowIdx - an array of int specifying the low index of pixel values to get.
      highIdx - an array of int specifying the high index of pixel values to get.
      Returns:
      a one-dimensional array of pixel values of the correct type for this image, cast to an Object.
    • getStoredPix

      public Object getStoredPix()
      Description copied from interface: ReadableImage
      Returns all the pixel values for this image in the order in which they are stored internally, and in the format they are stored internally.
      Specified by:
      getStoredPix in interface ReadableImage
      Returns:
      all the pixel values for this image.
    • putPix

      public void putPix(Object array) throws IllegalStateException
      Put pixel values from a specified array to this image. array is an array of the correct type of element for this image from which pixel values will be copied; it must be cast to an Object and must have the correct number of elements. The pixel values are set in the order in which they are stored internally.
      Parameters:
      array - a 1-dimensional array of pixel values of the correct java primitive data type to put to the image.
      Throws:
      IllegalStateException - if an I/O error occurs while accessing the pixel values.
      IllegalArgumentException - if the pixel values are of the wrong primitive data type, or cannot be put for other reasons.
    • putPix

      public void putPix(Object array, boolean radiological) throws IllegalStateException
      Put pixel values from a specified array to this image. array is an array of the correct type of element for this image from which pixel values will be copied; it must be cast to an Object and must have the correct number of elements.
      Specified by:
      putPix in interface WritableImage
      Parameters:
      array - a 1-dimensional array of pixel values of the correct java primitive data type to put to the image.
      radiological - true if the pixels have a standard radiological orientation Standard radiological orientation is:
      • For axial images, increasing left coordinate with column number, and increasing posterior coordinate with row number.
      • For coronal images, increasing left coordinate with column number, and increasing inferior coordinate with row number.
      • For sagittal images, increasing posterior coordinate with column number, and increasing inferior coordinate with row number.
      If false, the pixels are put without any consideration of the orientation.
      Throws:
      IllegalStateException - if an I/O error occurs while accessing the pixel values.
      IllegalArgumentException - if the pixel values are of the wrong primitive data type, or cannot be put for other reasons.
    • putPix

      public void putPix(Object array, int[] lowIdx, int[] highIdx) throws IllegalStateException
      Put pixel values from a specified array to this image. array is an array of the correct type of element for this image from which pixel values will be copied; it must be cast to an Object and must have the right number of elements to copy to the pixel values requested. The lowIdx and highIdx int arrays should have at least nDim elements, and the elements specify the pixel number range for each dimension. For example, if an image has nDim = 3, and dims[] = {5, 256, 256}, then pixels for the middle slices 4 will be returned by setting lowIdx to {1, 0, 0} and highIdx to {4, 255, 255}.
      Specified by:
      putPix in interface WritableImage
      Parameters:
      array - a 1-dimensional array of pixel values of the correct java primitive data type to put to the image.
      lowIdx - an array of int specifying the low index of pixel values to put.
      highIdx - an array of int specifying the high index of pixel values to put.
      Throws:
      IllegalStateException - if an error occurs while accessing the pixel values.
      IllegalArgumentException - if the indices supplied extend beyond the image, the pixel values are of the wrong primitive data type or cannot be put for other reasons.
    • getPix

      public Object getPix(int[] pixIdx) throws IllegalStateException
      Returns a single pixel value from the image.
      Specified by:
      getPix in interface ReadableImage
      Parameters:
      pixIdx - an int[] of length at least equal to nDim for this image where each element corresponds to an index to the pixel in each dimension. The first element of pixIdx refers to the slowest-varying dimension, and the last relevant element refers to the fastest-varying dimension. For example, for a 3-D image, pixIdx[0] refers to the slice dimension, and pixIdx[2] refers to the column dimension.
      Returns:
      the pixel value as a java Object cast from the appropriate class. For example, for a short int image, the pixel will be a Short cast to Object.
      Throws:
      IllegalStateException - if the pixel data cannot be retrieved.
    • putPix

      public void putPix(Object pixValue, int[] pixIdx) throws IOException
      Puts a single pixel value to the image.
      Specified by:
      putPix in interface WritableImage
      Parameters:
      pixValue - the pixel value to put, as a suitable Object.
      pixIdx - an int[] of length at least equal to nDim for this image where each element corresponds to an index to the pixel in each dimension. The first element of pixIdx refers to the slowest-varying dimension, and the last relevant element refers to the fastest-varying dimension. For example, for a 3-D image, pixIdx[0] refers to the slice dimension, and pixIdx[2] refers to the column dimension.
      Throws:
      IOException - if an I/O error occurs while accessing the pixel values.
      IllegalArgumentException - if the indices are inappropriate for this image, if the supplied pixel is of the wrong Class, or if the pixel value cannot be written to the image.
    • getSlice

      public Object getSlice(int slice) throws IllegalStateException
      Description copied from interface: ReadableImage
      Returns the pixel values for one slice of an n-dimensional image, where n > 1.

      N.B.The pixel values are always returned in a standard radiological orientation. Standard radiological orientation is:

      • For axial images, increasing left coordinate with column number, and increasing posterior coordinate with row number.
      • For coronal images, increasing left coordinate with column number, and increasing inferior coordinate with row number.
      • For sagittal images, increasing posterior coordinate with column number, and increasing inferior coordinate with row number.
      Thus, when this slice is viewed on-screen, the first pixel in the array returned belongs at the top left of the screen, and the last pixel in the array belongs at the bottom right of the screen. This is regardless of the sub-class of image (for example, the flipping of Analyze images is taken care of by this method).
      Specified by:
      getSlice in interface ReadableImage
      Parameters:
      slice - the slice number. Must be 0 for a 2-dimensional image or from 0 to dims[0]-1 for a 3-dimensional image. For images of higher dimensionality, each extra dimension multiplies the number of available slices by the size in that dimension, so all images of higher dimensionality that 1 look like multi-slice images.
      Returns:
      a 1-dimensional array of the primitive java type appropriate for this image, and of size [nRows * nCols]. This array is cast to an Object before return.
      Throws:
      IllegalStateException
    • getSlice

      public Object getSlice(Object array, int slice) throws IllegalStateException, IndexOutOfBoundsException
      Description copied from interface: ReadableImage
      Returns all the pixels for a two-dimensional slice of this image, as a 1-dimensional array of primitive values. The pixels values are ordered so that the first pixel in the returned array should be displayed at the top left corner of the 2-D image array, when viewed in standard radiological orientation.

      If the supplied array is null, a new array will be created and returned.

      Specified by:
      getSlice in interface ReadableImage
      Parameters:
      array - an array of suitable length and of a suitable primitive data type for this image.
      slice - the slice number. Slices numbered from zero up to one less than the total number of slices in this image, regardless of the dimensionality of the image.
      Returns:
      an array of the correct primitive data type for this image.
      Throws:
      IndexOutOfBoundsException - if the slice number is invalid for this image,
      IllegalStateException
    • putSlice

      public void putSlice(Object array, int slice) throws IllegalStateException
      Puts the pixel values to one slice of an n-dimensional image, where n > 1.

      N.B.Whenever the radiological orientation of the image can be determined, this method sets pixel values such that when the slice is viewed on-screen, the first pixel in the array belongs at the top left of the screen, and the last pixel in the array belongs at the bottom right of the screen. This is regardless of the sub-class of image (for example, the flipping of Analyze images is taken care of by this method).

      Specified by:
      putSlice in interface WritableImage
      Parameters:
      array - a 1-dimensional array of the correct primitive java data type for this image, with dimensions [nRows * nCols] containing the pixel values to put.
      slice - the slice number. Must be 0 for a 2-dimensional image or from 0 to dims[0]-1 for a 3-dimensional image.
      Throws:
      IllegalStateException - if an I/O error occurs while putting the pixel values, or if the array is not of the correct primitive data type for this image.
      ArrayIndexOutOfBoundsException - if the image does not have the right dimensionality, if the slice number is inappropriate for this image.
    • getPresentationPixelDataType

      public PixelDataType getPresentationPixelDataType()
      Description copied from interface: ReadableImage
      Returns a PixelDataType representing the data type of pixel values for this image, after any intensity scaling has taken place.
      Specified by:
      getPresentationPixelDataType in interface ReadableImage
      Returns:
      the PixelDataType representing the data type of this image after any remapping of intensity values (rescaling and adding an intensity offset) has taken place.
    • setMinMax

      public void setMinMax(int[] minmax) throws InvalidImageException
      Sets the min and max pixel values for this image. It is up to the caller to ensure that the values supplied are correct at the time they are written to the image. Any subsequent changes to the image pixel values may cause either the values returned by getMin() and getMax() to be incorrect, or cause these methods to throw a InvalidImageException.
      Parameters:
      minmax - an int array of length at least 2, where the first element is the minimum pixel value in the image, and second element is the maximum pixel value in the image.
      Throws:
      InvalidImageException - if the values supplied are unsuitable, or the values cannot be set.
    • setMinMax

      public abstract void setMinMax(int min, int max) throws InvalidImageException
      Sets the min and max pixel values for this image. It is up to the caller to ensure that the values supplied are correct at the time they are written to the image. Any subsequent changes to the image pixel values may cause either the values returned by getMin() and getMax() to be incorrect, or cause these methods to throw a InvalidImageException.
      Specified by:
      setMinMax in interface WritableImage
      Parameters:
      min - the minimum pixel value in the image.
      max - the maximum pixel value in the image.
      Throws:
      InvalidImageException - if the array supplied is unsuitable, or the values cannot be set.
    • getROIs

      public List<ROI> getROIs()
      Description copied from interface: ReadableImage
      Returns a List of ROIs that are stored with the image.
      Specified by:
      getROIs in interface ReadableImage
      Returns:
      a List of ROIs that are stored with the image, or null if there are no ROIs stored with the image.
    • clone

      public MultiSliceImage clone()
      Returns a copy of this MultiSliceImage. The copy will always be an in-memory image, regardless of whether the original is in-memory or on disk.
      Overrides:
      clone in class Object
      Returns:
      a clone of this MultiSliceImage instance.
    • parseMultiValuedString

      protected static double[] parseMultiValuedString(String s, int nValues) throws ParseException
      Convenience method to parse Strings of the form "value1\value2\value3\…\valueN", where value1 to valueN are numerical values.
      Parameters:
      s - the String to be parsed.
      nValues - the number of values expected in s.
      Returns:
      the multiple values in s as a double[].
      Throws:
      ParseException - if nValues numerical values cannot be parsed from String s.
    • main

      public static void main(String[] args)
      Run the self-test on the MultiSliceImage class.
      Parameters:
      args - ignored.