TDM 40100: Project 8 — 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 projects, we worked with images and implemented image Histogram Equalization, with some pretty cool results! In this project, we will continue to work with images key features, introduce YCbCr color space, and perform enhancing the image’s visual quality by histogram equalization technique with colors

Scope: Python, images, openCV, Histogram equalization, YCbCr, image digital fingerprint

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.


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

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

As in our previous projects, by default, a image is read in as a RGB image, where each pixel is represented as a value between 0 and 255, R represents "red", G represents "green", and B represents "blue". While it is natural for display with RGB, image with YCbCr format has advantages in many image processing, compression situations etc.

YCbCr is a color space used in image processing. Y stands for "Luminance", Cb stands for "Chrominance Blue", Cr stands for "Chrominance red". You may get more information for YCbCr from YCbCr

YCbCr can be derived from the RGB color space. There are several Python libraries can be used to do the conversion, in this project we will use cv2 from OpenCV

import cv2
ycbcr_img = cv2.cvtColor(img,cv2.COLOR_BGR2YCrCb)


Question 1 (2 pts)

  1. Please split /anvil/projects/tdm/data/images/ballpit.jpg into its `YCbCr`components and display them

To display the YCbCr Y component, you will need to set the Cb and Cr components to 127. To display the Cb component, you will need to set the Cr and Y components to 127, etc.

The human eye is more sensitive to luminance than to color. As you can tell from the previous question, the Y component captures the luminance, and contains the majority of the image detail that is so important to our vision. The other Cb and Cr components are essentially just color components, and our eyes aren’t as sensitive to changes in those components. Luminance shows the brightness of an image. An RGB image can be converted to a YCbCr image. The histogram equalization then can apply to the luminance without impacting the color channels (Cb and Cr channels), which, if histogram equalization directly applies to an RGB image, it may cause image artifacts issues. "Artifacts issues" refers to unwanted distortion in an image. Let’s process some images in the following questions to makes this explicitly clear

Question 2 (2 pts)

  1. Please write a function named equal_hist_rgb to do Histogram Equalization directly to an image with RGB format. The parameter will be an image. The returns will be a Histogram Equalized colored image. Run the function with input ballpit.jpg. Show the output Histogram Equalized colored image.

Question 3 (2 pts)

  1. Please write a function named equal_hist_YCrCb that applies Histogram Equalization to an image, so that first the image will be converted from RGB format to YCrCb format, then apply Histogram Equalization. The parameter will be an image. The returns will be a Histogram Equalized colored image. Run the function with image ballpit.jpg. Show the output Histogram Equalized colored image.

We can read a 3-chanel RGB image by both openCV cv2 and matplotlib.image. However, please do notice the output for cv2 is in BGR order but for matplotlib.image is in RGB order.

cv2.split() will be useful to split the image to 3 channels cv2.equalizeHist() will be useful to do histogram equalization. cv2.merge() will be useful to combine all channels back to an equalized image

Question 4 (1 pt)

  1. Please plot the original image of ballpit.jpg, output images of it from question 2 and question 3 as a combined chart. What is your conclusion?

Question 5 (1 pt)

  1. Please choose one of your favorite image as input to the two functions, display the original image and 2 output images in a combined histogram chart and state your finding

  2. Please provide the digital fingerprints for all 3 images original one, two output images from two functions using hashlib library

Just like human has unique fingerprint. Every image has a unique SHA-256 hash value. Even a tiny change of a pixel can cause a totally different SHA-256 hash value for the image. You may use a SHA-256 Hash value as the digital fingerprint for a image, for example

import hashlib
with open("img_name","rb") as f:
    img_bytes =
fingerP = hash_o.update(img_bytes)

Project 08 Assignment Checklist

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

    • firstname-lastname-project08.ipynb.

  • Submit files through Gradescope

Please make sure to double check that your submission is complete, and contains all of your code and output before submitting. If you are on a spotty internet connection, it is recommended to download your submission after submitting it to make sure what you think you submitted, was what you actually submitted.

In addition, please review our submission guidelines before submitting your project.