| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- using System;
- using System.Drawing;
- namespace shjxCamera
- {
- public class ColorData2Point
- {
- #region protected
- /// <summary>
- /// 单点颜色
- /// </summary>
- protected Color PointColor { get; set; }
- protected void UpdatePoint()
- {
- PointColor = Color.FromArgb(Convert.ToInt32(RTV / Area), Convert.ToInt32(GTV / Area), Convert.ToInt32(BTV / Area));
- }
- #endregion
- #region properties
- /// <summary>
- /// 序号
- /// </summary>
- public int Id { get; set; }
- /// <summary>
- /// 区域R总量
- /// </summary>
- public double RTV { get; set; }
- /// <summary>
- /// 区域G总量
- /// </summary>
- public double GTV { get; set; }
- /// <summary>
- /// 区域B总量
- /// </summary>
- public double BTV { get; set; }
- /// <summary>
- /// 区域面积
- /// </summary>
- public double Area { get; set; }
- /// <summary>
- /// 小数点后位数
- /// </summary>
- public int FloatCount { get; set; }
- #endregion
- #region methods
- public ColorData2Point(int id = 1, double rtv = 1, double gtv = 1, double btv = 1, double area = 1, int floatcount = 2)
- {
- Id = id;
- RTV = rtv;
- GTV = gtv;
- BTV = btv;
- Area = area;
- FloatCount = floatcount;
- UpdatePoint();
- }
- /// <summary>
- /// 返回单点R平均值
- /// </summary>
- /// <returns></returns>
- public double GetRSV()
- {
- double ret = Math.Round(RTV / Area, FloatCount);
- return ret;
- }
- /// <summary>
- /// 返回单点G平均值
- /// </summary>
- /// <returns></returns>
- public double GetGSV()
- {
- double ret = Math.Round(GTV / Area, FloatCount);
- return ret;
- }
- /// <summary>
- /// 返回单点B平均值
- /// </summary>
- /// <returns></returns>
- public double GetBSV()
- {
- double ret = Math.Round(BTV / Area, FloatCount);
- return ret;
- }
- /// <summary>
- /// 返回HSB色调值
- /// </summary>
- /// <returns></returns>
- public double GetHue()
- {
- UpdatePoint();
- return Math.Round(PointColor.GetHue(), FloatCount);
- }
- /// <summary>
- /// 返回HSB饱和度值
- /// </summary>
- /// <returns></returns>
- public double GetSaturation()
- {
- return 1.0;
- #if false
- #region MyRegion
- #if true
- UpdatePoint();
- return Math.Round(this.PointColor.GetSaturation(), FloatCount);
- #endif
- #region MyRegion
- this.UpdatePoint();
- var vmax = Math.Max(this.GTV, Math.Max(this.RTV, this.BTV)) / this.Area;
- var vmin = Math.Min(this.GTV, Math.Min(this.RTV, this.BTV)) / this.Area;
- var sat = Math.Max(1.0, Math.Round((vmax - vmin) / vmax * 100.0, 2));
- return sat;
- #endregion
- #endregion
- #endif
- }
- /// <summary>
- /// 返回HSB亮度值
- /// </summary>
- /// <returns></returns>
- public double GetBrightness()
- {
- UpdatePoint();
- return Math.Round(PointColor.GetBrightness(), FloatCount);
- }
- #endregion
- }
- }
|