Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- test('blackenLow test', function(){
- let url = 'https://people.cs.umass.edu/~joydeepb/robot.jpg';
- let img = lib220.loadImageFromURL(url);
- let blacken_img = blackenLow(img)
- for(let x=0; x<img.width; ++x){
- for(let y=0; y<img.height; ++y){
- let pixel = img.getPixel(x, y)
- let blacken_pixel = blacken_img.getPixel(x, y)
- for(let channel=0; channel<3; ++channel){
- if(pixel[channel] < 0.298){
- assert(blacken_pixel[channel] === 0)
- }
- if(pixel[channel] > 0.302){
- assert(blacken_pixel[channel] === pixel[channel])
- }
- }
- }
- }
- });
- test('saturate test', function(){
- let url = 'https://people.cs.umass.edu/~joydeepb/robot.jpg';
- let img = lib220.loadImageFromURL(url);
- let saturated_img = saturateHigh(img)
- for(let x=0; x<img.width; ++x){
- for(let y=0; y<img.height; ++y){
- let pixel = img.getPixel(x, y)
- let saturated_pixel = saturated_img.getPixel(x, y)
- for(let channel=0; channel<3; ++channel){
- if(pixel[channel] > 0.702){
- assert(saturated_pixel[channel] === 1)
- }
- if(pixel[channel] < 0.698){
- assert(saturated_pixel[channel] === pixel[channel])
- }
- }
- }
- }
- });
- test('gray test', function(){
- let url = 'https://people.cs.umass.edu/~joydeepb/robot.jpg';
- let img = lib220.loadImageFromURL(url);
- let gray_img = toGrayscale(img)
- for(let x=0; x<img.width; ++x){
- for(let y=0; y<img.height; ++y){
- let pixel = img.getPixel(x, y)
- let gray_pixel = gray_img.getPixel(x,y)
- for(let channel=0; channel<3; ++channel){
- if(pixel[channel] > 0.702 || pixel[channel] < 0.298){
- assert(pixelEq(pixel, gray_pixel))
- }
- }
- }
- }
- });
- test('imageMapXY function definition is correct', function() {
- let identityFunction = function(image, x, y) {
- return image.getPixel(x, y);
- };
- let inputImage = lib220.createImage(10, 10, [0, 0, 0]);
- let outputImage = imageMapXY(inputImage, identityFunction);
- // Output should be an image, so getPixel must work without errors.
- let p = outputImage.getPixel(0, 0);
- assert(p[0] === 0);
- assert(p[1] === 0);
- assert(p[2] === 0);
- assert(inputImage !== outputImage);
- });
- function pixelEq (p1, p2) {
- const epsilon = 0.002;
- for (let i = 0; i < 3; ++i) {
- if (Math.abs(p1[i] - p2[i]) > epsilon) {
- return false;
- }
- }
- return true;
- };
- test('identity function with imageMapXY', function() {
- let identityFunction = function(image, x, y ) {
- return image.getPixel(x, y);
- };
- let inputImage = lib220.createImage(10, 10, [0.2, 0.2, 0.2]);
- inputImage.setPixel(0, 0, [0.5, 0.5, 0.5]);
- inputImage.setPixel(5, 5, [0.1, 0.2, 0.3]);
- inputImage.setPixel(2, 8, [0.9, 0.7, 0.8]);
- let outputImage = imageMapXY(inputImage, identityFunction);
- assert(pixelEq(outputImage.getPixel(0, 0), [0.5, 0.5, 0.5]));
- assert(pixelEq(outputImage.getPixel(5, 5), [0.1, 0.2, 0.3]));
- assert(pixelEq(outputImage.getPixel(2, 8), [0.9, 0.7, 0.8]));
- assert(pixelEq(outputImage.getPixel(9, 9), [0.2, 0.2, 0.2]));
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement