Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

MATLAB Project d goldhill.jpg krusty.jpg kface.jpg goldengate.jpg toucan.jpg barbara.jpg track.jpg bridge.jpg 4 MATLAB Project In this project you will be asked to analyze digital images

MATLAB Project image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribeddimage text in transcribed goldhill.jpg image text in transcribed krusty.jpg image text in transcribed kface.jpg image text in transcribed goldengate.jpg image text in transcribed toucan.jpg image text in transcribed barbara.jpg image text in transcribed track.jpg image text in transcribed bridge.jpg image text in transcribed

4 MATLAB Project In this project you will be asked to analyze digital images using the SVD. Before you start the exercises, fa- miliarize yourself with the MATLAB functions: imread, image, imwrite, svds, uint8, and double. For example, type help imread at the MATLAB prompt to learn more about the imread command. 4.1 Simple Image Manipulations 1. Download the files goldhall.jpg and krusty.jpg from the course web page. Use the com- mand imread to read them into MATLAB and store them matrices. For example, A = imread('goldhill.jpg'); 3 = imread('krusty.jpg'); Use the command size to find the dimensions of A and B. Without displaying the images, how can you tell whether the images are monochrome (black and white) or RGB (color)? Take a look at some of the entries for A and B, say A (10,288) or (150,22,1). What do these numbers mean? Now use image to display A and B. 2. Create a subimage of krusty.jpg. You will do this by creating a submatrix of B, the matrix in which krusty.jpg is stored. Define the matrix subs as the submatrix of B given by subB = B(1:200, 100:300,:); This will store in subs the submatrix of B consisting of the rows 1 through 200. columns 100 through 300, in each layer of B. Save this matrix subs as a JPEG image called kface.jpg as indicated below: imwrite (subB,'kface.jpg"); This will save the image stored in subB as kface.jpg in the current directory. Display the image kface.jpg by typing image (suba); to show the image stored in subB. Then, try c = imread('kface.jpg' ); image (C); 3. Download the file goldengate.jpg from the course web page. Read the file into MATLAB and display it using image: D = imread('goldengate.jpg'); image (D); You should see an RGB image of the Golden Gate Bridge of San Francisco Find the dimension of matrix D by typing size (D) and check that MATLAB returns ans = 108 250 3 The last 3 indicates that this is an RGB or color image, and each color plane (red, green, and blue) is a 108 by 250 array. Extract the red, green, and blue color layers by doing the following Dred = D(:,:,1); Dgreen = D(:,:, 2); Dblue = D(:, :,3); Use the command subplot to show the original color image and its three color planes in the same figure. Remember that each color plane is a grayscale image. Now do the following: DLayer = D; define DLayer as the whole image DLayer (:, :,2) = zeros (108,250); & zero out green plane DLayer(:, :, 3) = zeros (108,250); zero out blue plane image (DLayer) What is the visual result? Modify the preceding instructions to get the green and blue layers of the image 4. Download the file toucan.jpg from the course web page. Store the image in matrix E and display it using image. Perform simple arithmetic operations on the image. If necessary.convert to double all uint8 data before you do arithmetic operations. You can then convert back to 8-bit unsigned integers using the uinto function Just for fun, display the result of the following operations: image (E'); image (2 E); image (E. 2): Comment on the visual effects that each of the above operations had on the original image Generate a random matrix R of the same size as E, with values uniformly distributed between 0 and 255. B = uint8 (255.rand (size (E) ) ) Display the image of the random matrix R: Image(); How about the matrix R + EP Type image (R + E); Comment on your observations of the images of R and R + E. 4.2 Compression of Grayscale Image Using the SVD and then 1. Download the file barbara.jpg from the course web page. Store the image in matrix display it using image. 2. Compute the 100 largest singular values of A. Type Ad - double (A): [U,S,V] = svds (Ad, 100); This will give an approximation of the matrix A by keeping its 100 largest singular values. 10 3. Show the image of the above approximation by doing the following: A100 = U+S+V'; A100 = uint8 (A100); figure: image (A100); 4. Find the size of A and use Equation (10) to calculate the amount of memory needed to store A. Keep in mind that each entry of A occupies 8 bits or 1 byte. Then use Equation (11) to calculate the amount of memory required to store the rank 100 approxima- tion. Determine the compression ratio for the rank 100 approximation According to your visual perception is A100 an acceptable approximation of A? What happens if you keep the 200 largest singular values? How much memory does A200 take up? Is A200 an acceptable approximation? What happens if you keep the 70 largest singular values? How much memory does A70 take up? Is A 70 an acceptable approximation? 4.3 Compression of Color Image Using the SVD 1. In Section 4.2 you compressed a black and white image using different rank approximations. In this exercise you will compress an RGB or color image. Download the file track.jpg from the course web page. Store the image in matrix and then display it using image. 2. Approximate B with rank 8, 32, and 128 matrices. For RGB images do it layer by layer: simply extend the ideas presented in Section 4.2 for monochrome images. Display the resulting approximations and comment on the quality of the images. Use subplot to show the original and approximate images in the same figure 4.4 Analysis of Compressed Images 1. The SVD of an Image Download the file bridge.jpg from the course web page. Read it into MATLAB and display it From the SVD of the image display a rank 1 approximation of the image. What can you say about the "columns" in the rank I approximation of the image in terms of linear dependence/independence? Does your image appear to agree that you indeed produced a rank 1 approximation? Next, reconstruct your image using the SVD of rank 2. 1.8.16, 32, 67, and 128. Using the command subplot, plot all these approximations along with the original image in the same window for an easy comparison 2. The Decay of the Singular Values Make a plot that shows how the singular values decay along the diagonal of the matrix in the Singular value decomposition A=UEVT How do the singular values decay for the image bridge.jpg? 11 3. Compression Error Using the SVD, approximate the image bridge.jpg with a rank 64 matrix. Compute the relative error using the Frobenius norm as defined in Equation (8). To find the Frobenius norm of an array M, type the MATLAB instruction norm(M,' fro'). Compare the relative errors between the images and discuss the results. 4. Compression Based on Visual Perception How much can you compress bridge.jpg using the SVD such that your compressed image is "almost" perfect based on your visual perception? How large did the rank need to be before it looked "natural" to your eyes? 3. Illustration of the Frobenius Norm Reconstruct bridge.jpg using two different methods: A rank 100 approximation . Using all but the first two singular values of the image. Compute the relative error in the Frobenius norm for both of the approximation. Does the result of the norm roughly agree with the error based on visual perception? 6. Compression Based on the Frobenius Norm For the image bridge.jpg, how large does the rank need to be so that the relative error (in the Frobenius norm) is less than 10%? MAIT GROES26 4 MATLAB Project In this project you will be asked to analyze digital images using the SVD. Before you start the exercises, fa- miliarize yourself with the MATLAB functions: imread, image, imwrite, svds, uint8, and double. For example, type help imread at the MATLAB prompt to learn more about the imread command. 4.1 Simple Image Manipulations 1. Download the files goldhall.jpg and krusty.jpg from the course web page. Use the com- mand imread to read them into MATLAB and store them matrices. For example, A = imread('goldhill.jpg'); 3 = imread('krusty.jpg'); Use the command size to find the dimensions of A and B. Without displaying the images, how can you tell whether the images are monochrome (black and white) or RGB (color)? Take a look at some of the entries for A and B, say A (10,288) or (150,22,1). What do these numbers mean? Now use image to display A and B. 2. Create a subimage of krusty.jpg. You will do this by creating a submatrix of B, the matrix in which krusty.jpg is stored. Define the matrix subs as the submatrix of B given by subB = B(1:200, 100:300,:); This will store in subs the submatrix of B consisting of the rows 1 through 200. columns 100 through 300, in each layer of B. Save this matrix subs as a JPEG image called kface.jpg as indicated below: imwrite (subB,'kface.jpg"); This will save the image stored in subB as kface.jpg in the current directory. Display the image kface.jpg by typing image (suba); to show the image stored in subB. Then, try c = imread('kface.jpg' ); image (C); 3. Download the file goldengate.jpg from the course web page. Read the file into MATLAB and display it using image: D = imread('goldengate.jpg'); image (D); You should see an RGB image of the Golden Gate Bridge of San Francisco Find the dimension of matrix D by typing size (D) and check that MATLAB returns ans = 108 250 3 The last 3 indicates that this is an RGB or color image, and each color plane (red, green, and blue) is a 108 by 250 array. Extract the red, green, and blue color layers by doing the following Dred = D(:,:,1); Dgreen = D(:,:, 2); Dblue = D(:, :,3); Use the command subplot to show the original color image and its three color planes in the same figure. Remember that each color plane is a grayscale image. Now do the following: DLayer = D; define DLayer as the whole image DLayer (:, :,2) = zeros (108,250); & zero out green plane DLayer(:, :, 3) = zeros (108,250); zero out blue plane image (DLayer) What is the visual result? Modify the preceding instructions to get the green and blue layers of the image 4. Download the file toucan.jpg from the course web page. Store the image in matrix E and display it using image. Perform simple arithmetic operations on the image. If necessary.convert to double all uint8 data before you do arithmetic operations. You can then convert back to 8-bit unsigned integers using the uinto function Just for fun, display the result of the following operations: image (E'); image (2 E); image (E. 2): Comment on the visual effects that each of the above operations had on the original image Generate a random matrix R of the same size as E, with values uniformly distributed between 0 and 255. B = uint8 (255.rand (size (E) ) ) Display the image of the random matrix R: Image(); How about the matrix R + EP Type image (R + E); Comment on your observations of the images of R and R + E. 4.2 Compression of Grayscale Image Using the SVD and then 1. Download the file barbara.jpg from the course web page. Store the image in matrix display it using image. 2. Compute the 100 largest singular values of A. Type Ad - double (A): [U,S,V] = svds (Ad, 100); This will give an approximation of the matrix A by keeping its 100 largest singular values. 10 3. Show the image of the above approximation by doing the following: A100 = U+S+V'; A100 = uint8 (A100); figure: image (A100); 4. Find the size of A and use Equation (10) to calculate the amount of memory needed to store A. Keep in mind that each entry of A occupies 8 bits or 1 byte. Then use Equation (11) to calculate the amount of memory required to store the rank 100 approxima- tion. Determine the compression ratio for the rank 100 approximation According to your visual perception is A100 an acceptable approximation of A? What happens if you keep the 200 largest singular values? How much memory does A200 take up? Is A200 an acceptable approximation? What happens if you keep the 70 largest singular values? How much memory does A70 take up? Is A 70 an acceptable approximation? 4.3 Compression of Color Image Using the SVD 1. In Section 4.2 you compressed a black and white image using different rank approximations. In this exercise you will compress an RGB or color image. Download the file track.jpg from the course web page. Store the image in matrix and then display it using image. 2. Approximate B with rank 8, 32, and 128 matrices. For RGB images do it layer by layer: simply extend the ideas presented in Section 4.2 for monochrome images. Display the resulting approximations and comment on the quality of the images. Use subplot to show the original and approximate images in the same figure 4.4 Analysis of Compressed Images 1. The SVD of an Image Download the file bridge.jpg from the course web page. Read it into MATLAB and display it From the SVD of the image display a rank 1 approximation of the image. What can you say about the "columns" in the rank I approximation of the image in terms of linear dependence/independence? Does your image appear to agree that you indeed produced a rank 1 approximation? Next, reconstruct your image using the SVD of rank 2. 1.8.16, 32, 67, and 128. Using the command subplot, plot all these approximations along with the original image in the same window for an easy comparison 2. The Decay of the Singular Values Make a plot that shows how the singular values decay along the diagonal of the matrix in the Singular value decomposition A=UEVT How do the singular values decay for the image bridge.jpg? 11 3. Compression Error Using the SVD, approximate the image bridge.jpg with a rank 64 matrix. Compute the relative error using the Frobenius norm as defined in Equation (8). To find the Frobenius norm of an array M, type the MATLAB instruction norm(M,' fro'). Compare the relative errors between the images and discuss the results. 4. Compression Based on Visual Perception How much can you compress bridge.jpg using the SVD such that your compressed image is "almost" perfect based on your visual perception? How large did the rank need to be before it looked "natural" to your eyes? 3. Illustration of the Frobenius Norm Reconstruct bridge.jpg using two different methods: A rank 100 approximation . Using all but the first two singular values of the image. Compute the relative error in the Frobenius norm for both of the approximation. Does the result of the norm roughly agree with the error based on visual perception? 6. Compression Based on the Frobenius Norm For the image bridge.jpg, how large does the rank need to be so that the relative error (in the Frobenius norm) is less than 10%? MAIT GROES26

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

Step: 3

blur-text-image

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

Managerial Accounting An Introduction to Concepts Methods and Uses

Authors: Michael W. Maher, Clyde P. Stickney, Roman L. Weil

10th Edition

1111822239, 324639767, 9781111822231, 978-0324639766

More Books

Students also viewed these Accounting questions

Question

What are the pros and cons when 2 major restaurant chains merge?

Answered: 1 week ago