Class MultiSliceImage

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

public abstract class MultiSliceImage extends Object implements WritableImage, 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:
    • ACCESSION_NUMBER_NAME

      public static final String ACCESSION_NUMBER_NAME
      The information field name that is written into image headers to indicate the accession number.
      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:
    • IMAGE_TYPE_NAME

      public static final String IMAGE_TYPE_NAME
      The information field name that is written into image headers to indicate the image type.
      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:
  • 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.
    • clearModified

      public void clearModified()
      Unsets the "modified" flag for this MultiSliceImage to indicate that it has been written since any changes were made.
    • setSuggestedFileName

      public void setSuggestedFileName(String name)
      Sets a suggested file name for 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.
    • 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 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.
    • 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
      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.
    • getAccessionNumber

      public String getAccessionNumber()
      Description copied from interface: ReadableImage
      Returns the accession number for this image.
      Specified by:
      getAccessionNumber in interface ReadableImage
      Returns:
      the accession number for this image, or null if the accession number can't be found.
    • setAccessionNumber

      public void setAccessionNumber(String accessionNumber)
      Description copied from interface: WritableImage
      Sets the accession number for this image. If the new accession number String is longer than is allowed by the image format, then it is truncated before being applied. No exception occurs if the image format does not support accession number recording.
      Specified by:
      setAccessionNumber in interface WritableImage
      Parameters:
      accessionNumber - the new accession number to be assigned to this image.
    • 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)
      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.
      Specified by:
      setModality in interface WritableImage
      Parameters:
      modality - the new imaging modality to be assigned to this image.
    • 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.
    • getStudyInstanceUID

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

      public void setStudyInstanceUID(com.xinapse.dicom.Uid uid)
      Description copied from interface: WritableImage
      Sets the study instance UID for this image.
      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.
      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)
      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.
    • 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)
      By default, laterality recording is not supported, so this method does nothing.
      Specified by:
      setLaterality in interface WritableImage
      Parameters:
      laterality - the image laterality.
    • getRawPix

      public Object getRawPix() 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:
      getRawPix in interface ReadableImage
      Returns:
      a one-dimensional array of pixel values of the correct type for this image.
      Throws:
      IllegalStateException - if an error occurs while accessing the pixel values.
    • getPix

      public Object getPix(boolean radiological) throws IllegalStateException
      Description copied from interface: ReadableImage
      Returns all the pixel values for this image, optionally returning them in the correct radiological order in which they will be presented, where the first pixel should be presented at the top left corner of the display device.
      Specified by:
      getPix in interface ReadableImage
      Parameters:
      radiological - true if the pixels are to be returned in the correct order for presentation, where the first returned pixel is to be presented at the top left, and the last at the bottom right of the display device; false if the are to be return in the order in which they are stored internally.
      Returns:
      all the pixel values for this image.
      Throws:
      IllegalStateException
    • 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 (the upper range index is exclusive). 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, 256, 256}.
      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. The high index is exclusive.
      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) throws IllegalStateException, IllegalArgumentException
      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, 256, 256}.
      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.
      Throws:
      IllegalArgumentException - if the indices supplied extend beyond the image, if the supplied array is of the wrong primitive data type, or if the pixel values cannot be gotten for other reasons.
      IllegalStateException
    • 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 3 slices will be returned by setting lowIdx to {1, 0, 0} and highIdx to {4, 256, 256}.
      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)
      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:
      IllegalStateException - if the image was opened read-only.
      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 put 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.
    • 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.
    • close

      public void close() throws InvalidImageException, IOException
      Closes this MultiSliceImage and frees up resources. If the image has been read from disk, has been modified, and is writable, then any changes are written to the disk file by this method. Any further operations to a closed MultiSliceImage are not possible, and may cause an exception to be thrown.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface ReadableImage
      Throws:
      InvalidImageException - if the image not valid and needs to be written.
      IOException - if the file cannot be written or closed.
    • disposeImageData

      public void disposeImageData()
      Description copied from interface: ReadableImage
      Gives this image the option to free up resources by removing access to image data. After this method is called, image data may no longer be accessible, and method calls to access it may result in an Exception being thrown.
      Specified by:
      disposeImageData in interface ReadableImage
    • doRescale

      public static Object doRescale(ReadableImage image, Object pix)
      Rescale some pixel intensities from an image according to to the rescale slope and intercept set in the image.
      Parameters:
      image - the image from which to get the rescale slope and intercept.
      pix - the pixel values to rescale.
      Returns:
      the rescaled pixel intensities, which may be a new Object or the original one supplied.
    • doUnRescale

      public static Object doUnRescale(ReadableImage image, Object pix)
      Undo the rescale some pixel intensities from an image according to to the rescale slope and intercept set in the image.
      Parameters:
      image - the image from which to get the rescale slope and intercept.
      pix - the pixel values to undo the rescaling.
      Returns:
      the un-rescaled pixel intensities, which may be a new Object or the original one supplied.
    • main

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