# Set an image to GreyScale

http://documentation.xojo.com/api/graphics/rgbsurface.html#rgbsurface-transform

The example invert the images colors changing what I feel is a CLUT. But I was not able to set the CLUT to Grey.

In fact, Transform allows to write, not read

I converted it from Color to Greyscale using GIMP and tried to extract a map from it, but read is not possible.

Must I use Pixel in an `If Â/Â End IF` block to change the colors ?
Small images only (the test image is 374?Ă?512).

grey is something like
grey = (r+g+b) / 3
=Color.RGB(grey ,grey ,grey )

For a small image, Iâd use the RGBSurface.Pixel method and loop through all pixels in the RGB image.

A quick, approximate conversion from RGB to gray can be done with a weighted sum (rather than Markusâs average): grey = 0.299 * R + 0.587 * G + 0.114 * B This better approximates the response of the human visual system. For example, human vision is more sensitive to green, so the weighting factor for green is greater.

A more rigorous approach would involve using the color management system of your display if you have a calibrated display. If you cannot do this, you might be safe assuming your user has a âstandardâ display that is calibrated to âsRGBâ. Be aware that XOJO uses the âgeneric RBGâ model, so you may have to invoke transforms between âgeneric RGBâ and âsRGBâ to get it right.

It would be nice if XOJO could build in easy access to the systemâs color management system and be more clear about these issues in the âdocumentationâ.

RGBSurface.Transform indeed applies a LUT, but itÂs a 1D-LUT (independently mapping red to red, green to green, and blue) while turning a color image to grayscale requires a more complex 3D-LUT (mapping RGB to RGB). Looping through the pixels in the RGBSurface, calculating a weighted sum of the RGB values, and creating a new picture from the resulting grayscale pixels would be your best bet.

IF you need speed, maybe try MBS Xojo Picture Plugin with GrayscaleMBS method.

@Christian:
It is for small, very small images, speed is not an issue.

@Craig: works fine, I forgot IÂve already followed that road longtime ago, so I had to search a bit.

Now, I have to implement the solution from the test project to the real project.