digital image processing, phyton

profileAssascreed
Project06_ColorTheory-.docx

Project 6 - Color Theory

In this project, you will implement the following:

1. Extract the YUV bands of an image

2. Decimate the Y band and show its effect on the quality of the RGB image

3. Decimate the U band and show its effect on the quality of the RGB image

4. Decimate the V band and show its effect on the quality of the RGB image

# import necessary packages # reading/writing image files

from skimage import io

from skimage import color

# displaying images and plots

import matplotlib.pyplot as plt

# array operations

import numpy as np

# mathematical calculations

import math

import cmath

# DFT calculations

from scipy import fftpack as ft

# histogram calculation

from skimage import exposure

# signal processing operations

from scipy import signal

from scipy.linalg import circulant

# display an image in original size

def my_display_actual_size(img, str_caption): height = img.shape[0]

width = img.shape[1] ndim = img.ndim

isColor = True

if ndim == 1: isColor=False elif ndim != 3: assert False

# determine a figure size big enough to accomodate an axis of xpixels by ypixels # as well as the ticklabels, etc.

margin = 0.05

dpi = 80

figsize = (1.0+margin)*height/dpi, (1.0+margin)*width/dpi

# define the figure

fig = plt.figure(figsize=figsize, dpi=dpi)

# make the axis the right size

ax = fig.add_axes([margin, margin, 1 - 2*margin, 1 - 2*margin])

# display the image

if isColor:

ax.imshow(img, interpolation='none')

else:

ax.imshow(img, cmap='gray', vmin=0, vmax=255, interpolation='none') plt.title(str_caption)

plt.show()

return

# end of function

# STEP 0 Pick an image

In [9]:

In [10]:

In [11]:

# set image folder

image_folder = r''

# read input image

image_file = r'/peppers.png' image_path = image_folder + image_file imgRGB = io.imread(image_path)

# display image

my_display_actual_size(imgRGB,'Input Image')

# STEP 1 Transform the image into YUV color space #

# Extract the YUV bands of the image using "my_RGB2YUV()" function #

# ADD YOUR CODE BELOW

# STEP 2.a Demonstrate the effect of the Y band on image resolution #

# Decimate the Y band by a factor of 4 in horizontal and vertical directions #

In [12]:

In [13]:

# ADD YOUR CODE BELOW

#

# Interpolate the decimated Y band back to its original size #

# ADD YOUR CODE BELOW

#

# Convert from YUV back to RGB (use the processed Y band) #

# ADD YOUR CODE BELOW

#

# Calculate and print the RMSE between the above image and the original image #

# ADD YOUR CODE BELOW

# STEP 2.b Demonstrate the effect of the U band on image resolution #

# Decimate the U band by a factor of 4 in horizontal and vertical directions #

In [14]:

# ADD YOUR CODE BELOW

#

# Interpolate the decimated U band back to its original size #

# ADD YOUR CODE BELOW

#

# Convert from YUV back to RGB (use the processed U band) #

# ADD YOUR CODE BELOW

#

# Calculate and print the RMSE between the above image and the original image #

# ADD YOUR CODE BELOW

# STEP 2.c Demonstrate the effect of the V band on image resolution #

# Decimate the V band by a factor of 4 in horizontal and vertical directions #

In [15]:

# ADD YOUR CODE BELOW

#

# Interpolate the decimated V band back to its original size #

# ADD YOUR CODE BELOW

#

# Convert from YUV back to RGB (use the processed V band) #

# ADD YOUR CODE BELOW

#

# Calculate and print the RMSE between the above image and the original image #

# ADD YOUR CODE BELOW

# STEP 3 Display the images obtained in STEP 2 above together with the original image #

# Display the original RGB image and the three RGB images obtained above in a 2x2 grid: # [Original RGB] [Y decimated RGB]

# [U decimated RGB] [V decimated RGB] #

In [16]:

# ADD YOUR CODE BELOW

STEP 4 Comments on the results ADD YOUR COMMENTS HERE

Compare the three RGB images obtained in STEP 2 to the original RGB image in terms of (a) visual quality and (b) RMSE value and explain why decimation of different YUV bands have different effects on the RGB image quality.

In [ ]: