Class SourceImage
- Direct Known Subclasses:
SourceImageSubset
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 Summary
FieldsModifier and TypeFieldDescriptionprotected static boolean
protected static boolean
protected static boolean
protected boolean
protected com.pixelmed.display.SourceImage.BufferedImageSource
protected MappedByteBuffer[]
protected FileChannel
protected FileChannel[]
protected FileInputStream
protected FileInputStream[]
protected static int
protected static int
protected static int
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
Allow subclasses to have their own constructors.SourceImage
(AttributeList list) Construct an image from a single or multi-frame DICOM image from a list of DICOM attributes.SourceImage
(AttributeList list, boolean applyICCProfileIfPresent) Construct an image from a single or multi-frame DICOM image from a list of DICOM attributes.Construct an image from a single or multi-frame DICOM image from an input stream (such as from a file or the network).SourceImage
(DicomInputStream i, boolean applyICCProfileIfPresent) Construct an image from a single or multi-frame DICOM image from an input stream (such as from a file or the network).SourceImage
(InputStream i, int w, int h, int depth) Construct a single-frame image from an unsigned raw image (no header) on an input stream with the specified width, height and bit depth.SourceImage
(InputStream i, int w, int h, int depth, int frames) Construct a multi-frame image from an unsigned raw image (no header) on an input stream with the specified width, height and bit depth.SourceImage
(String filename) Construct an image from a single or multi-frame DICOM image from a file.SourceImage
(String filename, boolean applyICCProfileIfPresent) Construct an image from a single or multi-frame DICOM image from a file. -
Method Summary
Modifier and TypeMethodDescriptionprotected static void
void
close()
static BufferedImage
createBandInterleavedByteThreeComponentColorImage
(int w, int h, byte[] data, int offset, ColorSpace colorSpace) static BufferedImage
createBandInterleavedShortThreeComponentColorImage
(int w, int h, short[] data, int offset, ColorSpace colorSpace) static BufferedImage
createByteGrayscaleImage
(int w, int h, byte[] data, int offset) static BufferedImage
createDoubleGrayscaleImage
(int w, int h, double[] data, int offset) static BufferedImage
createFloatGrayscaleImage
(int w, int h, float[] data, int offset) static BufferedImage
createPixelInterleavedByteThreeComponentColorImage
(int w, int h, byte[] data, int offset, ColorSpace colorSpace, boolean isChrominanceHorizontallyDownsampledBy2) static BufferedImage
createPixelInterleavedShortThreeComponentColorImage
(int w, int h, short[] data, int offset, ColorSpace colorSpace) static BufferedImage
createSignedShortGrayscaleImage
(int w, int h, short[] data, int offset) static BufferedImage
createUnsignedShortGrayscaleImage
(int w, int h, short[] data, int offset) protected void
finalize()
int
Make a BufferedImage for the first or only frame.getBufferedImage
(boolean useICC) Make a BufferedImage for the first or only frame.getBufferedImage
(int i) Make a BufferedImage for the selected frame.getBufferedImage
(int i, boolean useICC) Make a BufferedImage for the selected frame.protected ByteBuffer[]
getByteBuffersFromOtherAttributeOnDisk
(OtherAttributeOnDisk oad, int nframes) Get memory mapped file buffers for the specified attribute.protected ByteBuffer[]
getByteBuffersFromOtherByteAttributeMultipleFilesOnDisk
(OtherByteAttributeMultipleFilesOnDisk oad, int nframes) Get memory mapped file buffers for the specified attribute.int
int
double
double
int
int
int
int
int
short[]
int
short[]
int
int
short[]
protected ShortBuffer[]
getShortBuffersFromOtherWordAttributeOnDisk
(OtherWordAttributeOnDisk oad, int nframes) Get a memory mapped file buffer for value of the specified attribute.getTitle()
int
getWidth()
boolean
boolean
isImage()
boolean
boolean
isPadded()
boolean
isSigned()
boolean
isYBR()
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.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.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.void
setClipRect
(int i, Rectangle clipRect) Set the rectanguler clipping region for the selected frame.
-
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
-
memoryMappedFileChannel
-
memoryMappedFileInputStreams
-
memoryMappedFileChannels
-
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
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 streamw
- image widthh
- image heightdepth
- bit depth- Throws:
IOException
-
SourceImage
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 streamw
- image widthh
- image heightdepth
- bit depthframes
- 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
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 streamapplyICCProfileIfPresent
- whether or not to apply any ICC profile present in the attribute list- Throws:
IOException
DicomException
-
SourceImage
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
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 dataapplyICCProfileIfPresent
- whether or not to apply any ICC profile present in the attribute list- Throws:
DicomException
-
SourceImage
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
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
- Parameters:
w
-h
-data
-offset
-
-
createByteGrayscaleImage
- 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
- Parameters:
w
-h
-data
-offset
-
-
createDoubleGrayscaleImage
- Parameters:
w
-h
-data
-offset
-
-
clean
- Throws:
Exception
-
close
- Throws:
Throwable
-
finalize
- 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 fileIOException
- of cannot open fileThrowable
- 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 fileIOException
- of cannot open fileThrowable
- 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 mapnframes
- the number of frames- Returns:
- an array of short buffers
- Throws:
DicomException
- if cannot memory map fileIOException
- of cannot open fileThrowable
- if problem closing memory mapped file
-
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
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
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
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
-
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
-
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
-
getRealWorldValueTransform
-
getModalityTransform
-
getVOITransform
-
getDisplayShutter
-
getOverlay
-