Example #1
0
        public static colorFeature CalcFeature(Texture2D texture_)
        {
            Photo.colorFeature color = new colorFeature();
            int w = texture_.Width;
            int h = texture_.Height;
            int dlen = w * h * 4;
            byte[] d = new byte[dlen];
            texture_.GetData(d);
            List<Vector3> f = new List<Vector3>();
            Vector3 rgbave = Vector3.Zero;
            Vector3 hsvave = Vector3.Zero;
            for (int i = 0; i < FeatureSplit; ++i)
            {
                for (int j = 0; j < FeatureSplit; ++j)
                {
                    int count = 0;
                    Vector3 rgb = Vector3.Zero;
                    Vector3 hsv = Vector3.Zero;
                    for (int ii = h * i / FeatureSplit; ii < h * (i + 1) / FeatureSplit; ++ii)
                    {
                        for (int jj = w * j / FeatureSplit; jj < w * (j + 1) / FeatureSplit; ++jj)
                        {
                            int index = 4 * (jj + ii * w);
                            rgb.X += d[index + 2];
                            rgb.Y += d[index + 1];
                            rgb.Z += d[index];
                            ++count;
                        }
                    }
                    rgb /= (float)(count * 255);
                    rgbave += rgb;
                    ResourceManager.rgb2hsv(ref rgb, out hsv);
                    f.Add(hsv);
                }
            }
            color.feature_ = f.ToArray();

            rgbave /= (float)(FeatureSplit * FeatureSplit);
            ResourceManager.rgb2hsv(ref rgbave, out hsvave);
            color.variance_ = 0d;
            foreach (Vector3 ff in f)
            {
                color.variance_ += ResourceManager.HsvDist(ff, hsvave);
            }
            color.variance_ /= (double)(FeatureSplit * FeatureSplit);

            return color;
        }
Example #2
0
 /// <summary>
 /// コンストラクタ
 /// </summary>
 /// <param name="graphics"></param>
 /// <param name="filename"></param>
 public Photo(int photoID, string filename, Vector2 position, float scale, float angle, PhotoTag p, Texture2D t, colorFeature f)
 {
     ID_ = photoID;
     filename_ = filename;
     position_ = position;
     positionDisplay_ = position;
     positionTarget_ = position;
     scale_ = scale;
     scaleDisplay_ = 0f;
     scaleTarget_ = scale;
     angle_ = angle;
     angleDisplay_ = angle;
     angleTarget_ = angle;
     ptag = p;
     texture_ = t;
     color = f;
     //this.LoadTag();
 }