00001 /* 00002 * 00003 * Copyright (C) 2002-2010, OFFIS e.V. 00004 * All rights reserved. See COPYRIGHT file for details. 00005 * 00006 * This software and supporting documentation were developed by 00007 * 00008 * OFFIS e.V. 00009 * R&D Division Health 00010 * Escherweg 2 00011 * D-26121 Oldenburg, Germany 00012 * 00013 * 00014 * Module: dcmimage 00015 * 00016 * Author: Marco Eichelberg 00017 * 00018 * Purpose: class DcmQuantColorTable 00019 * 00020 * Last Update: $Author: joergr $ 00021 * Update Date: $Date: 2010-10-14 13:16:29 $ 00022 * CVS/RCS Revision: $Revision: 1.7 $ 00023 * Status: $State: Exp $ 00024 * 00025 * CVS/RCS Log at end of file 00026 * 00027 */ 00028 00029 00030 #ifndef DIQTCTAB_H 00031 #define DIQTCTAB_H 00032 00033 #include "dcmtk/config/osconfig.h" 00034 #include "dcmtk/ofstd/oftypes.h" /* for OFBool */ 00035 #include "dcmtk/ofstd/ofcond.h" /* for OFCondition */ 00036 #include "dcmtk/dcmimage/diqtpix.h" /* for DcmQuantPixel */ 00037 #include "dcmtk/dcmimage/diqthash.h" /* for DcmQuantHistogramItem */ 00038 #include "dcmtk/ofstd/ofstring.h" /* for class OFString */ 00039 00040 00041 class DicomImage; 00042 class DcmItem; 00043 00044 00048 class DcmQuantColorTable 00049 { 00050 public: 00051 00053 DcmQuantColorTable(); 00054 00056 ~DcmQuantColorTable(); 00057 00059 void clear(); 00060 00064 inline unsigned long getColors() const 00065 { 00066 return numColors; 00067 } 00068 00073 void setDescriptionString(OFString& str) const; 00074 00084 OFCondition computeHistogram(DicomImage& image, unsigned long maxcolors); 00085 00090 inline unsigned long getMaxVal() const 00091 { 00092 return maxval; 00093 } 00094 00099 inline const DcmQuantPixel& getPixel(unsigned long idx) const 00100 { 00101 #ifdef DEBUG 00102 assert(array && idx < numColors); 00103 #endif 00104 return *(array[idx]); 00105 } 00106 00111 inline DcmQuantComponent getRed(unsigned long idx) const 00112 { 00113 #ifdef DEBUG 00114 assert(array && idx < numColors); 00115 #endif 00116 return array[idx]->getRed(); 00117 } 00118 00123 inline DcmQuantComponent getGreen(unsigned long idx) const 00124 { 00125 #ifdef DEBUG 00126 assert(array && idx < numColors); 00127 #endif 00128 return array[idx]->getGreen(); 00129 } 00130 00135 inline DcmQuantComponent getBlue(unsigned long idx) const 00136 { 00137 #ifdef DEBUG 00138 assert(array && idx < numColors); 00139 #endif 00140 return array[idx]->getBlue(); 00141 } 00142 00158 OFCondition medianCut( 00159 DcmQuantColorTable& histogram, 00160 unsigned long sum, 00161 unsigned long theMaxval, 00162 unsigned long numberOfColors, 00163 DcmLargestDimensionType largeType, 00164 DcmRepresentativeColorType repType); 00165 00170 inline int computeIndex(const DcmQuantPixel& px) const 00171 { 00172 int result = -1; 00173 register int r2, g2, b2; 00174 register long newdist; 00175 register int r1 = OFstatic_cast(int, px.getRed()); 00176 register int g1 = OFstatic_cast(int, px.getGreen()); 00177 register int b1 = OFstatic_cast(int, px.getBlue()); 00178 register long dist = 2000000000; 00179 for (unsigned long i = 0; i < numColors; ++i) 00180 { 00181 r2 = r1 - OFstatic_cast(int, array[i]->getRed()); 00182 g2 = g1 - OFstatic_cast(int, array[i]->getGreen()); 00183 b2 = b1 - OFstatic_cast(int, array[i]->getBlue()); 00184 newdist = r2*r2 + g2*g2 + b2*b2; 00185 if (newdist < dist) 00186 { 00187 result = OFstatic_cast(int, i); 00188 dist = newdist; 00189 if (dist < array[i]->getValue()) i=numColors; // break out of for loop 00190 } 00191 } 00192 return result; 00193 } 00194 00204 OFCondition write( 00205 DcmItem& target, 00206 OFBool writeAsOW, 00207 OFBool write16BitEntries); 00208 00209 00210 private: 00211 00218 void computeClusters(); 00219 00221 DcmQuantColorTable(const DcmQuantColorTable& src); 00222 00224 DcmQuantColorTable& operator=(const DcmQuantColorTable& src); 00225 00227 DcmQuantHistogramItemPointer *array; 00228 00230 unsigned long numColors; 00231 00235 unsigned long maxval; 00236 00237 }; 00238 00239 #endif 00240 00241 00242 /* 00243 * CVS/RCS Log: 00244 * $Log: diqtctab.h,v $ 00245 * Revision 1.7 2010-10-14 13:16:29 joergr 00246 * Updated copyright header. Added reference to COPYRIGHT file. 00247 * 00248 * Revision 1.6 2005/12/08 16:01:45 meichel 00249 * Changed include path schema for all DCMTK header files 00250 * 00251 * Revision 1.5 2003/12/23 12:15:40 joergr 00252 * Adapted type casts to new-style typecast operators defined in ofcast.h. 00253 * Updated copyright header. 00254 * 00255 * Revision 1.4 2003/07/04 13:25:40 meichel 00256 * Replaced forward declarations for OFString with explicit includes, 00257 * needed when compiling with HAVE_STD_STRING 00258 * 00259 * Revision 1.3 2003/06/12 15:09:41 joergr 00260 * Fixed inconsistent API documentation reported by Doxygen. 00261 * 00262 * Revision 1.2 2002/05/15 09:53:29 meichel 00263 * Minor corrections to avoid warnings on Sun CC 2.0.1 00264 * 00265 * Revision 1.1 2002/01/25 13:32:04 meichel 00266 * Initial release of new color quantization classes and 00267 * the dcmquant tool in module dcmimage. 00268 * 00269 * 00270 */