Question

In: Electrical Engineering

Use SVD method to compress and decompress images in the MATLAB. Compression function. The input is...

Use SVD method to compress and decompress images in the MATLAB.

Compression function. The input is an image file and k. The output is a text file containing the reduced U, V , and the reduced diagonals of ?.

Decompression function. The input is the output of the compression code. The output is an image (you can use imshow for this purpose).

Solutions

Expert Solution

Copy the following code. Enter an integer when promted for input. You can run this program for varous values of reduced vectors.

function svdImg()
global r;
global M;
r=input('Number of vectors for reconstruction');
%Reading input image
img = imread('coins.png');
figure,imshow(img,[]);
title('Original image');
[M,N] =size(img);
%Calling Compression function
[FilePath] = comprSvd(img);
%Decompression Code
recImg = deComprSvd(FilePath);

end
function [FilePath] = comprSvd(img)
%Compression function takes image as input,and produces a txt file as
%output
global r;
%Compute SVD
[U,S,V] = svd(double(img));
%Assign reduced vectors
Ur = U(:,1:r);
Sr = S(1:r,1:r);
Vr = V(:,1:r);
%File name
FilePath = 'coef.txt';
%Writing data file
dlmwrite(FilePath,[Ur;Sr;Vr]);
end
function imgRecon = deComprSvd(inptFilePath)
%Decompression function takes txtfile as input and produces the
%reconstructed image.
global r;
global M;
%Reading txt file
K = dlmread(inptFilePath);
%Assigning reduced vectors
Ur = K(1:M,:);
Sr = K(M+1:M+r,:);
Vr = K(M+r+1:end,:);
%Reconstructing image
imgRecon = Ur*Sr*Vr';
figure,imshow(imgRecon,[]);
title(['Reconstruction with ' num2str(r) ' singular values']);
end

Typical Output:

>> svdImg
Number of vectors for reconstruction30
>>

Output images:

The following are the reconstructed imagese with 50,100

It can be observed that the quality of the reconstructed image is increasing as the number of vectors is increasing


Related Solutions

What characteristics of the image matrix would be suitable for SVD compression technique (i.e., high compression...
What characteristics of the image matrix would be suitable for SVD compression technique (i.e., high compression rate).
I want to make picture compress program in matlab use eigenmatrix in RGB with PCA. This...
I want to make picture compress program in matlab use eigenmatrix in RGB with PCA. This code listed below. But this code is fail. I want to make the picture have a colour, but in my program the picture is still colorless. Can you fix my code? clc clear all picture = im2double(imread('picture1.jpg')); Red = picture(:,:,1); premean = mean(Red(:)); premax = max(Red(:)); premin = min(Red(:)); x = size(Red,1); y = size(Red,2); Z = ones(x,y)*premean; A = (Red - Z)*(1/premax -...
USE MATLAB Write a program in Matlab that would continuously ask the user for an input...
USE MATLAB Write a program in Matlab that would continuously ask the user for an input between 1 and 6, which would represent the result of rolling a die. The program would then generate a random integer between 1 and 6 and compare its value to the value entered by user. If the user’s die is larger, it should display, “Mahahanap mo na ang forever mo. Sana all!” If the user’s die is smaller, it should display, “Gising na friend,...
On Matlab use BFGS Method to find the minimum of the following function: f(x) = x13...
On Matlab use BFGS Method to find the minimum of the following function: f(x) = x13 - 2x2x12 + x12 - x1using initial point (x0, y0) = (1, 2)T to start, and stop when f changes less than 0.0001
write a matlab function for frequency analysis using DFT. the function should take as input a...
write a matlab function for frequency analysis using DFT. the function should take as input a signal, and as output the number of sinusoids and their frequencies.
A. Write a function in MATLAB called findTranspose that takes in as input any matrix or...
A. Write a function in MATLAB called findTranspose that takes in as input any matrix or any vector and simply returns back the transpose of that input. You can always verify your answer by using the inbuilt transpose function in MATLAB, however, you cannot use the transpose function directly when writing your code. Here is the starter code that we are providing to help you get started %x is the input vector or matrix. You can find the %size that...
Write a function in Matlab that takes as input the number n and a symmetric tridiagonal...
Write a function in Matlab that takes as input the number n and a symmetric tridiagonal matrix given as two vectors: n×1 vector v representing the main diagonal and (n−1)×1 vector w representing the upper diagonal. Have this function output the Cholesky factor of the matrix as a vector for the main diagonal and a vector for the upper diagonal and output the number of flops and, separately, the number of square roots used as well. Use only basic programming....
Matlab Create/write a function that takes an input of x and y data, and a string...
Matlab Create/write a function that takes an input of x and y data, and a string (either linear? or quadratic), sets up a linear system of equations (Ax = b), and solves and plots the model.
In matlab please. It says that not enough arguments. How, what, and where to input? function...
In matlab please. It says that not enough arguments. How, what, and where to input? function longestword (word1,word2,word3) if strlength(word1) > strlength(word2) && strlength(word1) > strlength(word3) fprintf(word1); elseif strlength(word2) > strlength(word1) && strlength(word2) > strlength(word3) fprintf(word2); else fprintf(word3) end end
Write one a MATLAB function that implements the Bisection method, Newton’s method and Secant Method (all...
Write one a MATLAB function that implements the Bisection method, Newton’s method and Secant Method (all in one function). Your function must have the following signature function output = solve(f,options) % your code here end where the input is • f: the function in f(x) =0. options: is a struct type with the following fields o method: bisection, newton or secant tol: the tolerance for stopping the iterations. maximum_iterations: the maximum number of iterations allowed. initial_guess: that is P_0; if...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT