0
$\begingroup$

I'm trying to apply Power Law (Gamma) Transformation. Formula is simple: s = c*rγ. (c=1 , r= intensity , s= outputintensity). Here is detailed information: https://theailearner.com/2019/01/26/power-law-gamma-transformations/. I tried code (witch C#) below. But it doesn't work properly.

 public void gammatransform(Bitmap CikisResmi)
    {
        int ResimGenisligi = Img.Width;
        int ResimYuksekligi = Img.Height;
        int Greyscale;
        double y =0.4;

        for (int i = 0; i < ResimGenisligi; i++)
        {
            for (int j = 0; j < ResimYuksekligi; j++)
            {
                OkunanRenk = Img.GetPixel(i, j);
                Greyscale = Convert.ToInt16(OkunanRenk.R * 0.3 + OkunanRenk.G * 0.58 + OkunanRenk.B * 0.12);
                Greyscale = Convert.ToInt32(Math.Pow(Greyscale, y));
                if (Greyscale > 255)
                {
                    Greyscale = 255;
                }
                CikisResmi.SetPixel(i, j, Color.FromArgb(Greyscale, Greyscale, Greyscale));

            }
        }
        return;

}

$\endgroup$
  • 1
    $\begingroup$ You forgot to ask a question! And "It doesn't work properly" is hardly a problem description – as this is the signal processing SE site, we'll need you to narrow down your problem to a signal processing problem and describe that. $\endgroup$ – Marcus Müller Jul 30 '19 at 21:46
0
$\begingroup$

Gamma correction can be applied to values ranging between 0 and 1. Based on your code, it looks like there is either no conversion from 0..255 range to 0..1 range and back. If there range really is 0..1, the intermediate result is stored in an integer so it is an issue anyway.

| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.