![]() Pixel's average is effectively a "brightness" number 0.Once its working with flowers.jpg, try it with poppy.jpg or oranges.jpg. The result is a grayscale version of the original color image. Then set the red, green, and blue values of the pixel to be that average number. This average number represents the brightness of the pixel 0.255. We'll use that line whenever we want to compute the averageĪvg = (pixel.getRed() + pixel.getGreen() + pixel.getBlue())/3 įor this example, we'll write code to change the flowers.jpg image to grayscale, using the "average" strategy: for each pixel, compute the average of its red/green/blue values.Code below computes the average, stores it in a variable "avg".Algorithm: add red+green+blue, then divide by 3.The average measures how bright the pixel is 0.255.Average combines red/green/blue into one number.To average 3 numbers, add them up and divide by 3.We compute average of red/green/blue values for each pixel.More complicated brightness measures are possible, but average is simple and works fine for our purposes. The average shows how bright the pixel is, ignoring hue: 0 = totally dark, 255=totally bright, with intermediate average values corresponding to intermediate brightnesses. The average combines and summarizes the three values into one number 0.255. ![]() Looking at just red or blue or green in isolation, it's hard to tell which pixel is brightest or darkest in the above table.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |