Class SourceImage

java.lang.Object
com.pixelmed.display.SourceImage
Direct Known Subclasses:
SourceImageSubset

public class SourceImage extends Object

A class that encapsulates the pixel data and features and values from an image source (such as a DICOM image), usually for the purpose of displaying it.

See Also:
  • Field Details

    • allowMemoryMapping

      protected static boolean allowMemoryMapping
    • allowMemoryMappingFromMultiplePerFrameFiles

      protected static boolean allowMemoryMappingFromMultiplePerFrameFiles
    • allowDeferredReadFromFileIfNotMemoryMapped

      protected static boolean allowDeferredReadFromFileIfNotMemoryMapped
    • applyICCProfileIfPresent

      protected boolean applyICCProfileIfPresent
    • bufferedImageSource

      protected com.pixelmed.display.SourceImage.BufferedImageSource bufferedImageSource
    • memoryMappedFileInputStream

      protected FileInputStream memoryMappedFileInputStream
    • memoryMappedFileChannel

      protected FileChannel memoryMappedFileChannel
    • memoryMappedFileInputStreams

      protected FileInputStream[] memoryMappedFileInputStreams
    • memoryMappedFileChannels

      protected FileChannel[] memoryMappedFileChannels
    • memoryMappedByteBuffers

      protected MappedByteBuffer[] memoryMappedByteBuffers
    • memoryMapperNumberOfRetries

      protected static int memoryMapperNumberOfRetries
    • memoryMapperSleepTimeBetweenRetries

      protected static int memoryMapperSleepTimeBetweenRetries
    • memoryMapperRetriesBeforeSleeping

      protected static int memoryMapperRetriesBeforeSleeping
  • Constructor Details

    • SourceImage

      protected SourceImage()

      Allow subclasses to have their own constructors.

    • SourceImage

      public SourceImage(InputStream i, int w, int h, int depth) throws IOException

      Construct a single-frame image from an unsigned raw image (no header) on an input stream with the specified width, height and bit depth.

      Parameters:
      i - the input stream
      w - image width
      h - image height
      depth - bit depth
      Throws:
      IOException
    • SourceImage

      public SourceImage(InputStream i, int w, int h, int depth, int frames) throws IOException

      Construct a multi-frame image from an unsigned raw image (no header) on an input stream with the specified width, height and bit depth.

      Parameters:
      i - the input stream
      w - image width
      h - image height
      depth - bit depth
      frames - number of frames
      Throws:
      IOException
    • SourceImage

      public SourceImage(String filename, boolean applyICCProfileIfPresent) throws IOException, DicomException

      Construct an image from a single or multi-frame DICOM image from a file.

      Parameters:
      filename -
      applyICCProfileIfPresent - whether or not to apply any ICC profile present in the attribute list
      Throws:
      IOException
      DicomException
    • SourceImage

      public SourceImage(String filename) throws IOException, DicomException

      Construct an image from a single or multi-frame DICOM image from a file.

      Applies any ICC Profile that is present.

      Parameters:
      filename -
      Throws:
      IOException
      DicomException
    • SourceImage

      public SourceImage(DicomInputStream i, boolean applyICCProfileIfPresent) throws IOException, DicomException

      Construct an image from a single or multi-frame DICOM image from an input stream (such as from a file or the network).

      Parameters:
      i - the input stream
      applyICCProfileIfPresent - whether or not to apply any ICC profile present in the attribute list
      Throws:
      IOException
      DicomException
    • SourceImage

      public SourceImage(DicomInputStream i) throws IOException, DicomException

      Construct an image from a single or multi-frame DICOM image from an input stream (such as from a file or the network).

      Applies any ICC Profile that is present.

      Parameters:
      i - the input stream
      Throws:
      IOException
      DicomException
    • SourceImage

      public SourceImage(AttributeList list, boolean applyICCProfileIfPresent) throws DicomException

      Construct an image from a single or multi-frame DICOM image from a list of DICOM attributes.

      If decompression was deferred during AttributeList read, take care not to remove the Transfer Syntax from the AttributeList until after deferred decompression.

      Parameters:
      list - the list of attributes that include the description and values of the pixel data
      applyICCProfileIfPresent - whether or not to apply any ICC profile present in the attribute list
      Throws:
      DicomException
    • SourceImage

      public SourceImage(AttributeList list) throws DicomException

      Construct an image from a single or multi-frame DICOM image from a list of DICOM attributes.

      If decompression was deferred during AttributeList read, take care not to remove the Transfer Syntax from the AttributeList until after deferred decompression.

      Applies any ICC Profile that is present.

      Parameters:
      list - the list of attributes that include the description and values of the pixel data
      Throws:
      DicomException
  • Method Details

    • setAllowMemoryMapping

      public static void setAllowMemoryMapping(boolean allowMemoryMapping)

      Static method to set whether or not to allow memory mapping to be used at all when subsequently constructing SourceImage objects from attributes whose pixel data has been left on disk rather than read or constructed in memory.

      Default is to allow memory mapping.

      Performance will generally be suprior with memory mapping turned on, and less heap will be used, but apparent issues with native memory allocation and revovery after a failed mapping on some platforms may require disabling it.

      Parameters:
      allowMemoryMapping - true or false to allow or disallow memory mapping, respectively
    • setAllowMemoryMappingFromMultiplePerFrameFiles

      public static void setAllowMemoryMappingFromMultiplePerFrameFiles(boolean allowMemoryMappingFromMultiplePerFrameFiles)

      Static method to set whether or not to allow memory mapping to be used in the special case that the images on disk have their frames spread across separate files rather than one large contiguous file.

      Default is to to disable memory mapping in this case.

      Parameters:
      allowMemoryMappingFromMultiplePerFrameFiles - true or false to allow or disallow memory mapping of per-frame files, respectively
    • setAllowDeferredReadFromFileIfNotMemoryMapped

      public static void setAllowDeferredReadFromFileIfNotMemoryMapped(boolean allowDeferredReadFromFileIfNotMemoryMapped)

      Static method to set whether or not to reading of per-frame data from a file to be deferred when subsequently constructing SourceImage objects from attributes whose pixel data has been left on disk rather than all frames to be read and constructed in memory.

      Does not apply if memory mapping is enabled and succeeds.

      Default is to to allow deferred reading.

      Reading of the pixel data for a frame (and allocation of memory for it) is deferred until SourceImage.getBufferedImage(int) is called.

      Parameters:
      allowDeferredReadFromFileIfNotMemoryMapped - true or false to allow or disallow deferred read of per-frame data from file, respectively
    • setClipRect

      public void setClipRect(int i, Rectangle clipRect)

      Set the rectanguler clipping region for the selected frame.

      Parameters:
      i - frame number (from 0)
    • createUnsignedShortGrayscaleImage

      public static BufferedImage createUnsignedShortGrayscaleImage(int w, int h, short[] data, int offset)
      Parameters:
      w -
      h -
      data -
      offset -
    • createSignedShortGrayscaleImage

      public static BufferedImage createSignedShortGrayscaleImage(int w, int h, short[] data, int offset)
      Parameters:
      w -
      h -
      data -
      offset -
    • createByteGrayscaleImage

      public static BufferedImage createByteGrayscaleImage(int w, int h, byte[] data, int offset)
      Parameters:
      w -
      h -
      data -
      offset -
    • createPixelInterleavedByteThreeComponentColorImage

      public static BufferedImage createPixelInterleavedByteThreeComponentColorImage(int w, int h, byte[] data, int offset, ColorSpace colorSpace, boolean isChrominanceHorizontallyDownsampledBy2)
      Parameters:
      w -
      h -
      data -
      offset -
    • createBandInterleavedByteThreeComponentColorImage

      public static BufferedImage createBandInterleavedByteThreeComponentColorImage(int w, int h, byte[] data, int offset, ColorSpace colorSpace)
      Parameters:
      w -
      h -
      data -
      offset -
    • createPixelInterleavedShortThreeComponentColorImage

      public static BufferedImage createPixelInterleavedShortThreeComponentColorImage(int w, int h, short[] data, int offset, ColorSpace colorSpace)
      Parameters:
      w -
      h -
      data -
      offset -
    • createBandInterleavedShortThreeComponentColorImage

      public static BufferedImage createBandInterleavedShortThreeComponentColorImage(int w, int h, short[] data, int offset, ColorSpace colorSpace)
      Parameters:
      w -
      h -
      data -
      offset -
    • createFloatGrayscaleImage

      public static BufferedImage createFloatGrayscaleImage(int w, int h, float[] data, int offset)
      Parameters:
      w -
      h -
      data -
      offset -
    • createDoubleGrayscaleImage

      public static BufferedImage createDoubleGrayscaleImage(int w, int h, double[] data, int offset)
      Parameters:
      w -
      h -
      data -
      offset -
    • clean

      protected static void clean(Object object) throws Exception
      Throws:
      Exception
    • close

      public void close() throws Throwable
      Throws:
      Throwable
    • finalize

      protected void finalize() throws Throwable
      Throws:
      Throwable
    • getByteBuffersFromOtherByteAttributeMultipleFilesOnDisk

      protected ByteBuffer[] getByteBuffersFromOtherByteAttributeMultipleFilesOnDisk(OtherByteAttributeMultipleFilesOnDisk oad, int nframes) throws DicomException, IOException, Throwable

      Get memory mapped file buffers for the specified attribute.

      Parameters:
      oad - the attribute on disk to memory map
      Returns:
      an array of byte buffers, one per frame
      Throws:
      DicomException - if cannot memory map file
      IOException - of cannot open file
      Throwable - if problem closing memory mapped file
    • getByteBuffersFromOtherAttributeOnDisk

      protected ByteBuffer[] getByteBuffersFromOtherAttributeOnDisk(OtherAttributeOnDisk oad, int nframes) throws DicomException, IOException, Throwable

      Get memory mapped file buffers for the specified attribute.

      Parameters:
      oad - the attribute on disk to memory map
      Returns:
      an array of byte buffers, one per frame
      Throws:
      DicomException - if cannot memory map file
      IOException - of cannot open file
      Throwable - if problem closing memory mapped file
    • getShortBuffersFromOtherWordAttributeOnDisk

      protected ShortBuffer[] getShortBuffersFromOtherWordAttributeOnDisk(OtherWordAttributeOnDisk oad, int nframes) throws DicomException, IOException, Throwable

      Get a memory mapped file buffer for value of the specified attribute.

      Parameters:
      oad - the attribute on disk to memory map
      nframes - the number of frames
      Returns:
      an array of short buffers
      Throws:
      DicomException - if cannot memory map file
      IOException - of cannot open file
      Throwable - if problem closing memory mapped file
    • getBufferedImage

      public BufferedImage getBufferedImage()

      Make a BufferedImage for the first or only frame.

      The BufferedImage will have the bit depth and photometric interpretation of the original SourceImage.

      If it is an RGB photometric interpretation, and an ICC profile is present, it will be applied.

      Returns:
      a BufferedImage for the first or only frame
    • getBufferedImage

      public BufferedImage getBufferedImage(boolean useICC)

      Make a BufferedImage for the first or only frame.

      The BufferedImage will have the bit depth and photometric interpretation of the original SourceImage.

      Parameters:
      useICC - if true, if image has an RGB photometric interpretation, and an ICC profile is present, it will be applied
      Returns:
      a BufferedImage for the first or only frame
    • getBufferedImage

      public BufferedImage getBufferedImage(int i)

      Make a BufferedImage for the selected frame.

      The BufferedImage will have the bit depth and photometric interpretation of the original SourceImage.

      If it is an RGB photometric interpretation, and an ICC profile is present, it will be applied.

      Parameters:
      i - frame number (from 0)
      Returns:
      a BufferedImage for the selected frame
    • getBufferedImage

      public BufferedImage getBufferedImage(int i, boolean useICC)

      Make a BufferedImage for the selected frame.

      The BufferedImage will have the bit depth and photometric interpretation of the original SourceImage.

      Parameters:
      i - frame number (from 0)
      useICC - if true, if image has an RGB photometric interpretation, and an ICC profile is present, it will be applied
      Returns:
      a BufferedImage for the selected frame
    • getNumberOfBufferedImages

      public int getNumberOfBufferedImages()
    • isImage

      public boolean isImage()
    • getWidth

      public int getWidth()
    • getHeight

      public int getHeight()
    • getDimension

      public Dimension getDimension()
    • getMinimum

      public double getMinimum()
      Returns:
      the minimum pixel value, excluding any pixels in the padding value range
    • getMaximum

      public double getMaximum()
      Returns:
      the maximum pixel value, excluding any pixels in the padding value range
    • getMaskValue

      public int getMaskValue()
    • isSigned

      public boolean isSigned()
    • isInverted

      public boolean isInverted()
    • isPadded

      public boolean isPadded()
    • getPadValue

      public int getPadValue()
    • getPadRangeLimit

      public int getPadRangeLimit()
    • getBackgroundValue

      public int getBackgroundValue()
    • isGrayscale

      public boolean isGrayscale()
    • isYBR

      public boolean isYBR()
    • getTitle

      public String getTitle()
    • getNumberOfFrames

      public int getNumberOfFrames()
    • getPaletteColorLargestGray

      public int getPaletteColorLargestGray()
    • getPaletteColorFirstValueMapped

      public int getPaletteColorFirstValueMapped()
    • getPaletteColorNumberOfEntries

      public int getPaletteColorNumberOfEntries()
    • getPaletteColorBitsPerEntry

      public int getPaletteColorBitsPerEntry()
    • getPaletteColorRedTable

      public short[] getPaletteColorRedTable()
    • getPaletteColorGreenTable

      public short[] getPaletteColorGreenTable()
    • getPaletteColorBlueTable

      public short[] getPaletteColorBlueTable()
    • getSUVTransform

      public SUVTransform getSUVTransform()
    • getRealWorldValueTransform

      public RealWorldValueTransform getRealWorldValueTransform()
    • getModalityTransform

      public ModalityTransform getModalityTransform()
    • getVOITransform

      public VOITransform getVOITransform()
    • getDisplayShutter

      public DisplayShutter getDisplayShutter()
    • getOverlay

      public Overlay getOverlay()