In: Computer Science
Javascript. Consider the following code fragment, that is supposed to compute the pixel value
let c = image.getPixel(x, y); const m1 = (c[0] + c[1] + c[2]) / 3; c = image.getPixel(x + 1, y); const m2 = (c[0] + c[1] + c[2]) / 3; image.setPixel(x, y, [m1 - m2, m1 - m2, m1 - m2]);
Give three pairs of pixel values (x, y) = [?, ?, ?] and (x+1, y) = [?, ?, ?] in the input image, for which this code does produce the correct result.
Pair 1.)
(x, y) = [?, ?, ?]
(x+1, y) = [?, ?, ?]
Pair 2.)
(x, y) = [?, ?, ?]
(x+1, y)= [?, ?, ?]
Pair 3.)
(x, y) = [?, ?, ?]
(x+1, y)= [?, ?, ?]
Note: that we consider the RGB values as 0-255 but for this assignment, I believe they want between 0-1
Okay lets see the value of M1 and M2 ,
These are the average value, of the pixels which tells us that this represents the black and white version of the image, so what we have to do here is either take a black and white picture or something that doesn't change by taking the average so it can be the same if that's the objective but since it's not necessarily mentioned.
The only play here is that we have to keep the value of M1-M2 in the range (0,255)
Anything that gives a output in a range of 0-255 so,
Pair 1
(x,y)= [123,167,167]
(x+1,y) = [98,67,65]
Pair 2
(x,y) = [255,255,255] the Complete black
(x+1,y) = [0,0,0] white so even after AVG it will remain the black only
Pair 3
(x,y) = [100,150,200]
(x+1,y) = [50,100,150]
Now the one thing here is that all the colours will have Equal proportions in the resulting image any pixel, and if we represent it with lesser data that is instead of (a,a,a) by (a) we can have a good black and white image.