GrayworldWB.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. using OpenCVForUnity.CoreModule;
  2. using OpenCVForUnity.UtilsModule;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Runtime.InteropServices;
  6. namespace OpenCVForUnity.XphotoModule
  7. {
  8. // C++: class GrayworldWB
  9. /**
  10. * Gray-world white balance algorithm
  11. *
  12. * This algorithm scales the values of pixels based on a
  13. * gray-world assumption which states that the average of all channels
  14. * should result in a gray image.
  15. *
  16. * It adds a modification which thresholds pixels based on their
  17. * saturation value and only uses pixels below the provided threshold in
  18. * finding average pixel values.
  19. *
  20. * Saturation is calculated using the following for a 3-channel RGB image per
  21. * pixel I and is in the range [0, 1]:
  22. *
  23. * \( \texttt{Saturation} [I] = \frac{\textrm{max}(R,G,B) - \textrm{min}(R,G,B)
  24. * }{\textrm{max}(R,G,B)} \)
  25. *
  26. * A threshold of 1 means that all pixels are used to white-balance, while a
  27. * threshold of 0 means no pixels are used. Lower thresholds are useful in
  28. * white-balancing saturated images.
  29. *
  30. * Currently supports images of type REF: CV_8UC3 and REF: CV_16UC3.
  31. */
  32. public class GrayworldWB : WhiteBalancer
  33. {
  34. protected override void Dispose(bool disposing)
  35. {
  36. try
  37. {
  38. if (disposing)
  39. {
  40. }
  41. if (IsEnabledDispose)
  42. {
  43. if (nativeObj != IntPtr.Zero)
  44. xphoto_GrayworldWB_delete(nativeObj);
  45. nativeObj = IntPtr.Zero;
  46. }
  47. }
  48. finally
  49. {
  50. base.Dispose(disposing);
  51. }
  52. }
  53. protected internal GrayworldWB(IntPtr addr) : base(addr) { }
  54. // internal usage only
  55. public static new GrayworldWB __fromPtr__(IntPtr addr) { return new GrayworldWB(addr); }
  56. //
  57. // C++: float cv::xphoto::GrayworldWB::getSaturationThreshold()
  58. //
  59. /**
  60. * Maximum saturation for a pixel to be included in the
  61. * gray-world assumption
  62. * SEE: setSaturationThreshold
  63. * return automatically generated
  64. */
  65. public float getSaturationThreshold()
  66. {
  67. ThrowIfDisposed();
  68. return xphoto_GrayworldWB_getSaturationThreshold_10(nativeObj);
  69. }
  70. //
  71. // C++: void cv::xphoto::GrayworldWB::setSaturationThreshold(float val)
  72. //
  73. /**
  74. * getSaturationThreshold SEE: getSaturationThreshold
  75. * param val automatically generated
  76. */
  77. public void setSaturationThreshold(float val)
  78. {
  79. ThrowIfDisposed();
  80. xphoto_GrayworldWB_setSaturationThreshold_10(nativeObj, val);
  81. }
  82. #if (UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR
  83. const string LIBNAME = "__Internal";
  84. #else
  85. const string LIBNAME = "opencvforunity";
  86. #endif
  87. // C++: float cv::xphoto::GrayworldWB::getSaturationThreshold()
  88. [DllImport(LIBNAME)]
  89. private static extern float xphoto_GrayworldWB_getSaturationThreshold_10(IntPtr nativeObj);
  90. // C++: void cv::xphoto::GrayworldWB::setSaturationThreshold(float val)
  91. [DllImport(LIBNAME)]
  92. private static extern void xphoto_GrayworldWB_setSaturationThreshold_10(IntPtr nativeObj, float val);
  93. // native support for java finalize()
  94. [DllImport(LIBNAME)]
  95. private static extern void xphoto_GrayworldWB_delete(IntPtr nativeObj);
  96. }
  97. }