Grayscale Filter

Solve It

The color white has red, green, and blue values all set to 255, and the color black has red, green, and blue values all set to 0. In general, when all three color values are equal, the result is some shade of gray. We will set all color components of each pixel to the average of the original three color component values.

Code It

// weighted grey scale var image = new SimpleImage("duvall.jpg"); for (var p of image.values()) { var avg = (p.getGreen() + p.getRed() + p.getBlue()) / 3; p.setRed(avg); p.setBlue(avg); p.setGreen(avg); debug(avg); } print(image);

See It

 
 

Available Images


chapel.png
[231x308]

rodger.png
[315x424]

astrachan.jpg
[240x360]

duvall.jpg
[200x300]

hilton.jpg
[140x210]

Drop your images onto the area above to make it available within your code editor on this page. Note: your images will not be uploaded anywhere, they will stay on your computer.