CLAHE.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. using OpenCVForUnity.CoreModule;
  2. using OpenCVForUnity.UtilsModule;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Runtime.InteropServices;
  6. namespace OpenCVForUnity.ImgprocModule
  7. {
  8. // C++: class CLAHE
  9. /**
  10. * Base class for Contrast Limited Adaptive Histogram Equalization.
  11. */
  12. public class CLAHE : Algorithm
  13. {
  14. protected override void Dispose(bool disposing)
  15. {
  16. try
  17. {
  18. if (disposing)
  19. {
  20. }
  21. if (IsEnabledDispose)
  22. {
  23. if (nativeObj != IntPtr.Zero)
  24. imgproc_CLAHE_delete(nativeObj);
  25. nativeObj = IntPtr.Zero;
  26. }
  27. }
  28. finally
  29. {
  30. base.Dispose(disposing);
  31. }
  32. }
  33. protected internal CLAHE(IntPtr addr) : base(addr) { }
  34. // internal usage only
  35. public static new CLAHE __fromPtr__(IntPtr addr) { return new CLAHE(addr); }
  36. //
  37. // C++: void cv::CLAHE::apply(Mat src, Mat& dst)
  38. //
  39. /**
  40. * Equalizes the histogram of a grayscale image using Contrast Limited Adaptive Histogram Equalization.
  41. *
  42. * param src Source image of type CV_8UC1 or CV_16UC1.
  43. * param dst Destination image.
  44. */
  45. public void apply(Mat src, Mat dst)
  46. {
  47. ThrowIfDisposed();
  48. if (src != null) src.ThrowIfDisposed();
  49. if (dst != null) dst.ThrowIfDisposed();
  50. imgproc_CLAHE_apply_10(nativeObj, src.nativeObj, dst.nativeObj);
  51. }
  52. //
  53. // C++: void cv::CLAHE::setClipLimit(double clipLimit)
  54. //
  55. /**
  56. * Sets threshold for contrast limiting.
  57. *
  58. * param clipLimit threshold value.
  59. */
  60. public void setClipLimit(double clipLimit)
  61. {
  62. ThrowIfDisposed();
  63. imgproc_CLAHE_setClipLimit_10(nativeObj, clipLimit);
  64. }
  65. //
  66. // C++: double cv::CLAHE::getClipLimit()
  67. //
  68. public double getClipLimit()
  69. {
  70. ThrowIfDisposed();
  71. return imgproc_CLAHE_getClipLimit_10(nativeObj);
  72. }
  73. //
  74. // C++: void cv::CLAHE::setTilesGridSize(Size tileGridSize)
  75. //
  76. /**
  77. * Sets size of grid for histogram equalization. Input image will be divided into
  78. * equally sized rectangular tiles.
  79. *
  80. * param tileGridSize defines the number of tiles in row and column.
  81. */
  82. public void setTilesGridSize(Size tileGridSize)
  83. {
  84. ThrowIfDisposed();
  85. imgproc_CLAHE_setTilesGridSize_10(nativeObj, tileGridSize.width, tileGridSize.height);
  86. }
  87. //
  88. // C++: Size cv::CLAHE::getTilesGridSize()
  89. //
  90. public Size getTilesGridSize()
  91. {
  92. ThrowIfDisposed();
  93. double[] tmpArray = new double[2];
  94. imgproc_CLAHE_getTilesGridSize_10(nativeObj, tmpArray);
  95. Size retVal = new Size(tmpArray);
  96. return retVal;
  97. }
  98. //
  99. // C++: void cv::CLAHE::collectGarbage()
  100. //
  101. public void collectGarbage()
  102. {
  103. ThrowIfDisposed();
  104. imgproc_CLAHE_collectGarbage_10(nativeObj);
  105. }
  106. #if (UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR
  107. const string LIBNAME = "__Internal";
  108. #else
  109. const string LIBNAME = "opencvforunity";
  110. #endif
  111. // C++: void cv::CLAHE::apply(Mat src, Mat& dst)
  112. [DllImport(LIBNAME)]
  113. private static extern void imgproc_CLAHE_apply_10(IntPtr nativeObj, IntPtr src_nativeObj, IntPtr dst_nativeObj);
  114. // C++: void cv::CLAHE::setClipLimit(double clipLimit)
  115. [DllImport(LIBNAME)]
  116. private static extern void imgproc_CLAHE_setClipLimit_10(IntPtr nativeObj, double clipLimit);
  117. // C++: double cv::CLAHE::getClipLimit()
  118. [DllImport(LIBNAME)]
  119. private static extern double imgproc_CLAHE_getClipLimit_10(IntPtr nativeObj);
  120. // C++: void cv::CLAHE::setTilesGridSize(Size tileGridSize)
  121. [DllImport(LIBNAME)]
  122. private static extern void imgproc_CLAHE_setTilesGridSize_10(IntPtr nativeObj, double tileGridSize_width, double tileGridSize_height);
  123. // C++: Size cv::CLAHE::getTilesGridSize()
  124. [DllImport(LIBNAME)]
  125. private static extern void imgproc_CLAHE_getTilesGridSize_10(IntPtr nativeObj, double[] retVal);
  126. // C++: void cv::CLAHE::collectGarbage()
  127. [DllImport(LIBNAME)]
  128. private static extern void imgproc_CLAHE_collectGarbage_10(IntPtr nativeObj);
  129. // native support for java finalize()
  130. [DllImport(LIBNAME)]
  131. private static extern void imgproc_CLAHE_delete(IntPtr nativeObj);
  132. }
  133. }