This is the easiest way I can think of right now:
rgbToGrayScale[imageIn_Image, factor_ : 1] :=
Module[{res, w, h, i, j, r, g, b, data, image = imageIn},
res =
If [StringMatchQ[ImageColorSpace[image], "RGB"] && ImageChannels[image] === 3,
If[(Interleaving /. Options[image, Interleaving]),
image = Image[image, Interleaving -> True];
];
data = ImageData[image];
{w, h} = ImageDimensions[image];
res = ConstantArray[ConstantArray[0, w], h];
For[i = 1, i <= w, ++ i ,
For[j = 1, j <= h, ++ j,
{r, g, b} = data[[j, i]];
res[[j, i]] = Mean[{r, g, b}^factor];
];
];
Image[res]
,
image
];
Return[res];
];
You can use it as follows:
rgbToGrayScale[i]
rgbToGrayScale[i, 2]
rgbToGrayScale[i, 1.34]
p.s. Algebra
, Computer-Based Maths
, 3D Printing
have nothing to do with your question. Please consider removing them.