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)= [?, ?, ?]
Assuming a correct result means having a valid pixel value i.e.
0<=pixel_value<=255
There can be multiple cases where the set will produce an incorrect result or an error:-
Lets assume an image 4x4, where each cell contains the RGB values of that pixel
0,0,0 | 5,5,5 | 0,0,0 | 0,0,0 |
0,0,0 | 0,0,0 | 0,0,0 | 0,0,0 |
0,0,0 | 0,0,0 | 0,0,0 | 0,0,0 |
0,0,0 | 0,0,0 | 0,0,0 | 0,0,0 |
The Pairs which would produce wrong results would be:
Pair 1. (x,y)=(0,0)
(x,y)=[0,0,0]
(x+1,y)=[5,5,5]
Pair 2. (x,y)=(3,3)
(x,y)=[0,0,0]
(x+1,y)= //Out of bounds
Pair 3. (x,y)=(4,3)
(x,y)=//Out of bounds
(x+1,y)=//Out of bounds
Get Answers For Free
Most questions answered within 1 hours.