function
varargout = kompresi_citra(varargin)
gui_Singleton = 1;
gui_State = struct(
'gui_Name'
, mfilename, ...
'gui_Singleton'
, gui_Singleton, ...
'gui_OpeningFcn'
, @kompresi_citra_OpeningFcn, ...
'gui_OutputFcn'
, @kompresi_citra_OutputFcn, ...
'gui_LayoutFcn'
, [] , ...
'gui_Callback'
, []);
if
nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if
nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
function
kompresi_citra_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
guidata(hObject, handles);
movegui(hObject,
'center'
);
function
varargout = kompresi_citra_OutputFcn(hObject, eventdata, handles)
varargout{1} = handles.output;
function
edit4_Callback(hObject, eventdata, handles)
function
edit4_CreateFcn(hObject, eventdata, handles)
if
ispc && isequal(get(hObject,
'BackgroundColor'
), get(0,
'defaultUicontrolBackgroundColor'
))
set(hObject,
'BackgroundColor'
,
'white'
);
end
function
edit3_Callback(hObject, eventdata, handles)
function
edit3_CreateFcn(hObject, eventdata, handles)
if
ispc && isequal(get(hObject,
'BackgroundColor'
), get(0,
'defaultUicontrolBackgroundColor'
))
set(hObject,
'BackgroundColor'
,
'white'
);
end
function
pushbutton1_Callback(hObject, eventdata, handles)
[file, path] = uigetfile({
'*.bmp;*.jpg;*.png;*.tiff;'
;
'*.*'
},...
'Select an Image File'
);
if
~isequal(file,0)
Img = im2double(imread(fullfile(path,file)));
fileinfo = imfinfo(file);
SIZE = fileinfo.FileSize;
Size = SIZE/1024;
set(handles.edit3,
'String'
,[num2str(Size),
' kb'
]);
imshow(Img,
'Parent'
, handles.axes1)
handles.Img = Img;
handles.fileinfo = fileinfo;
guidata(hObject, handles)
axes(handles.axes2)
cla reset
set(gca,
'XTick'
,[])
set(gca,
'YTick'
,[])
set(handles.pushbutton2,
'Enable'
,
'on'
)
set(handles.pushbutton3,
'Enable'
,
'off'
)
set(handles.edit1,
'String'
,[])
set(handles.edit2,
'String'
,[])
set(handles.edit4,
'String'
,[])
set(handles.edit5,
'String'
,[])
else
return
end
function
pushbutton2_Callback(hObject, eventdata, handles)
Img = handles.Img;
fileinfo = handles.fileinfo;
Img_comp = zeros(size(Img));
for
n = 1:3
I = im2double(Img(:,:,n));
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);
Img_comp(:,:,n) = blkproc(B2,[8 8],
'P1*x*P2'
,T',T);
end
file_comp = [
'Hasil Kompresi.'
,fileinfo.Format];
imwrite(Img_comp,file_comp);
fileinfo_comp = imfinfo(file_comp);
SIZE = fileinfo_comp.FileSize;
Size = SIZE/1024;
set(handles.edit4,
'string'
,[num2str(Size),
' kb'
]);
imshow(Img_comp,
'Parent'
,handles.axes2)
set(handles.pushbutton3,
'Enable'
,
'on'
)
set(handles.edit1,
'String'
,[])
set(handles.edit2,
'String'
,[])
set(handles.edit5,
'String'
,[])
handles.Img_comp = Img_comp;
handles.fileinfo_comp = fileinfo_comp;
guidata(hObject, handles)
function
edit1_Callback(hObject, eventdata, handles)
function
edit1_CreateFcn(hObject, eventdata, handles)
if
ispc && isequal(get(hObject,
'BackgroundColor'
), get(0,
'defaultUicontrolBackgroundColor'
))
set(hObject,
'BackgroundColor'
,
'white'
);
end
function
edit2_Callback(hObject, eventdata, handles)
function
edit2_CreateFcn(hObject, eventdata, handles)
if
ispc && isequal(get(hObject,
'BackgroundColor'
), get(0,
'defaultUicontrolBackgroundColor'
))
set(hObject,
'BackgroundColor'
,
'white'
);
end
function
pushbutton3_Callback(hObject, eventdata, handles)
Img = handles.Img;
fileinfo = handles.fileinfo;
Img_comp = handles.Img_comp;
fileinfo_comp = handles.fileinfo_comp;
nilai_psnr = psnr(Img,Img_comp);
nilai_mse = mean(mse(Img,Img_comp));
filesize = fileinfo.FileSize;
filesize_comp = fileinfo_comp.FileSize;
persen_kompresi = filesize_comp/filesize*100;
set(handles.edit1,
'String'
,nilai_psnr)
set(handles.edit2,
'String'
,nilai_mse)
set(handles.edit5,
'String'
,persen_kompresi)
function
pushbutton4_Callback(hObject, eventdata, handles)
axes(handles.axes1)
cla reset
set(gca,
'XTick'
,[])
set(gca,
'YTick'
,[])
axes(handles.axes2)
cla reset
set(gca,
'XTick'
,[])
set(gca,
'YTick'
,[])
set(handles.pushbutton2,
'Enable'
,
'off'
)
set(handles.pushbutton3,
'Enable'
,
'off'
)
set(handles.edit1,
'String'
,[])
set(handles.edit2,
'String'
,[])
set(handles.edit3,
'String'
,[])
set(handles.edit4,
'String'
,[])
set(handles.edit5,
'String'
,[])
function
edit5_Callback(hObject, eventdata, handles)
function
edit5_CreateFcn(hObject, eventdata, handles)
if
ispc && isequal(get(hObject,
'BackgroundColor'
), get(0,
'defaultUicontrolBackgroundColor'
))
set(hObject,
'BackgroundColor'
,
'white'
);
end
Komentar
Posting Komentar