# TDM 30100: Project 7 — 2023

Motivation: Images are everywhere, and images are data! We will take some time to dig more into working with images as data in this series of projects.

Context: In the previous project, we learned to manipulate image’s basic factors by functions from the openCV cv2 module. In this project, we will understand key image features, detect color dominance, and perform enhancing the image’s visual quality by histogram equalization technique

Scope: Python, images, openCV, Histogram equalization

Learning Objectives
• Process images using numpy, matplotlib, and openCV.

Make sure to read about, and use the template found here, and the important information about projects submissions here.

## Dataset(s)

The following questions will use the following dataset(s):

• /anvil/projects/tdm/data/images/ballpit.jpg

## Questions

### Question 1 (2 pts)

1. Let’s work with our ballpit.jpg again. In project 06, we split the image into its color channels (red, green and blue). With outputs for its color channels, please find out the average values of intensity for each channel

2. Display the average values for each channel with a bar chart. Briefly explain what is your finding from the bar chart

 The average pixel values for the 3 channels can show the whole brightness of the image, reveal which color is dominant in the image, as well as image temperature - warm (reddish), cool(blueish) The average values of intensity of an image is calculated by summing up the intensity values of all pixels and dividing by the total number of pixels. Intensity is the value of a pixel. For a grayscaled image, the intensity has value from Black to white; for a color image in RGB, and each pixel has 3 intensity values, for R,G and B respectively.
 The average value can be calculated using numpy mean()

### Question 2 (2 pts)

1. In project 06, you created a red mask for red pixels and applied the red mask to the original image. Please create another 2 masks for green and blue channels.

2. Please identify how many pixels in the image are red, green and blue (respectively), and visualize the number of pixels for the 3 channels using a combined Histogram. Briefly explain what you found from the diagrams.

 A combined histogram here means a chart with 3 bars for the 3 channels respectively. The x-axis is the 3 channels, and the y-axis is the number of pixels for each channel.
 The summaries for each channel state the number of pixels for each color. So if blue has largest number, we can say blue is the dominant color of the image. To define lower and upper bounds for 3 colors depends on your personal judgement. You may need to adjust those thresholds value according to the different images and different purpose of your task.
 numpy sum() can be used to summarize pixels

### Question 3 (2 pts)

1. Write a function called equal_histogram_gray using the histogram equalized technique:

1. The function will accomplish a way to enhance image area that is too dark or light by adjusting the intensity values; it will only consider intensity but not any color information.

2. The input argument to the function is an image

3. The function returns a tuple of two images: one is the grayscaled image, and the other is a histogram-equalized grayscaled image

2. Run the function with "ballpit.jpg" as input. Visualize the 2 output images aligning with the original "ballpit.jpg" using a Histogram chart

 Histogram equalization is a technique in digital image processing. It is a process where the intensity values of an image are adjusted to create a higher overall contrast. Digital Image Processing is a significant aspect of data science. It is used to enhance and modify images so that their attributes are more easily understand. You may refer to more information about Histogram Equalization from the following website www.educative.io/answers/what-is-histogram-equalization-in-python
 The following 2 ways can be used to convert the image "ballpit.jpg" to grayscaled image import cv2 import matplotlib.image as mpimg IMAGE = '/anvil/projects/tdm/data/images/ballpit.jpg' img = mpimg.imread(IMAGE) gray_img1 = cv2.imread(IMAGE, 0) gray_img2= cv2.cvtColor(img.copy(), cv2.COLOR_BGR2GRAY) The cv2.equalizeHist() function will be useful to solve the question.

### Question 4 (2 pts)

1. Process one of your favorite photos with the function equal_histogram_gray. Write 1-2 sentences about your input and output. Make sure to show the result of the images.

Feel free to use /anvil/projects/tdm/data/images/coke.jpg — the results are pretty neat!

Project 07 Assignment Checklist

• Jupyter Lab notebook with your codes, comments and outputs for the assignment

• firstname-lastname-project07.ipynb.