Question

We’re sure you've seen old black-and-white (actually, grayscale) photos that, over time, have gained a yellowish...

We’re sure you've seen old black-and-white (actually, grayscale) photos that, over time, have gained a
yellowish tint. We can mimic this effect by creating sepia-tinted images.
There are several different ways to sepia-tint an image. In one of the simplest techniques, the image is
first converted to grayscale, and then each pixel's red and blue components are adjusted, leaving the
green component unchanged. Here's the algorithm:
· First, we convert the image to grayscale, because old photographic prints were grayscale. After this
conversion, each pixel is a shade of gray, so its red, green and blue components are equal.
· Next, we tint each pixel so that it's a bit yellow. In the RGB system, yellow is a mixture of red and
green. To make a pixel appear slightly more yellow, we can simply decrease its blue component by a
small percentage. If we also increase the red component by the same percentage, the brightness of
the tinted pixel is essentially unchanged. The amount by which we change a pixel's red and blue
components depends on whether the pixel is a dark gray, a medium gray, or a light gray.
o If the pixel's RGB values are less than 63, the pixel is in a shadowed area (it's a dark gray), so
the blue component is decreased by multiplying it by 0.9 and the red component is increased
by multiplying it by 1.1. (Note that we only have to compare one of the pixel’s components
to 63 – not all three – because all three components in a shade of gray have the same value.)
o If the pixel's RGB components are between 63 and 191 inclusive, the pixel is a medium gray.
The blue component is decreased by multiplying it by 0.85 and the red component is
increased by multiplying it by 1.15.
o If pixel's RGB components are greater than 191, the pixel is in a highlighted area (it's a light
gray), so the blue component is decreased by multiplying it by 0.93 and the red component is
increased by multiplying it by 1.08.
Develop a filter named sepia that returns a copy of the input image in which all the pixels have been
sepia-tinted. Don’t implement the grayscale algorithm in this function. Instead, import the grayscale
function from simple_Cimpl_filters.py,

0 0
Add a comment Improve this question Transcribed image text
Answer #1

please refer to below attached photos for clear understanding and implementation of the problem :

Note : please replace the load_gray function with the grayscale fucntion that u currently have.

Activities Atom - Thu 11:05 PM tint_image.py - n/yogeesh/random_stuff – Atom File Edit View Selection Find Packages Help tintActivities Atom - Thu 11:06 PM tint_image.py - -/yogeesh/random_stuff – Atom File Edit View Selection Find Packages Help tint

Activities Thu 11:06 PM OX dog.jpg - -/yogeesh/random_stuff - Atom File Edit View Selection Find Packages Help yogeesh@yogees

code :

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.image as img
import cv2

# create a numpy array of same shape as image filled with 0
# get the pixel for each height and width.
# get the increase and decrease factor for red and blue channels.
# as cv2 format is BGR , store the pixel * decrease_factor in first channels
# store same pixel in second as green is unchanged.
# store the pixel * increase_factor in last channel for red.
# return the new image.
def tint_image(image):
tinted_image = np.zeros_like(image)
for h in range(image.shape[0]):
for w in range(image.shape[1]):
pixel = image[h,w,0]
if pixel < 63:
decrease_factor = 0.9
increase_factor = 1.1

elif pixel >= 63 and pixel < 191:
decrease_factor = 0.85
increase_factor = 1.15

else:
decrease_factor = 0.93
increase_factor = 1.08

tinted_image[h,w,0] = int(pixel * decrease_factor)
tinted_image[h,w,1] = pixel
tinted_image[h,w,2] = int(pixel * increase_factor)

return tinted_image

# this fucntion loads a grayscale image using cv2 and convert grayscale to three channel grayscale.
# please replace this function with the one you have for grayscale fucntion .
def load_gray(filename):
gray = cv2.imread(filename , 0)
three_channel_gray = cv2.cvtColor(gray , cv2.COLOR_GRAY2BGR)
return three_channel_gray

def main():
three_channel_gray = load_gray("dog.jpg")
tinted_image = tint_image(three_channel_gray)

cv2.imshow("tinted_image" , tinted_image)
cv2.waitKey(0)
cv2.destroyAllWindows()

if __name__ == "__main__":
main()

Add a comment
Know the answer?
Add Answer to:
We’re sure you've seen old black-and-white (actually, grayscale) photos that, over time, have gained a yellowish...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • The ACME Manufacturing Company has hired you to help automate their production assembly line. Cameras have...

    The ACME Manufacturing Company has hired you to help automate their production assembly line. Cameras have been placed above a conveyer belt to enables parts on the belt to be photographed and analyzed. You are to augment the system that has been put in place by writing C code to detect the number of parts on the belt, and the positions of each object. The process by which you will do this is called Connected Component Labeling (CCL). These positions...

  • Mountain Paths (Part 1) Objectives 2d arrays Store Use Nested Loops Parallel data structures (i.e...

    Mountain Paths (Part 1) in C++ Objectives 2d arrays Store Use Nested Loops Parallel data structures (i.e. parallel arrays … called multiple arrays in the zyBook) Transform data Read from files Write to files structs Code Requirements Start with this code: mtnpathstart.zip Do not modify the function signatures provided. Do not #include or #include Program Flow Read the data into a 2D array Find min and max elevation to correspond to darkest and brightest color, respectively Compute the shade of...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT