LookupTable.hpp 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. /***************************************************************************
  2. * E-Com Technology Ltd.
  3. *
  4. * ECOMPACS DICOM Network Transport Libraries * Version 0.1 Beta
  5. ***************************************************************************/
  6. #ifndef __IMAGE_LOOKUP_TABLE__
  7. #define __IMAGE_LOOKUP_TABLE__
  8. #pragma warning (disable : 4251)
  9. class RealImage;
  10. class DICOM_API LookupTable
  11. {
  12. public:
  13. Array <int> MinForkCalibArray;
  14. Array <int> MaxForkCalibArray;
  15. int MinForkCalib; // current min fork position (Calib value)
  16. int MaxForkCalib; // current max fork position (Calib value)
  17. BOOL BlackSaturated; // flag for black saturation
  18. // The current curve is supposed to be constant
  19. // between minSpaceCalib and minForkCalib and between
  20. // maxForkCalib and maxSpaceCalib and is varying
  21. // between minForkCalib and maxForkCalib.
  22. public:
  23. LookupTable ();
  24. LookupTable ( const LookupTable & LUT);
  25. LookupTable (int minSpaceRaw,
  26. int maxSpaceRaw,
  27. float offset,
  28. float slope,
  29. int wwCal, // window width
  30. int wlCal) // window level
  31. {
  32. Init (minSpaceRaw, maxSpaceRaw, offset, slope, wwCal, wlCal);
  33. }
  34. ~LookupTable ();
  35. public:
  36. void Init ( int minSpaceRaw,
  37. int maxSpaceRaw,
  38. float offset,
  39. float slope,
  40. int wwCal, // window width
  41. int wlCal); // window level
  42. void AddMinMaxFork (int minForkCal, int maxForkCal)
  43. {
  44. if (minForkCal < MinSpaceCalib) minForkCal = MinSpaceCalib;
  45. else
  46. if (minForkCal > MaxSpaceCalib) minForkCal = MaxSpaceCalib;
  47. if (maxForkCal < MinSpaceCalib) maxForkCal = MinSpaceCalib;
  48. else
  49. if (maxForkCal > MaxSpaceCalib) maxForkCal = MaxSpaceCalib;
  50. MinForkCalibArray.Add (minForkCal);
  51. MaxForkCalibArray.Add (maxForkCal);
  52. }
  53. void SetMinMaxFork (int minForkCal, int maxForkCal)
  54. {
  55. if (minForkCal < MinSpaceCalib) minForkCal = MinSpaceCalib;
  56. else
  57. if (minForkCal > MaxSpaceCalib) minForkCal = MaxSpaceCalib;
  58. if (maxForkCal < MinSpaceCalib) maxForkCal = MinSpaceCalib;
  59. else
  60. if (maxForkCal > MaxSpaceCalib) maxForkCal = MaxSpaceCalib;
  61. MinForkCalib = minForkCal;
  62. MaxForkCalib = maxForkCal;
  63. }
  64. int GetMinSpaceCalib () const { return MinSpaceCalib; }
  65. int GetMaxSpaceCalib () const { return MaxSpaceCalib; }
  66. int GetMinSpaceRaw () const { return MinSpaceRaw; }
  67. int GetMaxSpaceRaw () const { return MaxSpaceRaw; }
  68. int GetImageRangeRaw () const { return ImageRangeRaw; }
  69. float GetIntercept () const { return Intercept; }
  70. float GetSlope () const { return Slope; }
  71. //**************************************************************************
  72. // Purpose: Create and compute the color transformation table that
  73. // translates the real image values into the pixmap ones,
  74. // (first apply the min and max, then apply the curve then
  75. // convert it from 256 to 240 color levels).
  76. // The created transformation tab is returned as the result
  77. // of the method.
  78. //**************************************************************************
  79. BYTE * CreateLookupTable (int depth) const;
  80. BYTE * CreateLookupTableEx (int depth) const;
  81. //**************************************************************************
  82. // Name: ComputeCalibratedValue
  83. //
  84. // Purpose: Translates from screen value to calibrated value.
  85. //**************************************************************************
  86. int ComputeCalibratedValue (int screenValue) const
  87. {
  88. return (int) (((((float) (MaxSpaceRaw - MinSpaceRaw) *
  89. (float) (screenValue) / 255.0) +
  90. (float) MinSpaceRaw) * Slope) + Intercept);
  91. }
  92. //**************************************************************************
  93. // Name: ComputeScreenValue
  94. //
  95. // Purpose: Translates from calibrated value to screen value.
  96. //**************************************************************************
  97. int ComputeScreenValue (int calibratedValue) const
  98. {
  99. return (int) (((( (float) calibratedValue - Intercept) / Slope) -
  100. (float) MinSpaceRaw) * 255.0 /
  101. (float) (MaxSpaceRaw - MinSpaceRaw + 1));
  102. }
  103. //**************************************************************************
  104. // Name: FromRawToCalibrated
  105. //
  106. // Purpose: Translates from raw value to calibrated one.
  107. //**************************************************************************
  108. int FromRawToCalibrated (int Raw) const
  109. {
  110. return (int) (((float) Raw * Slope) + Intercept);
  111. }
  112. //**************************************************************************
  113. // Name: FromCalibratedToRaw
  114. //
  115. // Purpose: Translates from Calibrated value to raw one.
  116. //**************************************************************************
  117. int FromCalibratedToRaw (int Cal) const
  118. {
  119. return (int) (((float) Cal - Intercept) / Slope);
  120. }
  121. private:
  122. RealImage * RealImage;
  123. int MaxSpaceCalib; // maximum intensity of the image (Calib value)
  124. int MinSpaceCalib; // minimum intensity of the image (Calib value)
  125. int MaxSpaceRaw; // maximum intensity of the image (Raw value)
  126. int MinSpaceRaw; // minimum intensity of the image (Raw value)
  127. int MinSpaceSet; // min pixel value of the set of images
  128. int MaxSpaceSet; // max pixel value of the set of images
  129. int ImageRangeRaw; // the image dynamic
  130. float Intercept; // offset for the real pixel values
  131. float Slope; // factor for real pixel slope
  132. private:
  133. friend class ImageProcess;
  134. friend class DICOMImage;
  135. friend class RealImage;
  136. friend class RealImage8;
  137. friend class RealImage16;
  138. friend class RealImageRGB;
  139. };
  140. #endif