ColorDataPoint.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Drawing;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. namespace SHJX.Service.Common.Camera
  8. {
  9. public class ColorDataPoint
  10. {
  11. #region protected
  12. /// <summary>
  13. /// 单点颜色
  14. /// </summary>
  15. protected Color PointColor { get; set; }
  16. protected void UpdatePoint()
  17. {
  18. PointColor = Color.FromArgb(
  19. Convert.ToInt32(RTV / Area),
  20. Convert.ToInt32(GTV / Area),
  21. Convert.ToInt32(BTV / Area));
  22. }
  23. #endregion
  24. #region properties
  25. /// <summary>
  26. /// 序号
  27. /// </summary>
  28. public int Id { get; set; }
  29. /// <summary>
  30. /// 区域R总量
  31. /// </summary>
  32. public double RTV { get; set; }
  33. /// <summary>
  34. /// 区域G总量
  35. /// </summary>
  36. public double GTV { get; set; }
  37. /// <summary>
  38. /// 区域B总量
  39. /// </summary>
  40. public double BTV { get; set; }
  41. /// <summary>
  42. /// 区域面积
  43. /// </summary>
  44. public double Area { get; set; }
  45. /// <summary>
  46. /// 小数点后位数
  47. /// </summary>
  48. public int FloatCount { get; set; }
  49. #endregion
  50. #region methods
  51. public ColorDataPoint(int id = 1, double rtv = 1, double gtv = 1, double btv = 1, double area = 1, int floatcount = 2)
  52. {
  53. Id = id;
  54. RTV = rtv;
  55. GTV = gtv;
  56. BTV = btv;
  57. Area = area;
  58. FloatCount = floatcount;
  59. UpdatePoint();
  60. }
  61. /// <summary>
  62. /// 返回单点R平均值
  63. /// </summary>
  64. /// <returns></returns>
  65. public double GetRSV()
  66. {
  67. double ret = Math.Round(RTV / Area, FloatCount);
  68. return ret;
  69. }
  70. /// <summary>
  71. /// 返回单点G平均值
  72. /// </summary>
  73. /// <returns></returns>
  74. public double GetGSV()
  75. {
  76. double ret = Math.Round(GTV / Area, FloatCount);
  77. return ret;
  78. }
  79. /// <summary>
  80. /// 返回单点B平均值
  81. /// </summary>
  82. /// <returns></returns>
  83. public double GetBSV()
  84. {
  85. double ret = Math.Round(BTV / Area, FloatCount);
  86. return ret;
  87. }
  88. /// <summary>
  89. /// 返回HSB色调值
  90. /// </summary>
  91. /// <returns></returns>
  92. public double GetHue()
  93. {
  94. this.UpdatePoint();
  95. return Math.Round(this.PointColor.GetHue(), FloatCount);
  96. }
  97. /// <summary>
  98. /// 返回HSB饱和度值
  99. /// </summary>
  100. /// <returns></returns>
  101. public double GetSaturation()
  102. {
  103. return 1.0;
  104. #region MyRegion
  105. //#if true
  106. // UpdatePoint();
  107. // return Math.Round(this.PointColor.GetSaturation(), FloatCount);
  108. //#endif
  109. //#region MyRegion
  110. //this.UpdatePoint();
  111. //var vmax = Math.Max(this.GTV, Math.Max(this.RTV, this.BTV)) / this.Area;
  112. //var vmin = Math.Min(this.GTV, Math.Min(this.RTV, this.BTV)) / this.Area;
  113. //var sat = Math.Max(1.0, Math.Round((vmax - vmin) / vmax * 100.0, 2));
  114. //return sat;
  115. //#endregion
  116. #endregion
  117. }
  118. /// <summary>
  119. /// 返回HSB亮度值
  120. /// </summary>
  121. /// <returns></returns>
  122. public double GetBrightness()
  123. {
  124. UpdatePoint();
  125. return Math.Round(this.PointColor.GetBrightness(), FloatCount);
  126. }
  127. #endregion
  128. }
  129. }