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. A 20 lighter version of the original color is FFFFFF, and C6C6C6 is the 20 darker color. A complement of this color would be FFFFFF, and the grayscale version is FFFFFF. Q: How to decide which pixel below is brightest? darkest? The Hex color FFFFFF is a light color, and the websafe version is hex FFFFFF, and the color name is white.Choose a few pixels out of flowers.jpg, each in a row below.Problem: for each pixel, how dark/light is it (ignoring hue).How to covert a regular color image to grayscale?.but this code gets a value from one color Usually code combines setRed() with getRed(), Set green and blue values to be the same as the red value. Likewise, set the blue value to be the same as the red value.Algorithm: for each pixel, set the green value to be the same as the red value.What change to the pixels will accomplish this?.Change the red/green/blue values to be all equal for each pixel.Change the image to be grayscale, not just red.Here's what individual pixels look like:. What is the code to do that? What will be the visual result of this? So for a pixel, if red is 27, set green and blue to also be 27. This image looks quite wrong.įor this example, we'll write code to fix this image by copying the red value over to be used as the green and blue value. Here is an image of the Statue of Liberty where all of the data is in the red values, so the whole image looks red (we saw this sort of image in an earlier puzzle solution). The higher the red/green/blue numbers, the lighter the shade of gray. If a pixel were red=75 green=50 blue=50 it would be a bit reddish, but making them all equal, it's not towards any particular hue. red=50 green=50 blue=50 is gray, without any bias towards red, green, or blue hue. The RGB scale is calibrated so that when a color's three red/green/blue numbers are equal, the color is a shade of gray.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |