Search code examples
c#image-processingcolorsnormalization

Color Normalization


Im doing a normalization for my image and i've already gotten done the RGB values for the image. can anyone help me with the RGB normalization for the c# codes like maybe some starters on how to write out the normalization code. thanks!


private void normalization_Click(object sender, EventArgs e) { // for (int x = 0; x < pictureBox1.Width; x++) {

           // for (int y = 0; y < pictureBox1.Height; y++)
            {


                try
                {
                    Bitmap img = new Bitmap(pictureBox1.Image);
                    Color c;
                    for (int i = 0; i < img.Width; i++)
                    {
                        for (int j = 0; j < img.Height; j++)
                        {
                            c = img.GetPixel(i, j);
                            int r = Convert.ToInt16(c.R);
                            int g = Convert.ToInt16(c.G);
                            int b = Convert.ToInt16(c.B);

                            d = r / (r + g + b);
                            h = g / (r + g + b);
                            f = b / (r + g + b);

                            img.SetPixel(i, j, Color.FromArgb(d, h, f));

                            Color pixelColor = img.GetPixel(i, j);
                            float normalizedPixel = (d + h + f);
                            Color normalizedPixelColor = System.Drawing.ColorConverter.(normalizedPixel);
                            img.SetPixel(x, y, normalizedPixelColor);

                        }
                    }

                }
                catch (Exception ex) { }

Hi. I've done the formulaes and all for normalization. The problem that I am facing now is that I'm having trouble getting the values of the RGB pixels out of the listbox and normalizing it with the formulae and then putting the pixels back into picturebox/image. Above is the code that i've tried to do to put the normalized RGB pixels back into the picturebox. Can I ask for some help with this because it still doesn't normalize my image. Thanks.


Solution

  • Have a look at AForge.NET if you do not mind having a dependency in your project. As a bonus you'll have plenty of other algorithms at your availability without the need for you to re-invent the for loop...