コード例 #1
0
        public Stroke GenerateStroke(ColorImage input, int x, int y, int s, int factor, int level)
        {
            ArrayList list = new ArrayList();
            double    m00, m01, m10, m11, m02, m20;
            double    a, b, c;
            double    tempval;
            double    dw, dxc, dyc;
            int       xc, yc;
            double    theta;
            float     w, l;

            m00 = m01 = m10 = m11 = m02 = m20 = 0;

            System.Drawing.Color firstColor = input.GetColor(x, y);             //System::Drawing::Color::FromArgb((int)color[0], (int)color[1], (int)color[2]);

            ColorImage cropImage            = input.Crop(x, y, s, s);

            ComputeMoments(cropImage, firstColor, s, ref m00, ref m01, ref m10, ref m11, ref m02, ref m20);

            dxc     = m10 / m00;
            dyc     = m01 / m00;
            a       = (m20 / m00) - (double)((dxc) * (dxc));
            b       = 2 * (m11 / m00 - (double)((dxc) * (dyc)));
            c       = (m02 / m00) - (double)((dyc) * (dyc));
            theta   = System.Math.Atan2(b, (a - c)) / 2;
            tempval = System.Math.Sqrt(b * b + (a - c) * (a - c));
            dw      = System.Math.Sqrt(6 * (a + c - tempval));
            w       = (float)(System.Math.Sqrt(6 * (a + c - tempval)));
            l       = (float)(System.Math.Sqrt(6 * (a + c + tempval)));
            xc      = (int)(x + System.Math.Round(dxc - s / 2));
            yc      = (int)(y + System.Math.Round(dyc - s / 2));

            Stroke stroke = new Stroke();

            stroke.xc    = factor * xc;
            stroke.yc    = factor * yc;
            stroke.w     = factor * w;
            stroke.l     = factor * l;
            stroke.theta = (float)theta;
            stroke.red   = firstColor.R;
            stroke.green = firstColor.G;
            stroke.blue  = firstColor.B;
            stroke.level = level;

            return(stroke);
        }
コード例 #2
0
        public ColorImage GenerateStrokeArea(Bitmap input, int s)
        {
            ColorImage piece;
            double     m;
            ArrayList  list = new ArrayList();
            double     pixVal;

            DateTime start = DateTime.Now;

            //Bitmap img = new Bitmap(input.Width, input.Height);
            ColorImage cImg = new ColorImage(input.Width, input.Height);

            StreamWriter writer = null;             //new StreamWriter("new.txt");

            ColorImage inMem = new ColorImage(new UnsafeBitmap(input));

            for (int i = 0; i < input.Height; i++)
            {
                for (int j = 0; j < input.Width; j++)
                {
                    piece = inMem.Crop(j, i, s, s);

                    System.Drawing.Color topColor = inMem.GetColor(j, i);

                    m = Moment00(piece, topColor, writer);

                    pixVal = (255.0 * m / (piece.Width * piece.Height));

                    cImg.SetColor(j, i, Color.FromArgb((int)pixVal, (int)pixVal, (int)pixVal));
                }
            }

            //img.Save("area.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);

            TimeSpan duration = DateTime.Now - start;

            System.Console.WriteLine("Stroke area computed in " + duration.TotalMilliseconds + "ms");

            return(cImg);
        }