OFFIS DCMTK  Version 3.6.0
diqtctab.h
1 /*
2  *
3  * Copyright (C) 2002-2010, OFFIS e.V.
4  * All rights reserved. See COPYRIGHT file for details.
5  *
6  * This software and supporting documentation were developed by
7  *
8  * OFFIS e.V.
9  * R&D Division Health
10  * Escherweg 2
11  * D-26121 Oldenburg, Germany
12  *
13  *
14  * Module: dcmimage
15  *
16  * Author: Marco Eichelberg
17  *
18  * Purpose: class DcmQuantColorTable
19  *
20  * Last Update: $Author: joergr $
21  * Update Date: $Date: 2010-10-14 13:16:29 $
22  * CVS/RCS Revision: $Revision: 1.7 $
23  * Status: $State: Exp $
24  *
25  * CVS/RCS Log at end of file
26  *
27  */
28 
29 
30 #ifndef DIQTCTAB_H
31 #define DIQTCTAB_H
32 
33 #include "dcmtk/config/osconfig.h"
34 #include "dcmtk/ofstd/oftypes.h" /* for OFBool */
35 #include "dcmtk/ofstd/ofcond.h" /* for OFCondition */
36 #include "dcmtk/dcmimage/diqtpix.h" /* for DcmQuantPixel */
37 #include "dcmtk/dcmimage/diqthash.h" /* for DcmQuantHistogramItem */
38 #include "dcmtk/ofstd/ofstring.h" /* for class OFString */
39 
40 
41 class DicomImage;
42 class DcmItem;
43 
44 
49 {
50 public:
51 
54 
57 
59  void clear();
60 
64  inline unsigned long getColors() const
65  {
66  return numColors;
67  }
68 
73  void setDescriptionString(OFString& str) const;
74 
84  OFCondition computeHistogram(DicomImage& image, unsigned long maxcolors);
85 
90  inline unsigned long getMaxVal() const
91  {
92  return maxval;
93  }
94 
99  inline const DcmQuantPixel& getPixel(unsigned long idx) const
100  {
101 #ifdef DEBUG
102  assert(array && idx < numColors);
103 #endif
104  return *(array[idx]);
105  }
106 
111  inline DcmQuantComponent getRed(unsigned long idx) const
112  {
113 #ifdef DEBUG
114  assert(array && idx < numColors);
115 #endif
116  return array[idx]->getRed();
117  }
118 
123  inline DcmQuantComponent getGreen(unsigned long idx) const
124  {
125 #ifdef DEBUG
126  assert(array && idx < numColors);
127 #endif
128  return array[idx]->getGreen();
129  }
130 
135  inline DcmQuantComponent getBlue(unsigned long idx) const
136  {
137 #ifdef DEBUG
138  assert(array && idx < numColors);
139 #endif
140  return array[idx]->getBlue();
141  }
142 
159  DcmQuantColorTable& histogram,
160  unsigned long sum,
161  unsigned long theMaxval,
162  unsigned long numberOfColors,
163  DcmLargestDimensionType largeType,
164  DcmRepresentativeColorType repType);
165 
170  inline int computeIndex(const DcmQuantPixel& px) const
171  {
172  int result = -1;
173  register int r2, g2, b2;
174  register long newdist;
175  register int r1 = OFstatic_cast(int, px.getRed());
176  register int g1 = OFstatic_cast(int, px.getGreen());
177  register int b1 = OFstatic_cast(int, px.getBlue());
178  register long dist = 2000000000;
179  for (unsigned long i = 0; i < numColors; ++i)
180  {
181  r2 = r1 - OFstatic_cast(int, array[i]->getRed());
182  g2 = g1 - OFstatic_cast(int, array[i]->getGreen());
183  b2 = b1 - OFstatic_cast(int, array[i]->getBlue());
184  newdist = r2*r2 + g2*g2 + b2*b2;
185  if (newdist < dist)
186  {
187  result = OFstatic_cast(int, i);
188  dist = newdist;
189  if (dist < array[i]->getValue()) i=numColors; // break out of for loop
190  }
191  }
192  return result;
193  }
194 
205  DcmItem& target,
206  OFBool writeAsOW,
207  OFBool write16BitEntries);
208 
209 
210 private:
211 
218  void computeClusters();
219 
222 
225 
228 
230  unsigned long numColors;
231 
235  unsigned long maxval;
236 
237 };
238 
239 #endif
240 
241 
242 /*
243  * CVS/RCS Log:
244  * $Log: diqtctab.h,v $
245  * Revision 1.7 2010-10-14 13:16:29 joergr
246  * Updated copyright header. Added reference to COPYRIGHT file.
247  *
248  * Revision 1.6 2005/12/08 16:01:45 meichel
249  * Changed include path schema for all DCMTK header files
250  *
251  * Revision 1.5 2003/12/23 12:15:40 joergr
252  * Adapted type casts to new-style typecast operators defined in ofcast.h.
253  * Updated copyright header.
254  *
255  * Revision 1.4 2003/07/04 13:25:40 meichel
256  * Replaced forward declarations for OFString with explicit includes,
257  * needed when compiling with HAVE_STD_STRING
258  *
259  * Revision 1.3 2003/06/12 15:09:41 joergr
260  * Fixed inconsistent API documentation reported by Doxygen.
261  *
262  * Revision 1.2 2002/05/15 09:53:29 meichel
263  * Minor corrections to avoid warnings on Sun CC 2.0.1
264  *
265  * Revision 1.1 2002/01/25 13:32:04 meichel
266  * Initial release of new color quantization classes and
267  * the dcmquant tool in module dcmimage.
268  *
269  *
270  */
a class representing a list of DICOM elements in which each element has a different tag and elements ...
Definition: dcitem.h:51
DcmQuantHistogramItemPointer * array
color table data
Definition: diqtctab.h:227
objects of this class represent individual RGB pixels.
Definition: diqtpix.h:44
const DcmQuantPixel & getPixel(unsigned long idx) const
returns the color at index idx.
Definition: diqtctab.h:99
DcmQuantComponent getGreen(unsigned long idx) const
returns the green color component at index idx
Definition: diqtctab.h:123
this class extends DcmQuantPixel by an integer value which is used for various purposes.
Definition: diqthitm.h:45
unsigned long numColors
number of entries in color table
Definition: diqtctab.h:230
this class implements a color table that can either be a look-up table or an image color histogram...
Definition: diqtctab.h:48
DcmQuantComponent getBlue() const
returns the blue component
Definition: diqtpix.h:115
DcmQuantComponent getBlue(unsigned long idx) const
returns the blue color component at index idx
Definition: diqtctab.h:135
void clear()
resets the object to default-constructed state
DcmQuantComponent getRed(unsigned long idx) const
returns the red color component at index idx
Definition: diqtctab.h:111
unsigned long getColors() const
returns the number of colors in the color table
Definition: diqtctab.h:64
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.
unsigned long maxval
maximum pixel value to which all color samples were down-sampled during computation of the histogram...
Definition: diqtctab.h:235
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 Ta...
unsigned long getMaxVal() const
after a call to computeHistogram(), this method returns the maximum pixel value to which all color sa...
Definition: diqtctab.h:90
void setDescriptionString(OFString &str) const
creates a description string suitable for use as Derivation Description.
DcmQuantComponent getGreen() const
returns the green component
Definition: diqtpix.h:107
int computeIndex(const DcmQuantPixel &px) const
determines for a given color the closest match in the color LUT.
Definition: diqtctab.h:170
~DcmQuantColorTable()
destructor
DcmQuantComponent getRed() const
returns the red component
Definition: diqtpix.h:99
DcmQuantColorTable()
constructor
Interface class for dcmimgle/dcmimage module.
Definition: dcmimage.h:64
DcmQuantColorTable & operator=(const DcmQuantColorTable &src)
private undefined copy assignment operator
void computeClusters()
after a call to medianCut(), this method computes for each entry in the color map the minimum of the ...
a simple string class that implements a subset of std::string.
Definition: ofstring.h:86
OFCondition computeHistogram(DicomImage &image, unsigned long maxcolors)
creates a color table containing a histogram of the given image.
General purpose class for condition codes.
Definition: ofcond.h:305


Generated on Wed Jan 4 2017 for OFFIS DCMTK Version 3.6.0 by Doxygen 1.8.6