# My Power Law (Gamma) Transformation Code Doesn't Compatible With Gamma Value

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;


}

• 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. – Marcus Müller Jul 30 '19 at 21:46