Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

# 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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Essentials of Database Management

Authors: Jeffrey A. Hoffer, Heikki Topi, Ramesh Venkataraman

1st edition

133405680, 9780133547702 , 978-0133405682

More Books

Students also viewed these Databases questions

Question

What is one of the skills required for independent learning?Explain

Answered: 1 week ago

Question

To what extent is news constructed or created?

Answered: 1 week ago