Question: # import necessary packages # reading / writing image files from skimage import io from skimage import color # displaying images and plots import matplotlib

# import necessary packages
# reading/writing image files
from skimage import io
from skimage import color
# displaying images and plots
import matplotlib as mpl
import matplotlib.pyplot as plt
# array operations
import numpy as np
# mathematical calculations
import math
# data frame operations
import pandas as pd
# STEP 1 Quantize the image with 32 so that there are only 8 intensity levels
# ADD YOUR CODE HERE
# display the quantized image
def my_imgLuminance(imgRGB):
# make sure it is a color image
dim_img = imgRGB.shape[2]
assert dim_img >=3
# get the luminance data
if dim_img ==3:
imgLum = color.rgb2gray(imgRGB)
else:
# ignore the alpha channel
imgLum = color.rgb2gray(imgRGB[:,:,0:3])
imgLum = np.round(imgLum *255,0)
imgLum = np.minimum(imgLum,255)
imgLum = np.maximum(imgLum,0)
imgLum = imgLum.astype('uint8')
return imgLum
def my_Histogram(img, nBit):
nLevel =2**nBit
valMax =0
for i in range(8-nBit,8):
valMax +=2**i
imgQuan = img & valMax
hist = np.zeros((nLevel,), dtype=int)
valMin =2**(8-nBit)
for n in range(nLevel):
hist[n]= np.count_nonzero(imgQuan==n*valMin)
return hist, imgQuan, nLevel
if imgRGB.ndim >=3:
imgLum = my_imgLuminance(imgRGB)
else:
imgLum = imgRGB
nBit =3
histLum, imgLumQuan, numLevel = my_Histogram(imgLum, nBit)
print("----------------------")
print("Level:", nLevel)
print("----------------------")
plt.figure(figsize=(5,5))
plt.subplot(1,1,1)
plt.title('Quantize Image')
plt.imshow(imgLumQuan, cmap='gray')
plt.axis('off')
plt.show()
plt.close()
# STEP 2 Define a vector source by combining two consecutive pixels
# and calculate the probabilities of these vector symbols
# ADD YOUR CODE HERE
# notes:
# since each pixel has 8 intensity levels, there will be 8x8=64 symbols in the vector source.
# the symbols for the vector source could be represented as "aa, ab, ac,..., hf, fg, hh."
# there are a total of 512*512/2=131,072 sample vectors in the input image to calculate the histogram
# calculate the histogram of the vector symbols
# obtain the pdf by normalizing the histogram
# plot the pdf of this vector source

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!