Class Analyze75Image

All Implemented Interfaces:
ReadableImage, WritableImage, AutoCloseable

public class Analyze75Image extends ANZImage implements AutoCloseable
This class is a representation of a multi-dimensional image in the Analyze 7.5 format. An Analyze75Image can be created from two data sources (one for the header, the other for the image data), or it can be created afresh.

Image data for images loaded from disk remain on disk, and have their pixel loaded as required; image data loaded from streams or created afresh reside in memory.

Both big-endian and little-endian byte ordering are implemented and supported. When reading existing images, the byte order is auto-detected from the header file. When existing images are copied or modified, the original byte order is retained. For images newly-created from scratch by this package, the byte ordering is the native byte order.

N.B. The Analyze format requires that for BINARY images, individual slices must begin on a byte boundary. In this implementation, that restriction is removed. If you wish to maintain compatibility with Analyze and other programs that maintain this restriction, ensure that a multi-slice/multi-frame images have slices with a number of pixels that is a multiple of 8 (bits).

  • Field Details

    • DEFAULT_COMPRESSED

      public static final boolean DEFAULT_COMPRESSED
      Whether to store Analyze 7.5 images compressed by default.
      See Also:
  • Constructor Details

    • Analyze75Image

      public Analyze75Image()
      Creates an uninitialised instance of an Analyze75Image. Needed so that newInstance() method can be called on the class.
    • Analyze75Image

      public Analyze75Image(short nCols, short nRows, short nSlices, short nFrames, ANZPixFormat dataType) throws ANZException
      Creates a new in-memory Analyze75Image. This image exists in memory, and will only be written with an explicit write() method call.
      Parameters:
      nCols - the number of columns in the image x-direction.
      nRows - the number of rows in the image y-direction.
      nSlices - the number of slice in the image.
      nFrames - the number of frames (time points) in the image.
      dataType - the ANZPixFormat for the image. If dataType is not one of the original Analyze 7.5 pixel formats, then an ANZException is thrown.
      Throws:
      ANZException - if the image cannot be created.
    • Analyze75Image

      public Analyze75Image(ANZPixFormat dataType, Short... dims) throws ANZException
      Creates a new in-memory Analyze75Image. This image exists in memory, and will only be written with an explicit write() method call.
      Parameters:
      dataType - an ANZPixFormat.
      dims - the number of samples in each of the image dimensions. The number of arguments supplied determines the dimensionality of the image.
      Throws:
      ANZException - if the header cannot be created.
    • Analyze75Image

      public Analyze75Image(String fileName, FileAccessMode mode, Logger logger) throws InvalidImageException, IOException
      Opens an existing Analyze75Image, with pixel data remaining on disk until requested.
      Parameters:
      fileName - the name of the image file.
      mode - the access mode for the image.
      logger - the Logger for warning/error messages.
      Throws:
      InvalidImageException - if the image cannot be opened or loaded, or if mode is invalid.
      FileNotFoundException - if the image file doesn't exist.
      IOException - if an I/O error occurs.
    • Analyze75Image

      public Analyze75Image(Analyze75Image im)
      Instantiates a new Analyze75Image, copying it from an existing one.
      Parameters:
      im - the image to copy.
  • Method Details

    • getSaveCompressed

      public static boolean getSaveCompressed()
      Returns whether Analyze 7.5 images should be stored compressed. The value is obtained either from the System Property "analyze.compressed" (preferentially) or the user's preference.
      Returns:
      true if the Analyze 7.5 images should be stored compressed; false otherwise.
    • getPreferredCompressed

      public static boolean getPreferredCompressed()
      Returns the user's preference about whether Analyze 7.5 images should be stored compressed.

      If the system property "analyze.compressed" exists, and the property value is either "true" or "false", then the user's preference is overridden by the property value.

      Returns:
      true if the user prefers to store Analyze 7.5 images compressed; false otherwise.
    • savePreferredCompressed

      public static void savePreferredCompressed(boolean compressed)
      Sets the user's preference about whether Analyze 7.5 images should be stored compressed.
      Parameters:
      compressed - true if the user prefers to store Analyze 7.5 images compressed.
    • getCopy

      public Analyze75Image getCopy()
      Creates an in-memory copy of an Analyze 7.5 image.
      Specified by:
      getCopy in interface ReadableImage
      Specified by:
      getCopy in interface WritableImage
      Returns:
      a copy of the Analyze75Image.
    • getPreviewIcon

      public static PreviewIcon getPreviewIcon(File f, boolean withImagePreview)
      Returns the PreviewIcon for an Analyze75Image header, or null if the supplied File does not represent an Analyze 7.5 image header.
      Parameters:
      f - the File to be tested.
      withImagePreview - whether a image preview is to be generated. Generating an image preview will take longer than not generating one.
      Returns:
      PreviewIcon if the File produces an Analyze75Image header; null otherwise.
    • isFlipped

      public boolean isFlipped()
      Returns true if this Analyze75Image is flipped.
      Returns:
      true if this Analyze75Image is flipped; false otherwise.
    • getOrient

    • getNSliceLocations

      public int getNSliceLocations()
      For Analyze 7.5 images, all slices in a block are parallel and evenly-spaced. As long as the slice-separation is non-zero, the number of slice locations is equal to the dimensions of the slice dimension.
      Specified by:
      getNSliceLocations in interface ReadableImage
      Returns:
      1 if the slice separation is zero; the size of the slice dimension otherwise.
    • setImagePositionPatient

      public void setImagePositionPatient(org.jogamp.vecmath.Point3f position, int slice)
      This action is not supported by the Analyze 7.5 file format, so this method has no effect. All slices are parallel in a block, and the position of individual slices may not be set.
      Specified by:
      setImagePositionPatient in interface WritableImage
      Parameters:
      position - the position of the first pixel in the volume.
      slice - the slice number in the volume.
    • setImageOrientationPatient

      public void setImageOrientationPatient(org.jogamp.vecmath.Vector3f[] orientation, int slice)
      This action is not supported by the Analyze 7.5 file format, so this method has no effect. All slices are parallel in a block, and the position of individual slices may not be set.
      Specified by:
      setImageOrientationPatient in interface WritableImage
      Specified by:
      setImageOrientationPatient in class MultiSliceImage
      Parameters:
      orientation - the direction cosines of the image row, column and (optionally) slice directions respectively in Left,Posterior,Superior (LPS) coordinates.
      slice - the slice number in the volume.
    • supportsIntensityRescaling

      public boolean supportsIntensityRescaling()
      Returns false because Analyze 7.5 images do not support intensity rescaling.
      Specified by:
      supportsIntensityRescaling in interface WritableImage
      Returns:
      false.
    • getIntensityRescale

      public float[] getIntensityRescale()
      Intensity rescaling is not supported by Analyze 7.5 format, so this method always returns float[] [1.0f, 0.0f].
      Specified by:
      getIntensityRescale in interface ReadableImage
      Returns:
      the array [1.0f, 0.0f].
    • setIntensityRescale

      public void setIntensityRescale(float rescaleSlope, float rescaleIntercept) throws InvalidImageException
      Intensity rescaling is not supported by Analyze 7.5 format, so this method does nothing.
      Specified by:
      setIntensityRescale in interface WritableImage
      Parameters:
      rescaleSlope - ignored.
      rescaleIntercept - ignored.
      Throws:
      InvalidImageException - if the supplied intensity rescaling is not the identity.
    • setRescaleUnits

      public void setRescaleUnits(com.xinapse.dicom.RescaleUnits units)
      This action is not supported by the Analyze file format, so this method does nothing.
      Specified by:
      setRescaleUnits in interface WritableImage
      Parameters:
      units - ignored.
    • setOrient

      public void setOrient(byte orient) throws ANZException
      Sets the orientation of this Analyze75Image.
      Parameters:
      orient - the orientation code for the image. Must be one of:
      Throws:
      ANZException - if the orient is invalid, or if the orientation cannot be set.
    • appendAuditInfo

      public void appendAuditInfo(String name, String value)
      This action is not supported by Analyze 7.5 format, so this method does nothing.
      Specified by:
      appendAuditInfo in interface WritableImage
      Parameters:
      name - the audit information name.
      value - the audit information value.
    • getPatientPosition

      public PatientPosition getPatientPosition()
      This action is not supported by the Analyze file format, so this method always returns null.
      Specified by:
      getPatientPosition in interface ReadableImage
      Returns:
      null.
    • setPatientPosition

      public void setPatientPosition(PatientPosition position)
      This action is not supported by the Analyze file format, so this method does nothing.
      Specified by:
      setPatientPosition in interface WritableImage
      Parameters:
      position - the position in which the patient is lying in the scanning equipment. e.g. PatientPosition.HFS (head-first supine).
    • setScanTR

      public void setScanTR(Float TR)
      This action is not supported by Analyze 7.5 format, so this method does nothing.
      Specified by:
      setScanTR in interface WritableImage
      Parameters:
      TR - the scan repetition time.
    • setScanTI

      public void setScanTI(Float TI)
      This action is not supported by Analyze 7.5 format, so this method does nothing.
      Specified by:
      setScanTI in interface WritableImage
      Parameters:
      TI - the scan inversion time.
    • setScanTE

      public void setScanTE(Float TE)
      This action is not supported by Analyze 7.5 format, so this method does nothing.
      Specified by:
      setScanTE in interface WritableImage
      Parameters:
      TE - the scan echo time.
    • setFrameTE

      public void setFrameTE(Float TE, int frame)
      This action is not supported by Analyze 7.5 format, so this method does nothing.
      Specified by:
      setFrameTE in interface WritableImage
      Parameters:
      TE - the scan echo time.
      frame - the frame number for which to set the TE.
    • getDICOMImageType

      public String[] getDICOMImageType()
      This action is not supported by Analyze 7.5 format, so this method returns null.
      Specified by:
      getDICOMImageType in interface ReadableImage
      Returns:
      null.
    • setDICOMImageType

      public void setDICOMImageType(String[] imageTypes)
      This action is not supported by Analyze 7.5 format, so this method does nothing.
      Specified by:
      setDICOMImageType in interface WritableImage
      Parameters:
      imageTypes - the image types.
    • getFrameDICOMImageType

      public String[] getFrameDICOMImageType(int index)
      This action is not supported by Analyze 7.5 format, so this method returns null.
      Specified by:
      getFrameDICOMImageType in interface ReadableImage
      Parameters:
      index - the frame for which to return the image type.
      Returns:
      null.
    • setFrameDICOMImageType

      public void setFrameDICOMImageType(String[] imageTypes, int index)
      This action is not supported by Analyze 7.5 format, so this method does nothing.
      Specified by:
      setFrameDICOMImageType in interface WritableImage
      Parameters:
      imageTypes - the image types.
      index - the index for which to set the image type.
    • setSaturationFreqOffsetPPM

      public void setSaturationFreqOffsetPPM(Float freqOffset)
      This action is not supported by Analyze 7.5 format, so this method does nothing.
      Specified by:
      setSaturationFreqOffsetPPM in interface WritableImage
      Parameters:
      freqOffset - the saturation frequency offset in PPM.
    • setFrameSaturationFreqOffsetPPM

      public void setFrameSaturationFreqOffsetPPM(Float freqOffset, int index)
      This action is not supported by Analyze 7.5 format, so this method does nothing.
      Specified by:
      setFrameSaturationFreqOffsetPPM in interface WritableImage
      Parameters:
      freqOffset - the saturation frequency offset in PPM.
      index - the index for which to set the saturation frequency offset.
    • setEchoTrainLength

      public void setEchoTrainLength(Integer etl)
      This action is not supported by Analyze 7.5 format, so this method does nothing.
      Specified by:
      setEchoTrainLength in interface WritableImage
      Parameters:
      etl - the echo train length.
    • setFlipAngle

      public void setFlipAngle(Float flipAngle)
      This action is not supported by Analyze 7.5 format, so this method does nothing.
      Specified by:
      setFlipAngle in interface WritableImage
      Parameters:
      flipAngle - the scan flip angle.
    • getSliceThickness

      public Float getSliceThickness()
      This action is not supported by the Analyze file format, so this method always returns null.
      Specified by:
      getSliceThickness in interface ReadableImage
      Returns:
      null;
    • setSliceThickness

      public void setSliceThickness(Float thickness)
      This action is not supported by the Analyze file format, so this method does nothing.
      Specified by:
      setSliceThickness in interface WritableImage
      Parameters:
      thickness - ignored.
    • getScanDate

      public Date getScanDate()
      Scan dates are not supported by Analyze 7.5 format.
      Specified by:
      getScanDate in interface ReadableImage
      Returns:
      null always.
    • setScanDate

      public void setScanDate(Date scanDate)
      This action is not supported by Analyze 7.5 format, so this method does nothing.
      Specified by:
      setScanDate in interface WritableImage
      Parameters:
      scanDate - the new scan date/time.
    • getPulseSequence

      public String getPulseSequence()
      Pulse sequence names are not supported by Analyze 7.5 for,at.
      Specified by:
      getPulseSequence in interface ReadableImage
      Returns:
      null always.
    • setPulseSequence

      public void setPulseSequence(String seqName)
      This action is not supported by Analyze 7.5 format, so this method does nothing.
      Specified by:
      setPulseSequence in interface WritableImage
      Parameters:
      seqName - the new scanning sequence name.
    • getScanningSequence

      public PulseSequenceType getScanningSequence()
      Scan sequences are not supported by Analyze 7.5 format.
      Specified by:
      getScanningSequence in interface ReadableImage
      Returns:
      null.
    • setScanningSequence

      public void setScanningSequence(PulseSequenceType seq)
      This action is not supported by Analyze 7.5 format, so this method does nothing.
      Specified by:
      setScanningSequence in interface WritableImage
      Parameters:
      seq - the new scanning sequence name.
    • getSequenceVariant

      public PulseSequenceVariant getSequenceVariant()
      Scanning sequence variants are not supported by Analyze 7.5 format.
      Specified by:
      getSequenceVariant in interface ReadableImage
      Returns:
      null.
    • getSeriesDescription

      public String getSeriesDescription()
      Series descriptions are not supported by Analyze 7.5 format.
      Specified by:
      getSeriesDescription in interface ReadableImage
      Returns:
      null.
    • getSeriesNumber

      public Integer getSeriesNumber()
      Series numbers are not supported by Analyze 7.5 format.
      Specified by:
      getSeriesNumber in interface ReadableImage
      Returns:
      null.
    • setSequenceVariant

      public void setSequenceVariant(PulseSequenceVariant seqVar)
      This action is not supported by Analyze 7.5 format, so this method does nothing.
      Specified by:
      setSequenceVariant in interface WritableImage
      Parameters:
      seqVar - the new scanning sequence variant name.
    • setSeriesNumber

      public void setSeriesNumber(Integer seriesNumber)
      This action is not supported by Analyze 7.5 format, so this method does nothing.
      Specified by:
      setSeriesNumber in interface WritableImage
      Parameters:
      seriesNumber - the new series number.
    • setSeriesDescription

      public void setSeriesDescription(String description)
      This action is not supported by Analyze 7.5 format, so this method does nothing.
      Specified by:
      setSeriesDescription in interface WritableImage
      Parameters:
      description - the new series description.
    • getPatientName

      public String getPatientName()
      Patient names are not supported by Analyze 7.5 format.
      Specified by:
      getPatientName in interface ReadableImage
      Returns:
      null.
    • getPatientID

      public String getPatientID()
      Returns the Patient ID set in the image header.
      Specified by:
      getPatientID in interface ReadableImage
      Returns:
      the Patient ID set in the image header.
    • getPatientDoB

      public Date getPatientDoB()
      Patient's Birth Date is not supported by Analyze 7.5 format.
      Specified by:
      getPatientDoB in interface ReadableImage
      Returns:
      null.
    • getPatientSex

      public com.xinapse.dicom.Sex getPatientSex()
      Description copied from interface: ReadableImage
      Returns the patient sex for this image.
      Specified by:
      getPatientSex in interface ReadableImage
      Returns:
      the patient's sex image, or Sex.OTHER if the patient's sex can't be found.
    • getStudyID

      public String getStudyID()
      Study ID is not supported by Analyze 7.5 format.
      Specified by:
      getStudyID in interface ReadableImage
      Returns:
      null.
    • getScanTR

      public Float getScanTR()
      This action is not supported by the Analyze 7.5 format, so this method always returns null.
      Specified by:
      getScanTR in interface ReadableImage
      Returns:
      null always.
    • getScanTI

      public Float getScanTI()
      This action is not supported by the Analyze 7.5 format, so this method always returns null.
      Specified by:
      getScanTI in interface ReadableImage
      Returns:
      null always.
    • getScanTE

      public Float getScanTE()
      This action is not supported by the Analyze file format, so this method always returns null.
      Specified by:
      getScanTE in interface ReadableImage
      Returns:
      null always.
    • getFrameTE

      public Float getFrameTE(int frame)
      This action is not supported by the Analyze file format, so this method always returns null.
      Specified by:
      getFrameTE in interface ReadableImage
      Parameters:
      frame - the index for which to return the echo time.
      Returns:
      null always.
    • getSaturationFreqOffsetPPM

      public Float getSaturationFreqOffsetPPM()
      This action is not supported by the Analyze file format, so this method always returns null.
      Specified by:
      getSaturationFreqOffsetPPM in interface ReadableImage
      Returns:
      null always.
    • getFrameSaturationFreqOffsetPPM

      public Float getFrameSaturationFreqOffsetPPM(int index)
      This action is not supported by the Analyze file format, so this method always returns null.
      Specified by:
      getFrameSaturationFreqOffsetPPM in interface ReadableImage
      Parameters:
      index - the frame for which to return the saturation frequency offset.
      Returns:
      null always.
    • getEchoTrainLength

      public Integer getEchoTrainLength()
      This action is not supported by the Analyze file format, so this method always returns null.
      Specified by:
      getEchoTrainLength in interface ReadableImage
      Returns:
      null always.
    • getFlipAngle

      public Float getFlipAngle()
      This action is not supported by the Analyze file format, so this method always returns null.
      Specified by:
      getFlipAngle in interface ReadableImage
      Returns:
      null always.
    • getFrameDWbValue

      public Float getFrameDWbValue(int frame)
      This action is not supported by the Analyze file format, so this method always returns null.
      Specified by:
      getFrameDWbValue in interface ReadableImage
      Parameters:
      frame - the frame number for which to get the b-value.
      Returns:
      null always.
    • setFrameDWbValue

      public void setFrameDWbValue(float bValue, int frame)
      This action is not supported by Analyze 7.5 format, so this method does nothing.
      Specified by:
      setFrameDWbValue in interface WritableImage
      Parameters:
      bValue - the diffusion-weighting b-value.
      frame - the index to the image frame for which to set the b-value. For 3-D images, this is the slice number; for 4-D images it is the frame number.
    • getFrameDWGradientVector

      public org.jogamp.vecmath.Vector3f getFrameDWGradientVector(int frame)
      This action is not supported by the Analyze file format, so this method always returns null.
      Specified by:
      getFrameDWGradientVector in interface ReadableImage
      Parameters:
      frame - the frame number for which to return the gradient-vector.
      Returns:
      null always.
    • setFrameDWGradientVector

      public void setFrameDWGradientVector(org.jogamp.vecmath.Vector3f gradVec, int frame)
      This action is not supported by Analyze 7.5 format, so this method does nothing.
      Specified by:
      setFrameDWGradientVector in interface WritableImage
      Parameters:
      gradVec - the diffusion-weighting gradient vector.
      frame - the index to the image frame for which to set the gradient vector. For 3-D images, this is the slice number; for 4-D images it is the frame number.
    • getFrameDWBMatrix

      public float[] getFrameDWBMatrix(int frame)
      This action is not supported by the Analyze file format, so this method always returns null.
      Specified by:
      getFrameDWBMatrix in interface ReadableImage
      Parameters:
      frame - the frame number for which to get the b-matrix.
      Returns:
      null always.
    • setFrameDWBMatrix

      public void setFrameDWBMatrix(float[] bMatrix, int frame)
      This action is not supported by Analyze 7.5 format, so this method does nothing.
      Specified by:
      setFrameDWBMatrix in interface WritableImage
      Parameters:
      bMatrix - the diffusion-weighting B-matrix.
      frame - the index to the image frame for which to set the B-matrix. For 3-D images, this is the slice number; for 4-D images it is the frame number.
    • getFrameTriggerDelayMS

      public Float getFrameTriggerDelayMS(int frame)
      This action is not supported by the Analyze file format, so this method always returns null.
      Specified by:
      getFrameTriggerDelayMS in interface ReadableImage
      Parameters:
      frame - the frame number for which to get the trigger delay.
      Returns:
      null always.
    • setFrameTriggerDelayMS

      public void setFrameTriggerDelayMS(float delay, int frame)
      This action is not supported by Analyze 7.5 format, so this method does nothing.
      Specified by:
      setFrameTriggerDelayMS in interface WritableImage
      Parameters:
      delay - the trigger delay (in milliseconds).
      frame - the index to the image frame for which to set the trigger delay. For 3-D images, this is the slice number; for 4-D images it is the frame number.
    • getRescaleUnits

      public com.xinapse.dicom.RescaleUnits getRescaleUnits()
      Description copied from interface: ReadableImage
      Returns the output units of Intensity Rescale Slope and Intensity Rescale Intercept, retrieved by getIntensityRescale().
      Specified by:
      getRescaleUnits in interface ReadableImage
      Overrides:
      getRescaleUnits in class ANZImage
      Returns:
      the RescaleUnits describing the physical meaning of the pixel intensity units. Returns the RescaleUnits.US if the physical meaning is unknown, or arbitrary.
    • setPatientName

      public void setPatientName(String patientName)
      This action is not supported by Analyze 7.5 format, so this method does nothing.
      Specified by:
      setPatientName in interface WritableImage
      Parameters:
      patientName - is ignored.
    • setPatientID

      public void setPatientID(String patientID)
      Description copied from interface: WritableImage
      Sets the patient ID for this image. If the new patient ID 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 patient ID recording.
      Specified by:
      setPatientID in interface WritableImage
      Parameters:
      patientID - the new patient ID to be assigned to this image.
    • setPatientDoB

      public void setPatientDoB(Date patientDoB)
      This action is not supported by Analyze 7.5 format, so this method does nothing.
      Specified by:
      setPatientDoB in interface WritableImage
      Parameters:
      patientDoB - is ignored.
    • setPatientSex

      public void setPatientSex(com.xinapse.dicom.Sex sex)
      This action is not supported by Analyze 7.5 format, so this method does nothing.
      Specified by:
      setPatientSex in interface WritableImage
      Parameters:
      sex - is ignored.
    • setStudyID

      public void setStudyID(String studyID)
      This action is not supported by Analyze 7.5 format, so this method does nothing.
      Specified by:
      setStudyID in interface WritableImage
      Parameters:
      studyID - is ignored.
    • getMin

      public Double getMin() throws ANZException
      Description copied from interface: ReadableImage
      Returns the minimum pixel intensity in the image.
      Specified by:
      getMin in interface ReadableImage
      Overrides:
      getMin in class ANZImage
      Returns:
      the maximum pixel intensity as a Double, or null if the intensity min hasn't been calculated for this image.
      Throws:
      ANZException
    • getMax

      public Double getMax() throws ANZException
      Description copied from interface: ReadableImage
      Returns the maximum pixel intensity in the image.
      Specified by:
      getMax in interface ReadableImage
      Overrides:
      getMax in class ANZImage
      Returns:
      the maximum pixel intensity as a Double, or null if the intensity max hasn't been calculated for this image.
      Throws:
      ANZException
    • getImageTypeName

      public String getImageTypeName()
      Returns the human readable name for this type of image.
      Specified by:
      getImageTypeName in interface WritableImage
      Returns:
      the String "Analyze".
    • getCommonName

      public static String getCommonName()
      Returns the common name for this type of image.
      Returns:
      the String "Analyze".
    • main

      public static void main(String[] args)
      Run the self-test for the Analyze75Image class.
      Parameters:
      args - an array of image file names to try to open.