Exemplo n.º 1
0
        private Color[,] dilatationGray(Color[,] Image, StructElement structElement)
        {
            if (OutputImage != null)
            {
                OutputImage.Dispose();                                                  // Reset output image
            }
            OutputImage = new Bitmap(InputImage.Size.Width, InputImage.Size.Height);    // Create new output image
                                                                                        //Color[,] Image = new Color[InputImage.Size.Width, InputImage.Size.Height];  // Create array to speed-up operations (Bitmap functions are very slow)
            Color[,] output     = new Color[InputImage.Size.Width, InputImage.Size.Height];
            int[,] structMatrix = structElement.getMatrix();

            for (int i = 0; i < InputImage.Size.Width; i++)
            {
                for (int j = 0; j < InputImage.Size.Height; j++)
                {
                    output[i, j] = Color.FromArgb(255, 255, 255);
                }
            }
            int offset = (structElement.getSize() - 1) / 2;

            //convertImageToString(Image);
            setupProgressBar();
            int value = 0;

            for (int u = offset; u < InputImage.Size.Width - offset; u++)
            {
                for (int v = offset; v < InputImage.Size.Height - offset; v++)
                {
                    value = 0;
                    for (int i = -offset; i < offset; i++)
                    {
                        for (int j = -offset; j < offset; j++)
                        {
                            if (structMatrix[i + offset, j + offset] != -256)          //cell off
                            {
                                if (Image[u + i, v + j].R + structMatrix[i + offset, j + offset] > 255)
                                {
                                    value = Math.Max(value, 255);
                                }
                                else
                                {
                                    value = Math.Max(value, (Image[u + i, v + j].R) + (structMatrix[i + offset, j + offset]));
                                }
                            }
                        }
                    }
                    output[u, v] = Color.FromArgb(value, value, value);
                    progressBar.PerformStep();
                }
            }


            return(output);
        }
Exemplo n.º 2
0
        private Color[,] dilatationBinary(Color[,] Image, StructElement structElement)
        {
            if (OutputImage != null)
            {
                OutputImage.Dispose();                                                   // Reset output image
            }
            OutputImage     = new Bitmap(InputImage.Size.Width, InputImage.Size.Height); // Create new output image
            Color[,] output = new Color[InputImage.Size.Width, InputImage.Size.Height];
            setupProgressBar();
            int[,] H = structElement.getMatrix();
            int Hsize = structElement.getSize();

            for (int i = 0; i < InputImage.Size.Width; i++)
            {
                for (int j = 0; j < InputImage.Size.Height; j++)
                {
                    output[i, j] = Color.FromArgb(255, 255, 255);
                }
            }
            for (int i = 0; i < Hsize; i++)
            {
                for (int j = 0; j < Hsize; j++)
                {
                    if (H[i, j] == 1)
                    {
                        for (int u = 0; u < InputImage.Size.Width - Hsize; u++)
                        {
                            for (int v = 0; v < InputImage.Size.Height - Hsize; v++)
                            {
                                if (Image[u, v].R == 0)
                                {
                                    output[u + i, v + j] = Color.FromArgb(0, 0, 0);
                                }
                            }
                        }
                    }
                }
            }

            return(output);
        }