Üye
[CODE title="DCT Image Compression Method"]function varargout = DCTCompressionMethod(varargin)
% DCTCOMPRESSIONMETHOD MATLAB code for DCTCompressionMethod.fig
% DCTCOMPRESSIONMETHOD, by itself, creates a new DCTCOMPRESSIONMETHOD or raises the existing
% singleton*.
%
% H = DCTCOMPRESSIONMETHOD returns the handle to a new DCTCOMPRESSIONMETHOD or the handle to
% the existing singleton*.
%
% DCTCOMPRESSIONMETHOD('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in DCTCOMPRESSIONMETHOD.M with the given input arguments.
%
% DCTCOMPRESSIONMETHOD('Property','Value',...) creates a new DCTCOMPRESSIONMETHOD or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before DCTCompressionMethod_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to DCTCompressionMethod_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help DCTCompressionMethod
% Last Modified by GUIDE v2.5 11-Mar-2018 16:18:54
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @DCTCompressionMethod_OpeningFcn, ...
'gui_OutputFcn', @DCTCompressionMethod_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
% End initialization code - DO NOT EDIT
% --- Executes just before DCTCompressionMethod is made visible.
function DCTCompressionMethod_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to DCTCompressionMethod (see VARARGIN)
% Choose default command line output for DCTCompressionMethod
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes DCTCompressionMethod wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = DCTCompressionMethod_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)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --- Executes on button press in Compress_btn.
function Compress_btn_Callback(hObject, eventdata, handles)
% hObject handle to Compress_btn (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global file_name;
[f,p] = uigetfile({'*.bmp;*.jpg;*.png;*.tiff;';'*.*'},'Select an Image File');
file_name = [p,f];
infilename = file_name;
img_orig = (imread(infilename));
img_orig = imresize(img_orig,[512,512]);
imwrite(img_orig,'dct_resized_original.JPG');
fileinfo = dir('dct_resized_original.JPG');
SIZE_original_bytes = fileinfo.bytes;
Size_original_kilobytes = SIZE_original_bytes/1024;
%
% im_info=imfinfo(infilename);
% SIZE_original_bytes = im_info.FileSize;
% Size_original_kilobytes = SIZE_original_bytes/1024;
set(handles.text7,'string',Size_original_kilobytes);
imshow(img_orig,'Parent', handles.axes1)
I1 = img_orig;
I = I1 ,:,1);
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);
B_Channel_1 = B2;
I2 = blkproc(B2,[8 8],'P1*x*P2',T',T);
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);
B_Channel_2 = B2;
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);
B_Channel_3 = B2;
I4 = blkproc(B2,[8 8],'P1*x*P2',T',T);
save DCT_Compressed_File.mat B_Channel_1 B_Channel_2 B_Channel_3
L ,:, =cat(3,I2, I3, I4);
imwrite(L,'CompressedDCTImage.JPG');
fileinfo = dir('CompressedDCTImage.JPG');
SIZE_comp_bytes = fileinfo.bytes;
Size_compress_kilobytes = SIZE_comp_bytes/1024;
set(handles.text9,'string',Size_compress_kilobytes);
imshow(L,'Parent', handles.axes2)
x = [Size_original_kilobytes,Size_compress_kilobytes];
axes(handles.axes3);
bar(x);
compression_ratio = (Size_compress_kilobytes / (Size_original_kilobytes) ) * 100;
set(handles.text10,'string',compression_ratio)
D = abs(double(I1)-double(L)).^2;
mse = sum(D ))/numel(I1);
psnr = 10*log10(255*255/mse);
compression_ratio_dct = compression_ratio;
mse_dct = mse;
psnr_dct = psnr;
set(handles.text11,'string',mse);
set(handles.text12,'string',psnr);
save DCT_parameters compression_ratio_dct mse_dct psnr_dct[/CODE]
% DCTCOMPRESSIONMETHOD MATLAB code for DCTCompressionMethod.fig
% DCTCOMPRESSIONMETHOD, by itself, creates a new DCTCOMPRESSIONMETHOD or raises the existing
% singleton*.
%
% H = DCTCOMPRESSIONMETHOD returns the handle to a new DCTCOMPRESSIONMETHOD or the handle to
% the existing singleton*.
%
% DCTCOMPRESSIONMETHOD('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in DCTCOMPRESSIONMETHOD.M with the given input arguments.
%
% DCTCOMPRESSIONMETHOD('Property','Value',...) creates a new DCTCOMPRESSIONMETHOD or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before DCTCompressionMethod_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to DCTCompressionMethod_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help DCTCompressionMethod
% Last Modified by GUIDE v2.5 11-Mar-2018 16:18:54
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @DCTCompressionMethod_OpeningFcn, ...
'gui_OutputFcn', @DCTCompressionMethod_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
% End initialization code - DO NOT EDIT
% --- Executes just before DCTCompressionMethod is made visible.
function DCTCompressionMethod_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to DCTCompressionMethod (see VARARGIN)
% Choose default command line output for DCTCompressionMethod
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes DCTCompressionMethod wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = DCTCompressionMethod_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)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --- Executes on button press in Compress_btn.
function Compress_btn_Callback(hObject, eventdata, handles)
% hObject handle to Compress_btn (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global file_name;
[f,p] = uigetfile({'*.bmp;*.jpg;*.png;*.tiff;';'*.*'},'Select an Image File');
file_name = [p,f];
infilename = file_name;
img_orig = (imread(infilename));
img_orig = imresize(img_orig,[512,512]);
imwrite(img_orig,'dct_resized_original.JPG');
fileinfo = dir('dct_resized_original.JPG');
SIZE_original_bytes = fileinfo.bytes;
Size_original_kilobytes = SIZE_original_bytes/1024;
%
% im_info=imfinfo(infilename);
% SIZE_original_bytes = im_info.FileSize;
% Size_original_kilobytes = SIZE_original_bytes/1024;
set(handles.text7,'string',Size_original_kilobytes);
imshow(img_orig,'Parent', handles.axes1)
I1 = img_orig;
I = I1
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);
B_Channel_1 = B2;
I2 = blkproc(B2,[8 8],'P1*x*P2',T',T);
I = I1
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);
B_Channel_2 = B2;
I3 = blkproc(B2,[8 8],'P1*x*P2',T',T);
I = I1
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);
B_Channel_3 = B2;
I4 = blkproc(B2,[8 8],'P1*x*P2',T',T);
save DCT_Compressed_File.mat B_Channel_1 B_Channel_2 B_Channel_3
L
imwrite(L,'CompressedDCTImage.JPG');
fileinfo = dir('CompressedDCTImage.JPG');
SIZE_comp_bytes = fileinfo.bytes;
Size_compress_kilobytes = SIZE_comp_bytes/1024;
set(handles.text9,'string',Size_compress_kilobytes);
imshow(L,'Parent', handles.axes2)
x = [Size_original_kilobytes,Size_compress_kilobytes];
axes(handles.axes3);
bar(x);
compression_ratio = (Size_compress_kilobytes / (Size_original_kilobytes) ) * 100;
set(handles.text10,'string',compression_ratio)
D = abs(double(I1)-double(L)).^2;
mse = sum(D
psnr = 10*log10(255*255/mse);
compression_ratio_dct = compression_ratio;
mse_dct = mse;
psnr_dct = psnr;
set(handles.text11,'string',mse);
set(handles.text12,'string',psnr);
save DCT_parameters compression_ratio_dct mse_dct psnr_dct[/CODE]
Moderatörün son düzenlenenleri: