Image manipulation

1.2 Manipulating an image in memory Once an image has been loaded into memory, the operations that can be carried out on it essentially consist of making calculations on the array of pixels.
Grey levels With the format of a colour image where each pixel is represented by the three levels r, v and b, the grey colour is obtained by assigning the same value to the three colour levels. To transform a colour image into a grayscale image, each pixel must be assigned a grayscale value, which is called the luminance, calculated from the colour of the image. The human eye is not sensitive in the same way to these three colours, so to get a good result we cannot simply average them. The C.I.E. (Commission for International Electrotechnical Cooperation) proposes to characterize the luminance information (the value) of a pixel by the formula :
Grey = 0.2125 Red + 0.7154 Green + 0.0721 Blue
Exercise 5:Write a function image levelGrey(tImageim)which returns a grayscale image created from the image given as a parameter. Use the given formula to calculate the luminance of each pixel.
Blurring The Gaussian blurring algorithm consists in replacing each pixel of an image by the average value of the pixels surrounding it. As this operation modies the pixel values and performs the calculations from the values of the surrounding pixels it is necessary to leave the original image unchanged and create a new image. The degree of blurring depends on the number of pixels considered around the pixel to be blurred. This is expressed as the radius which denes the square of the pixels around the pixel to be blurred from which the average value is calculated. For example, in the following gure the light blue pixel in the middle will be blurred by replacing it with the average of the 9 pixels located within a radius of 1 pixel around it to obtain the purple pixel.
Radius blurring 1 —–>
More generally, given a blur of radius r pixels, we replace a pixel by the average of the pixels
pixels located in a square of dimension 2r + 1 around
Blurring of radius r —–>
The pixel is replaced by the pixel (the average of the values of the (2r + 1)^2 pixels of which pi,j is the centre). Of course this calculation is to be done for each of the red, green and blue components.
Exercise 6: Write a function pixel blur avg(tImageim, int i, int j, int r)which returns the pixel obtained by calculating the average of the pixels located in the square of radius r around the pixel of coordinates (i, j) of the imageim. Be careful to manage the edges of the image! There are no (2r + 1)^2 pixels around a pixel if it is less than r pixels from an edge.
Exercise 7:Write a function image blur(tImage im,int n)which returns a new image created by blurring the image given as a parameter with a blurring radius r. The resulting image is obtained by invoking the oumoy function on each pixel of the given image.
Clipping Exercise 8:Obtaining the contours of the elements of an image can be done from Gaussian blurring by replacing each pixel of the original image by the pixel obtained with the formula :
*Blanc(French) = white(ENG)where White is the white pixel whose components r, v and b are all 255 and where the fuzzy pixel is calculated as with radius r = 2.
Write a function image contours(tImage im)which return as a result a new image containing the contours of the given image.

× How can I help you?