Question

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 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)= [?, ?, ?]

Homework Answers

Answer #1

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:-

  • The pixel value is negative
  • one or both of the values (m1 and m2) could not be calculated because the parameters of getPixel(x,y) were out of bounds

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

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
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...
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.
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 ×...
Using the following code perform ALL of the tasks below in C++: ------------------------------------------------------------------------------------------------------------------------------------------- Implementation: Overload input...
Using the following code perform ALL of the tasks below in C++: ------------------------------------------------------------------------------------------------------------------------------------------- Implementation: Overload input operator>> a bigint in the following manner: Read in any number of digits [0-9] until a semi colon ";" is encountered. The number may span over multiple lines. You can assume the input is valid. Overload the operator+ so that it adds two bigint together. Overload the subscript operator[]. It should return the i-th digit, where i is the 10^i position. So the first...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT