JavaScript imageMosaic: compute image mosaic. You must implement the final version of the image mosaic algorithm we discussed in class (which includes the scaling of mosaic images and also randomization). Since the algorithm involves several nested loops and can take a while to run, this function will be implemented using a non-blocking loop so that the browser will not complain about its running speed. Details are in the comments embedded in the code. function imageMosaic(input, output, mosaic_name) { let width = input.width; let height = input.height;   let mimages = mosaics[mosaic_name]; // mimages is an array of mosaic images let w = mimages[0].width; // all mosaic images have the same size wxh let h = mimages[0].height; let num = mimages.length; // number of mosaic images console.log('Computing Image Mosaic...'); let y = 0; (function chunk() { for(x = 0; x <= width-w; x += w) { // x loop // ===YOUR CODE STARTS HERE=== /* for(y=0; y<=input.height-h; y+=h) {   for (x=0; x<=input.width-w; x+=w) { // loop over blocks     for(k=0; k<#candidates; k++) { // loop over candidates       d_r = d_g = d_b = 0;       for(j=0; j

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

JavaScript

  • imageMosaic: compute image mosaic. You must implement the final version of the image mosaic algorithm we discussed in class (which includes the scaling of mosaic images and also randomization). Since the algorithm involves several nested loops and can take a while to run, this function will be implemented using a non-blocking loop so that the browser will not complain about its running speed. Details are in the comments embedded in the code.

function imageMosaic(input, output, mosaic_name) {

let width = input.width;

let height = input.height;

 

let mimages = mosaics[mosaic_name]; // mimages is an array of mosaic images

let w = mimages[0].width; // all mosaic images have the same size wxh

let h = mimages[0].height;

let num = mimages.length; // number of mosaic images

console.log('Computing Image Mosaic...');

let y = 0;

(function chunk() {

for(x = 0; x <= width-w; x += w) { // x loop

// ===YOUR CODE STARTS HERE===

/*

for(y=0; y<=input.height-h; y+=h) {

  for (x=0; x<=input.width-w; x+=w) { // loop over blocks

    for(k=0; k<#candidates; k++) { // loop over candidates

      d_r = d_g = d_b = 0;

      for(j=0; j<h; j++) {

        for(i=0; i<w; i++) { // loop over pixels in block

          update d_r, d_g, d_b;

        }

      }

calculate d = d_r + d_g + d_b;

      multiply d with a random noise between 1 and 2

      keep track of best matches (i.e. smallest d)

      keep track of scales a_r, a_g, a_b of best match

    }

    copy the best match, multiplied by the scales, to output image block.

  }

}

*/

}

}

}

// ---YOUR CODE ENDS HERE---

}

output.updatePixels();

y+=h;

if (y <= height-h) { // y loop in non-blocking version

setTimeout(chunk, 0);

} else {

console.log('Done.');

}

})();

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY