DCMTK Version 3.6.8
OFFIS DICOM Toolkit
Public Member Functions | Private Member Functions | Private Attributes | List of all members
DcmQuantColorTable Class Reference

this class implements a color table that can either be a look-up table or an image color histogram. More...

Public Member Functions

 DcmQuantColorTable ()
 constructor
 
 ~DcmQuantColorTable ()
 destructor
 
void clear ()
 resets the object to default-constructed state
 
unsigned long getColors () const
 returns the number of colors in the color table More...
 
void setDescriptionString (OFString &str) const
 creates a description string suitable for use as Derivation Description. More...
 
OFCondition computeHistogram (DicomImage &image, unsigned long maxcolors)
 creates a color table containing a histogram of the given image. More...
 
unsigned long getMaxVal () const
 after a call to computeHistogram(), this method returns the maximum pixel value to which all color samples were down-sampled during computation of the histogram.
 
const DcmQuantPixelgetPixel (unsigned long idx) const
 returns the color at index idx. More...
 
DcmQuantComponent getRed (unsigned long idx) const
 returns the red color component at index idx More...
 
DcmQuantComponent getGreen (unsigned long idx) const
 returns the green color component at index idx More...
 
DcmQuantComponent getBlue (unsigned long idx) const
 returns the blue color component at index idx More...
 
OFCondition medianCut (DcmQuantColorTable &histogram, unsigned long sum, unsigned long theMaxval, unsigned long numberOfColors, DcmLargestDimensionType largeType, DcmRepresentativeColorType repType)
 computes a color LUT for the given image histogram. More...
 
int computeIndex (const DcmQuantPixel &px) const
 determines for a given color the closest match in the color LUT. More...
 
OFCondition write (DcmItem &target, OFBool writeAsOW, OFBool write16BitEntries)
 writes the current color table into a DICOM object, encoded as Red/Green/Blue Palette Color Lookup Table and Data. More...
 

Private Member Functions

void computeClusters ()
 after a call to medianCut(), this method computes for each entry in the color map the minimum of the euclidean distances to any other of the entries. More...
 
 DcmQuantColorTable (const DcmQuantColorTable &src)
 private undefined copy constructor
 
DcmQuantColorTableoperator= (const DcmQuantColorTable &src)
 private undefined copy assignment operator
 

Private Attributes

DcmQuantHistogramItemPointerarray
 color table data
 
unsigned long numColors
 number of entries in color table
 
unsigned long maxval
 maximum pixel value to which all color samples were down-sampled during computation of the histogram.
 

Detailed Description

this class implements a color table that can either be a look-up table or an image color histogram.

Member Function Documentation

◆ computeClusters()

void DcmQuantColorTable::computeClusters ( )
private

after a call to medianCut(), this method computes for each entry in the color map the minimum of the euclidean distances to any other of the entries.

Any color which has an euclidean distance of less than half of this distance is necessarily mapped to this entry. This data is used by computeIndex()

◆ computeHistogram()

OFCondition DcmQuantColorTable::computeHistogram ( DicomImage image,
unsigned long  maxcolors 
)

creates a color table containing a histogram of the given image.

Pixel sample values are downsampled if necessary to make sure the histogram fits into the given size limit.

Parameters
imagecolor image for which a histogram is computed
maxcolorsmaximum number of colors allowed in histogram. If necessary, pixel sample values are down-sampled to enforce this maximum.
Returns
EC_Normal if successful, an error code otherwise.

◆ computeIndex()

int DcmQuantColorTable::computeIndex ( const DcmQuantPixel px) const
inline

determines for a given color the closest match in the color LUT.

Parameters
pxcolor to look up in LUT
Returns
index of closest match in LUT, -1 if look-up table empty

References DcmQuantPixel::getBlue(), DcmQuantPixel::getGreen(), and DcmQuantPixel::getRed().

Referenced by DcmQuantColorMapping< T1, T2 >::create().

◆ getBlue()

DcmQuantComponent DcmQuantColorTable::getBlue ( unsigned long  idx) const
inline

returns the blue color component at index idx

Parameters
idxindex, must be < getColors()
Returns
blue color component

◆ getColors()

unsigned long DcmQuantColorTable::getColors ( ) const
inline

returns the number of colors in the color table

Returns
number of colors in color table

◆ getGreen()

DcmQuantComponent DcmQuantColorTable::getGreen ( unsigned long  idx) const
inline

returns the green color component at index idx

Parameters
idxindex, must be < getColors()
Returns
green color component

◆ getPixel()

const DcmQuantPixel & DcmQuantColorTable::getPixel ( unsigned long  idx) const
inline

returns the color at index idx.

Parameters
idxindex, must be < getColors()
Returns
const reference to color

Referenced by DcmQuantColorMapping< T1, T2 >::create().

◆ getRed()

DcmQuantComponent DcmQuantColorTable::getRed ( unsigned long  idx) const
inline

returns the red color component at index idx

Parameters
idxindex, must be < getColors()
Returns
red color component

◆ medianCut()

OFCondition DcmQuantColorTable::medianCut ( DcmQuantColorTable histogram,
unsigned long  sum,
unsigned long  theMaxval,
unsigned long  numberOfColors,
DcmLargestDimensionType  largeType,
DcmRepresentativeColorType  repType 
)

computes a color LUT for the given image histogram.

This median-cut colormap generator is based on Paul Heckbert's paper "Color Image Quantization for Frame Buffer Display", SIGGRAPH '82 Proceedings, page 297.

Parameters
histogramimage color histogram
sumnumber of pixels in image (columns * rows * frames)
theMaxvalmaximum value to which pixels were downsampled for histogram computation
numberOfColorsdesired number of colors in color LUT
largeTypealgorithm used for determining the largest dimension in the Median Cut algorithm
repTypealgorithm for choosing a representative color for each box in the Median Cut algorithm
Returns
EC_Normal if successful, an error code otherwise.

◆ setDescriptionString()

void DcmQuantColorTable::setDescriptionString ( OFString str) const

creates a description string suitable for use as Derivation Description.

Parameters
strdescription string returned in this parameter

◆ write()

OFCondition DcmQuantColorTable::write ( DcmItem target,
OFBool  writeAsOW,
OFBool  write16BitEntries 
)

writes the current color table into a DICOM object, encoded as Red/Green/Blue Palette Color Lookup Table and Data.

Parameters
targetDICOM dataset to write to
writeAsOWif true, LUT data is encoded as OW, otherwise LUT data is encoded as US. A LUT with 64k entries is always encoded as OW since a US data element with 64k entries cannot be written in explicit VR.
write16BitEntriesif true, LUT data is encoded with 16 bits per entry
Returns
EC_Normal if successful, an error code otherwise.

The documentation for this class was generated from the following file:


Generated on Tue Dec 19 2023 for DCMTK Version 3.6.8 by Doxygen 1.9.4