Clear CLC U Imread Figure Imagesc (U) Colormap (Gray) Title

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

Homework

Image Compression
g201279600
clear
clc
u = imread("peppers256.png");
figure; imagesc(u);colormap(gray);title('origina

N = size(u,1);
%FFT2 and plot
u_hat = fft2(u);
u_hat1 = log(abs(u_hat));
%compress
ind = 8 < u_hat1 ;%< 10.000001;
1
u_hat2 = mat2gray(ind).*u_hat1;
ind_d = double(ind);
ind_z = sparse(ind_d);
u_hat_low = ind_d.*double(u_hat);
%IFFT2 and display
u2 = ifft2(u_hat_low);
u3 =mat2gray(u2);
figure; imagesc(u3);colormap(gray);title(' Compr
%Calculate percintage
[i,j,s] = find(ind_z);
perc = 100*length(i)/N^2
perc = 26.5213
title(['percentage =',num2str(perc),'%'])

2
3

You might also like