NIM : 1941160036
Jawaban
1. - Metode Run Length Encoding (RLE)
Metode ini digunakan untuk mengompresi citra yang memiliki kelompok-kelompok
pixel yang berderajat keabuan yang sama. Kompresi citra dengan metode Run Length
Encoding dilakukan dengan membuat rangkaian pasangan nilai (P,Q) untuk setiap
baris pixel, dimana nilai P menyatakan nilai derajat keabuan, sedangkan nilai Q
menyatakan jumlah pixel berurutan yang memiliki derajat keabuan tersebut.
- Metode Huffman
Metode Huffman merupakan salah satu teknik kompresi dengan cara melakukan
pengkodean dalam bentuk bit untuk mewakili data karakter.
- Metode Kuantisasi
Metode ini bekerja dengan cara mengurangi derajat keabuan, sehingga jumlah bit
yang dibutuhkan untuk merepresentasikan citra berkurang. Akibatnya secara visual
kualitas citra menjadi jelek. Oleh karena itu metode ini termasuk dalam loossy
compression, sehingga citra yang sudah dikompresi sulit didekompresi kembali
karena adanya informasi yang hilang.
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Outputs from this function are returned to the command line.
function varargout = ImageCompression1_OutputFcn(hObject, eventdata,
handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
I = I1(:,:,2);
I = im2double(I);
T = dctmtx(8);
B = blkproc(I,[8 8],'P1*x*P2',T,T');
mask = [1 1 1 1 0 0 0 0
1 1 1 0 0 0 0 0
1 1 0 0 0 0 0 0
1 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0];
B2 = blkproc(B,[8 8],'P1.*x',mask);
I3 = blkproc(B2,[8 8],'P1*x*P2',T',T);
I = I1(:,:,3);
I = im2double(I);
T = dctmtx(8);
B = blkproc(I,[8 8],'P1*x*P2',T,T');
mask = [1 1 1 1 0 0 0 0
1 1 1 0 0 0 0 0
1 1 0 0 0 0 0 0
1 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0];
B2 = blkproc(B,[8 8],'P1.*x',mask);
I4 = blkproc(B2,[8 8],'P1*x*P2',T',T);
fileinfo = dir('kompresi.jpg');
SIZE = fileinfo.bytes;
Size = SIZE/1024;
set(handles.text8,'string',Size);
imshow(L,'Parent', handles.axes2)
end
- hasil gambar
3. Script
clear all;
close all;
clc;
[file1]=uigetfile('*.txt');
p=file1;
t=sprintf('%s',p);
b1=dlmread([file1]);
len=length(b1);
%lead=str2double(lead);
col2=b1(1:end,lead);
e=fix(sqrt(len));
m=1;
for i=1:e
for j=1:e
m=m+1;
end
end
g3=g2;
for i=1:e
for j=1:e
if(g3(i,j)<0)
g3(i,j)=(g3(i,j))*(-1);
end
end
end
max_term=g3(1,1);
for i=1:e
for j=1:e
if(g3(i,j)>max_term)
max_term=g3(i,j);
end
end
end
time=b1(1:end,1)*1000;
plot(time,col2);
title(string);
%title('Input ECG Signal:t');
grid on;
fid=fopen('inputfile.txt','w+');
cnt2=fwrite(fid,col2);
fclose(fid);
%%%%%%A%%%%%%%%%%%%%%%%%%%%%%%
a=g3;
I=a;
[m,n]=size(I);
Totalcount=m*n;
cnt=1;
sigma=0;
k=I==i;
count(cnt)=sum(k(:))
pro(cnt)=count(cnt)/Totalcount;
sigma=sigma+pro(cnt);
cumpro(cnt)=sigma;
cnt=cnt+1;
end;
symbols = [0:max_term];
dict = huffmandict(symbols,pro);
vec_size = 1;
for p = 1:m
for q = 1:n
newvec(vec_size) = I(p,q);
vec_size = vec_size+1;
end
end
%Huffman Encodig
hcode = huffmanenco(newvec,dict);
%Huffman Decoding
dhsig1 = huffmandeco(hcode,dict);
dhsig = uint8(dhsig1);
dec_row=sqrt(length(dhsig));
dec_col=dec_row;
arr_row = 1;
arr_col = 1;
vec_si = 1;
for x = 1:m
for y = 1:n
back(x,y)=dhsig(vec_si);
arr_col = arr_col+1;
vec_si = vec_si + 1;
end
arr_row = arr_row+1;
end
z=b1(1:end,1)*750;
RGB = ind2rgb(deco,map);
figure,subplot(1,2,1),title('original graph'),...
subplot(1,2,1),plot(b1,col2),xlabel('Time / s');
figure,subplot(1,2,1),plot(time,col2),xlabel('Time / s');
% subplot(2,2,3),imshow((b1)),title('compressed graph');
% K=imfinfo('original.jpg');
% size_of_file=K.FileSize
%K=imfinfo('compressed.jpg');
%size_of_file=K.FileSize
%K=imfinfo('fdr.jpg');
%size_of_file=K.FileSize
disp(bytes(p));
cnt=fwrite(fid,q);
fclose(fid);
disp(bytes('comp1.txt'));
fid=fopen('recons1.txt','w+');
cnt1=fwrite(fid,pro);
fclose(fid);
disp(bytes(pro));
for i=1:e
y3(i)=ecg(i)- main_t(i);
y4(i)=(y3(i).^2);
% y5=sum(y4(i));
y5(i)=(ecg(i).^2);
end
y6=sum(y4)/sum(y5);
prd=sqrt(y6);
disp(prd);
b0=bytes(p);
b1=bytes('comp1.txt');
CR1=b0/b1;
CR=100/CR1;
disp(CR);
disp('QUALITY SCORE');
c=double(CR);
d=double(prd);
qs=double(c/(d*100));
disp(qs);
- Gambar
Dekompres
Dekompres
Jadi perbedaannya adalah file kompres memiliki bite yang kecil dibandingkan file dekompres
dan file kompres sedikit lebih buram Glitchi.