计算机专外Week2-Exercises
来源:互联网 发布:java nio网络编程 编辑:程序博客网 时间:2024/04/30 23:23
Week 2 > Image For-Loop Exercises > Vertical2
Q1: Add code inside the loop to modify flowers.jpg like this: set each pixel to have green of 0, leaving the red and blue values unchanged. The result should be that the flowers look red, since the yellow was made of red+green light.
image = new SimpleImage("flowers.jpg");for (pixel: image) { // Your code here pixel.setGreen(0);}print(image);
Q2: Add code inside the loop to modify flowers.jpg like this: set each pixel to have red 255, green 0, blue 0.
image = new SimpleImage("flowers.jpg");for (pixel: image) { // Your code here pixel.setRed(255); pixel.setGreen(0); pixel.setBlue(0);}print(image);
Week 2 > Image Expressions Exercises > Problems
Q1:Write code to fix the 51020-poppy.png image which should show an orange California Poppy in the foreground (the California state flower!). The background is mostly green with some in the upper-right.
image = new SimpleImage("51020-poppy.png");for (pixel: image) { // Your code here pixel.setRed(pixel.getRed()*10); pixel.setGreen(pixel.getGreen()*5); pixel.setBlue(pixel.getBlue()*20);}print(image);
Q2:Write code to fix the 51020-stop-sky.png image which should show a red stop sign front with a background of a light blue sky and green tree leaves.
image = new SimpleImage("51020-stop-sky.png");for (pixel: image) { // Your code here pixel.setRed(pixel.getRed()*20); pixel.setGreen(pixel.getGreen()*10); pixel.setBlue(pixel.getBlue()*5);}print(image);
Q3: Write code to fix the 51020-oranges.png image which should show a box of oranges. The box itself is dull gray. The sign on the box is black, with “organic” written in light orange, and the rest of the letters in white.
image = new SimpleImage("51020-oranges.png");for (pixel: image) { // Your code here pixel.setRed(pixel.getRed()*20); pixel.setGreen(pixel.getGreen()*5); pixel.setBlue(pixel.getBlue()*10);}print(image);
Week 2 > Image Puzzle Exercises > Problems
Q1 Iron Puzzle: Write code to fix the puzzle-iron.png image. The red and green values in the image are random noise, so they should be set to 0. The real image is in the blue values, which have been divide by 10. The “solution” image will look blue, since it is exclusively in the blue values, so don’t worry about that. We’ll see a way to fix that blueness in a later section.
image = new SimpleImage("puzzle-iron.png");for (pixel: image) { // Your code here pixel.setRed(pixel.getRed()*0); pixel.setGreen(pixel.getGreen()*0); pixel.setBlue(pixel.getBlue()*10);}print(image);
Q2 Copper Puzzle: Write code to fix the puzzle-copper.png image. The red values in the image are random noise, so they should be set to 0. The real image is in the blue and green values, which have been divide by 10.
image = new SimpleImage("puzzle-copper.png");for (pixel: image) { // Your code here pixel.setRed(pixel.getRed()*0); pixel.setGreen(pixel.getGreen()*10); pixel.setBlue(pixel.getBlue()*10);}print(image);
Week 2 > Grayscale Image Exercises > Problems
Q1: The image below, golden-gate-red.jpg, shows the golden gate bridge, but all of the data is in the red values.
Write code that for each pixel copies the red value over to be the green and blue value. The result will be to change the image to grayscale which will look better.
image = new SimpleImage("golden-gate-red.jpg");for (pixel: image) { // Your code here pixel.setGreen(pixel.getRed()); pixel.setBlue(pixel.getRed());}print(image);
Q2: Here is the banana.jpg image:
Write code to change the banana.jpg image to be grayscale. Reminder: here is the line used in the loop to compute the average of the red/green/blue values and store that value in a variable named “avg”.
avg = (pixel.getRed() + pixel.getGreen() + pixel.getBlue())/3;
image = new SimpleImage("banana.jpg");for (pixel: image) { // Your code here avg = (pixel.getRed() + pixel.getGreen() + pixel.getBlue())/3; pixel.setRed(avg); pixel.setGreen(avg); pixel.setBlue(avg);}print(image);
- 计算机专外Week2-Exercises
- 计算机专外-Week1 exercises
- 计算机专外Week4-Exercises
- 计算机专外Week5-Exercises
- 计算机专外Week6-Exercises
- week2
- Week2
- week2
- Week2
- week2
- week2
- Exercises
- test Week2
- FERMI-week2
- ARA-week2
- week2总结
- Oct week2
- NO2.week2
- 用nfs挂载内核时出错 ERROR: Cannot umount的解决办法
- VMware的三种工作模式
- tensorflow cross_entropy 四种交叉熵计算函数
- LeetCode 遍历技巧 | 18. 4Sum
- 死磕 Java 并发 : 深入分析 volatile 的实现原理
- 计算机专外Week2-Exercises
- ubuntu下python 2.7与python 3.X的转换
- python把函数作为参数
- 网络编程基础
- 414. Third Maximum Number (java)
- Floyd—Warshall算法
- 问题:Hibernate ,测试类中并没有在控制台打印出sql语句?
- Simple game 【概率期望】
- 菜鸟程序员的超神之路