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