Exemple #1
0
        // Converting Energy Image to Black & White Image
        public void generateEnergyImage()
        {
            int w = energyImageMat.GetLength(0);
            int h = energyImageMat.GetLength(1);

            energyImage = new Bitmap(w, h);
            LockBitmap lockEnergy = new LockBitmap(energyImage);
            lockEnergy.LockImage();
            for (int i = 0; i < w; ++i)
                for (int j = 0; j < h; ++j)
                {
                    int map = 255 - (int)(energyImageMat[i, j] * 255.0);
                    lockEnergy.SetPixel(i, j, Color.FromArgb(map, map, map));
                }
            lockEnergy.UnlockImage();
        }
Exemple #2
0
        private void computeEnergy()
        {
            LockBitmap lImg = new LockBitmap(userImage);
            lImg.LockImage();
            int w = userImage.Width;
            int h = userImage.Height;
            energyImageMat = new int[w, h];
            int[,] tmpMat = new int[w, h];
            for (int i = 0; i < w; ++i)                     //defining obstacles in the image (1 = obstacle || 0 = non-obstacle)
                for (int j = 0; j < h; ++j)
                    if (colorDist(lImg.GetPixel(i, j), Settings.targetedColor) <= Settings.colorDist)
                        tmpMat[i, j] = 1;
                    else
                        tmpMat[i, j] = 0;

            lImg.UnlockImage();
            for (int i = 0; i < w; ++i)                 //Computing gradient magnitude
                for (int j = 0; j < h; ++j)
                    if (tmpMat[i, j] == 1)
                    {
                        if (i == 0 || j == 0 || i == w - 1 || j == h - 1)
                            energyImageMat[i, j] = 1;
                        else
                        {
                            energyImageMat[i, j] |= (tmpMat[i, j - 1] == 0 || tmpMat[i, j + 1] == 0) ? 1 : 0;
                            energyImageMat[i, j] |= (tmpMat[i - 1, j] == 0 || tmpMat[i + 1, j] == 0) ? 1 : 0;
                        }
                    }
        }