Esempio n. 1
0
 float getOutputPixel(PositionType pos)
 {
     if (!IsValid(pos))
     {
         return(0);
     }
     return(m_output[pos.Y * m_imageWidth + pos.X]);
 }
Esempio n. 2
0
 byte getPixel(PositionType pos)
 {
     if (!IsValid(pos))
     {
         return(0);
     }
     return(m_image[pos.Y * m_imageWidth + pos.X]);
 }
Esempio n. 3
0
 void transformAt(PositionType pos, PositionType target, float distance)
 {
     target += pos;
     if (IsValid(target) && getOutputPixel(target) + distance < getOutputPixel(pos))
     {
         target = getPosAt(target);
         posAt(pos, target);
         setOutputPixel(pos, (float)Math.Sqrt((pos.X - target.X) * (pos.X - target.X) + (pos.Y - target.Y) * (pos.Y - target.Y)));
     }
 }
Esempio n. 4
0
 PositionType posAt(PositionType pos, PositionType value)
 {
     posBuffer[pos.Y * m_imageWidth + pos.X] = value;
     return(value);
 }
Esempio n. 5
0
 PositionType getPosAt(PositionType pos)
 {
     return(posBuffer[pos.Y * m_imageWidth + pos.X]);
 }
Esempio n. 6
0
 void setOutputPixel(PositionType pos, float value)
 {
     m_output[pos.Y * m_imageWidth + pos.X] = value;
 }
Esempio n. 7
0
 private bool IsValid(PositionType pos)
 {
     return(pos.X >= 0 && pos.Y >= 0 && pos.X < m_imageWidth && pos.Y < m_imageHeight);
 }
Esempio n. 8
0
        public float[] Transform(float backgroundVal, int [][] closestPoints = null)
        {
            for (int y = 0; y < m_imageHeight; ++y)
            {
                for (int x = 0; x < m_imageWidth; ++x)
                {
                    PositionType pos    = new PositionType(x, y);
                    byte         center = getPixel(pos);
                    posAt(pos, pos);
                    setOutputPixel(pos,
                                   (center != 0 && (getPixel(new PositionType(x - 1, y)) != center || getPixel(new PositionType(x + 1, y)) != center ||
                                                    getPixel(new PositionType(x, y - 1)) != center || getPixel(new PositionType(x, y + 1)) != center))
                        ? 0
                        : backgroundVal
                                   );
                }
            }

            float[]        distance = { (float)Math.Sqrt(2.0F), 1.0F, (float)Math.Sqrt(2.0F), 1.0F };
            PositionType[] target   =
            {
                new PositionType(-1, -1),
                new PositionType(0,  -1),
                new PositionType(+1, -1),
                new PositionType(-1,  0),
            };

            for (int y = 0; y < m_imageHeight; ++y)
            {
                for (int x = 0; x < m_imageWidth; ++x)
                {
                    for (int i = 0; i < 4; ++i)
                    {
                        transformAt(new PositionType(x, y), target[i], distance[i]);
                    }
                }
            }

            for (int y = 0; y < m_imageHeight; ++y)
            {
                for (int x = 0; x < m_imageWidth; ++x)
                {
                    for (int i = 0; i < 4; ++i)
                    {
                        transformAt(new PositionType(m_imageWidth - x - 1, m_imageHeight - y - 1), -(target[3 - i]), distance[3 - i]);
                    }
                }
            }

            for (int y = 0; y < m_imageHeight; ++y)
            {
                for (int x = 0; x < m_imageWidth; ++x)
                {
                    PositionType pos = new PositionType(x, y);
                    if (getPixel(pos) != 0)
                    {
                        setOutputPixel(pos, -getOutputPixel(pos));
                    }

                    if (closestPoints != null)
                    {
                        var npos = getPosAt(pos);
                        closestPoints[pos.Y * m_imageWidth + pos.X] = new[] { npos.X, npos.Y };
                    }
                }
            }

            return(m_output);
        }