1 / 11

Computer Science 111

Computer Science 111. Fundamentals of Programming I More Digital Image Processing. Morph of the Day. Lightening and Darkening. Higher RGB values generally produce a brighter image, whereas lower RGB values produce a darker image

burke-sykes
Download Presentation

Computer Science 111

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Computer Science 111 Fundamentals of Programming I More Digital Image Processing

  2. Morph of the Day

  3. Lightening and Darkening • Higher RGB values generally produce a brighter image, whereas lower RGB values produce a darker image • Changing the RGB values of each pixel by the same amount will lighten or darken an image • The functions lighten and darken expect an image and an integer factor as arguments and modify the brightness or darkness of the image by that amount lighten(image, 20)

  4. Lightening and Darkening • Higher RGB values generally produce a brighter image, whereas lower RGB values produce a darker image • Changing the RGB values of each pixel by the same amount will lighten or darken an image • The functions lighten and darken expect an image and an integer factor as arguments and modify the brightness or darkness of the image by that amount darken(image, 20)

  5. Color Filtering • Lightening and darkening are special cases of color filtering • A color filter is a triple of RGB factors that is applied to each pixel to change the overall color of an image in a consistent way • Thus, the triple (0, 0, 0) indicates no change, whereas the triple (22, -10, 100) adds those amounts to the RGB values of each pixel • The image on the right shows the result of enhancing just the red value with the triple (20, 0, 0)

  6. Using a Color Filter colorFilter(image, (20, 0, 0)) # Increase red colorFilter(image, (0, 0, -20)) # Decrease blue def lighten(image, amount): colorFilter(image, (amount, amount, amount)) def darken(image, amount): colorFilter(image, (-amount, -amount, -amount)) The functions lighten and darken also use colorFilter, where the amounts in the triples are equal

  7. Defining colorFilter def colorFilter(image, (r, g, b)): def baseValue(value, offset): if offset == 0: return value elif offset < 0: return max(value + offset, 0) else: return min(value + offset, 255) for … for … (red, green, blue) = image.getPixel(x, y) (red, green, blue) = (baseValue(red, r), baseValue(green, g), baseValue(blue, b)) image.setPixel(x, y, (red, green, blue)) The nested functionbaseValue keeps the result of the addition or subtraction within the allowable range (0-255)

  8. Blurring an Image • Helps to remove raggedy edges (pixelation) in some images by softening them • Build a new image in which each pixel contains the average of the RGB values of it and its neighboring pixels • Begin with position (1, 1) and end with position (width - 2, height - 2) • Won’t alter the pixels on the perimeter, but then we won’t have to check for the perimeter as we traverse the image

  9. The blur Function def blur(image): width = image.getWidth() - 1 height = image.getHeight() - 1 newImage = image.clone() for y in xrange(1, height): for x xrange(1, width): get the current pixel and its 4 neighbors from image create a new tuple with the averages of r, g, b set the pixel at (x, y) in newImage to the result return newImage This function creates and returns a new image

  10. Edge Detection • Shows what a sketch of an image would look like • Examine neighbors below and to the left of each pixel • If the luminance of the pixel differs from either of these neighbors by a significant amount, we have detected an edge, so set its color to black • Otherwise, set that pixel’s color to white • Function detectEdges expects the image and a difference threshold as arguments and returns a new black and white image detectEdges(image, 20)

  11. Shrinking an Image • Make a copy whose width and height are a percentage of the width and height of the original image • Transfer color values from the original to the copy, skipping rows and columns as needed shrink(image, 0.5)

More Related