The easiest thing to do with pictures is to change the colour values of their pixels by changing the red, green, and blue components. You can get quite different effects by simply playing with those values.
If we want to reduce the red by 50%, we will set the red channel to 0.50 times whatever it is right now. If we want to increase the red by 25%, we will set the red to 1.25 times whatever it is right now.
We could do it to one pixel at coordinates (51,100) in our picture stored as pict by using the following commands:
redvalue=getRed(getPixel(pict, 51, 100))
setRed(getPixel(pict,51,100),0.50 * redvalue)
That’s pretty tedious to write, especially for all the pixels even in a small image, but by using a loop, we can automate the process.
Looping Through All the Pixels
getPixels returns a sequence of all the pixel objects in an input picture, so we can make a loop like this to reduce the red value by 0.5
for pixel in getPixels(pict):
redvalue=getRed(pixel)
setRed(pixel, redvalue*0.5)
So our whole program might look like this:
![]() |
Here is the original image and the result after the red has been reduced by 50%

![]() |
|
![]() |
|
Making Negatives
To create a negative image of a picture, we need to set the RGB values to their opposites, for example if the red value was 255, we need to set it to 0. To work out other values, we subtract them from 255.
So the following function will make a negative image:
![]() |
![]() |
Making Greyscale Images
A colour value is greyscale when all three RGB values are the same eg(52,52,52).
When converting to greyscale, to make the RGB values all the same for each pixel, we average the 3 values ie (R+G+B)/3 to give an intensity value.
![]() |
![]() |
Converting to greyscale this way does not take account of luminance, which is how the human eye perceives colour. We consider for example that blue is darker than red, even when the same amount of light is reflected off it. To get a better greyscale image, we can use the following formulas:
Multiply red by 0.299, multiply green by 0.587, multiply blue by 0.114, then add them together to get a luminance value:









