Question: CHW 6 . 2 . Discrete Cosine Transforms and Image Compression The discrete cosine transform is a powerful technique for expressing data as a sum

CHW6.2. Discrete Cosine Transforms and Image Compression
The discrete cosine transform is a powerful technique for expressing data as a sum of cosine waves, and has many applications in audio and image compression. We will use the "chunking" technique discussed in the lab activity here to compress a whole image.
Given a 512512 image, stored in the variable image, you will break the image into smaller 88 chunks. Then for each chunk, you will convert to the DCT basis, drop the frequencies with relatively small contribution, then convert back to the standard basis and clip the resulting pixel values so that they lie between 0 and 255. This image is given in gray scale, where each pixel varies from 0 to 255. To gauge which frequencies have a small contribution, use a tolerance of 10% of the largest absolute value in each particular chunk after converting it into the DCT basis.
The setup code provides the helper function create_dct_basis(n, which creates an nn matrix whose columns make up the n-dimensional DCT basis.
To construct your solution, write a code snippet that:
defines the function compress_chunk(chunk) that takes as argument a "chunk" of the image, with dimension 88, and returns the compressed "chunk".
make sure your compressed chunk returned from compress_chunk() contains only
defines the function compress_chunk(chunk) that takes as argument a "chunk" of the image, with dimension 88, and returns the compressed "chunk".
make sure your compressed chunk returned from compress_chunk() contains only values between 0 and 255, as in the original image. You may find the function numpy.clip() useful.
use your function to construct the variable compressed, which contains the compressed image.
The setup code gives the following variable:
\table[[Name,Type,Description],[image,512512 numpy array,Test image],[create_dct_basis,function,Creates the n-dimensional DCT basis]]
Your code snippet should define the following variable:
\table[[Name,Type,Description],[compress_chunk,function,Function to compress an 88 chunk],[compressed,512512 numpy array,Compressed image]]
user_code.py
import numpy as np
import numpy.linalg as la
import matplotlib.pyplot as plt
plt.figure()
plt.imshow(image, cmap='gray')
compressed = image. copy()
## Add your code here
plt.figure()
plt.imshow (compressed, cmap='gray')
 CHW6.2. Discrete Cosine Transforms and Image Compression The discrete cosine transform

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!