Question

JavaScript, Consider the following code fragment, that is supposed to compute the pixel value let c...

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 not 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)=

Homework Answers

Answer #1

In this code, the RGB index of pixel (x,y) is set to the the average RGB of (x,y) - (x+1, y)

Also, we know that each colour index is a 8 bits value between 0 to 255 in decimals.

So, any value out of this range will produce error, such as:

Pair 1 :

(x, y) = [ 51, 51, 51] and (x+1, y) = [255, 255, 255]

Hence, m1 - m2 = 51 - 255 = -201 ( not acceptable)

Pair 2 :

(X,y) = [21, 43, 56] and (x+1,y) = [255, 124, 200]

M1 - m2 = 40 - 193 = - 153 (not acceptable)

Pair 3:

(x,y) = [0, 0, 0] and (X+1, y) = [ 51,51,51]

m1 - m2 = 0 - 51 = -51 ( not acceptable)

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Consider the following code fragment, that is supposed to compute the pixel value let c =...
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...
Consider the following function, that is supposed to return true only if provided two arrays a...
Consider the following function, that is supposed to return true only if provided two arrays a and b that are the same. function arrayEqual(a, b) { for (let i = 0; i < a.length && i < b.length; ++i) { if(a[i] !== b[i]) { return false; } } return true; } Give three pairs of arrays for which the function correctly returns false, true and then incorrectly return true . False Pair 1.) a = , b = Pair 2.)...
Consider an axiomatic system that consists of elements in a set S and a set P...
Consider an axiomatic system that consists of elements in a set S and a set P of pairings of elements (a, b) that satisfy the following axioms: A1 If (a, b) is in P, then (b, a) is not in P. A2 If (a, b) is in P and (b, c) is in P, then (a, c) is in P. Given two models of the system, answer the questions below. M1: S= {1, 2, 3, 4}, P= {(1, 2), (2,...
QUESTION 1 Convert the following code fragment to assembly code fragment, using instructions discussed in class....
QUESTION 1 Convert the following code fragment to assembly code fragment, using instructions discussed in class. if X > Y then Y=X else X=Y 2 QUESTION Suppose a user wants to do a system call. Assume that the service routine of this system call is at physical address 500. Suppose the user knows this address of the service routine. So instead of executing a system call, the user simply jumps to this location 500 (by executing “JMP 500”). Assume that...
IV.Translate the following C code fragment to ARM assembly instructions. Assume t, x, y, and z...
IV.Translate the following C code fragment to ARM assembly instructions. Assume t, x, y, and z are stored in registers r0, r1, r2, and r3. unsigned int x, y, z, t; do { x = x + 1; z = t + (z << 1); y = y - x; } while (y != x); V. What does the following sequence of instructions do? Why? RSB r2, r3, r3, LSL #4 RSB r2, r2, r2, LSL #3 VI. Write a...
In C++ Please, Write a code fragment that uses a loop to calculate ln (i.e. natural...
In C++ Please, Write a code fragment that uses a loop to calculate ln (i.e. natural log), from values of ranging from ‘1’ through ‘10’ in steps of ‘1’. Print out in this format: Ln(1) = 0 Ln(2) = 0.6931 etc.
19) What will be the output of the following JavaScript code? for(var x = 1; x...
19) What will be the output of the following JavaScript code? for(var x = 1; x < 5; x++) console.log(x); a) 11111 b) 12345 c) 1234 d) 5555 20) What will be the output of the following JavaScript code? var x = 0 do{ console.log(x) }while(x > 0) a) 0 b) null c) 1 d) No output quiz 3 4) Which of the following is an entry point of ASP.NET Core application? a) Main method of Program class b) Configure...
Write the C55x assembly code for each of the following C snippet code shown below. Assume...
Write the C55x assembly code for each of the following C snippet code shown below. Assume the 8-bit values a, b, c, and d are stored in locations 0x600, 0x601, 0x602, and 0x603 respectively in the memory. Store the result x in location 0x604 and y in location 0x60C. Do not use software to generate the assembly code and comment your code. x = (a - b)3 - (c*d); for (j=0;j<=200;j++)   y = y + (a * b);
1.    Given the following segment of code: (If there is nothing output, write None.) int x;...
1.    Given the following segment of code: (If there is nothing output, write None.) int x; int y; cin >> x; cin >> y; while (x > y) {     x -= 3;     cout << x << " "; } cout << endl;        a.    What are the output and final values of x and y when the input is 10 for x and 0 for y? [2, 2, 2]               Output                                                                                                                                                                                                    x = ______________                                                                                                                                                                                                   ...
Analysing Algorithmic Efficiency (Marks: 3) Analyze the following code fragment and provide an asymptotic (Θ) bound...
Analysing Algorithmic Efficiency (Marks: 3) Analyze the following code fragment and provide an asymptotic (Θ) bound on the running time as a function of n. You do not need to give a formal proof, but you should justify your answer. 1: foo ← 0 2: for i ← 0 to 2n 2 do 3: foo ← foo × 4 4: for j ← 1396 to 2020 do 5: for k ← 4i to 6i do 6: foo ← foo ×...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT