function varargout = GUI(varargin)
% GUI MATLAB code for GUI.fig
% GUI, by itself, creates a new GUI or raises the existing
% singleton*.
%
% H = GUI returns the handle to a new GUI or the handle to
% the existing singleton*.
%
% GUI('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in GUI.M with the given input arguments.
%
% GUI('Property','Value',...) creates a new GUI or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before GUI_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to GUI_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 GUI
% Last Modified by GUIDE v2.5 14-Jul-2017 12:35:54
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @GUI_OpeningFcn, ...
'gui_OutputFcn', @GUI_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 GUI is made visible.
function GUI_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 GUI (see VARARGIN)
% Choose default command line output for GUI
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes GUI wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = GUI_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 xingcheng.
function xingcheng_Callback(hObject, eventdata, handles)
% hObject handle to xingcheng (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
I=imread('C:\Users\Admin\Desktop\chepail.bmp');
image1=im2bw(I,0.43);
axes(handles.axes5);
imshow(I);
X=image1(:); %令X为新建的二值图像的一维数据组
x=1:1:length(X); % 编码之前的图像数据
plot(handles.axes6,x,X(x));
% 游程编码程序段
j=1;
image4(1)=1;
for z=1:1:(length(X)-1)
if (X(z)==X(z+1))
image4(j)=image4(j)+1;
else data(j)=X(z);
j=j+1;
image4(j)=1;
end
end
data(j)=X(length(X));
image4length=length(image4); % 计算游程编码后的所占字节数
H=length(x);
%y=1:1:image4length ;
CR1=H/image4length; % 压缩比
% 游程编码解压
i=1;
for m=1:image4length
for n=1:1:image4(m);
rec_image(i)=data(m);
i=i+1;
end
end
u=1:1:length(rec_image); % 解压后的图像数据
plot(handles.axes7,u,rec_image(u));
rec2_image=reshape(rec_image,32,115); % 重建二维二维图像数组
axes(handles.axes8);
imshow(rec2_image);
handles.text4 = CR1;
set(handles.edit4,'string',CR1);
% --- Executes on button press in DCT.
function DCT_Callback(hObject, eventdata, handles)
% hObject handle to DCT (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
RGB=imread('C:\Users\Admin\Desktop\chepail.bmp');
R=RGB(:,:,1);
G=RGB(:,:,2);
B=RGB(:,:,3);
axes(handles.axes1);
imshow(RGB);
Y=0.299*double(R)+0.587*double(G)+0.114*double(B);
U=-0.169*double(R)-0.3316*double(G)+0.5*double(B);
V=0.5*double(R)-0.4186*double(G)-0.0813*double(B);
axes(handles.axes2);
imshow(uint8(Y));
T=dctmtx(8);
BY=blkproc(Y,[8 8],'P1*x*P2',T,T');
BU=blkproc(U,[8 8],'P1*x*P2',T,T');
BV=blkproc(V,[8 8],'P1*x*P2',T,T');
a= [16 11 10 16 24 40 51 61;
12 12 14 19 26 58 60 55;
14 13 16 24 40 57 69 55;
14 17 22 29 51 87 80 62;
18 22 37 56 68 109 103 77;
24 35 55 64 81 104 113 92;
49 64 78 87 103 121 120 101;
72 92 95 98 112 100 103 99;]; %量化值
b=[ 17 18 24 47 99 99 99 99;
18 21 26 66 99 99 99 99;
24 26 56 99 99 99 99 99;
47 66 99 99 99 99 99 99;
99 99 99 99 99 99 99 99;
99 99 99 99 99 99 99 99;
99 99 99 99 99 99 99 99;
99 99 99 99 99 99 99 99;];
BY2=blkproc(BY,[8 8],'x./P1',a);
BU2=blkproc(BU,[8 8],'x./P1',b);
BV2=blkproc(BV,[8 8],'x./P1',b);
BY3=int8(BY2);
BU3=int8(BU2);
BV3=int8(BV2);
BY4=blkproc(double(BY3),[8 8],'x.*P1',a);
BU4=blkproc(double(BU3),[8 8],'x.*P1',b);
BV4=blkproc(double(BV3),[8 8],'x.*P1',b);
mask=[
1 1 1 1 1 0 0 0;
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;];
BY5=blkproc(BY4,[8 8],'P1.*x',mask);
BU5=blkproc(BU4,[8 8],'P1.*x',mask);
BV5=blkproc(BV4,[8 8],'P1.*x',mask);
YI=blkproc(double(BY5),[8 8],'P1*x*P2',T',T);
UI=blkproc(double(BU5),[8 8],'P1*x*P2',T',T);
VI=blkproc(double(BV5),[8 8],'P1*x*P2',T',T);
axes(handles.axes3);
imshow(uint8(YI));
RI=YI-0.001*UI+1.402*VI;
GI=YI-0.344*UI-0.714*VI;
BI=YI+1.772*UI+0.001*VI;
RGBI=cat(3,RI,GI,BI);%经过DCT变换和量化后的YUV图像
RGBI=uint8(RGBI);
axes(handles.axes4);
imshow(RGBI);
I = RGBI;
[M,N] = size(I);
I1 = I(:);
P = zeros(1,256);
%获取各符号的概率;
for i = 0:255
P(i+1) = length(find(I1 == i))/(M*N);
end
k = 0:255;
dict = huffmandict(k,P); %生成字典
enco = huffmanenco(I1,dict); %编码
deco = huffmandeco(enco,dict); %解码
Ide = col2im(deco,[M,N],[32,115],'distinct'); %把向量重新转换成图像块;
handles.axes4 = imshow(uint8(Ide));
CR=length(enco)/length(deco);
set(handles.edit3,'string',CR);
function edit3_Callback(hObject, eventdata, handles)
% hObject handle to edit3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit3 as text
% str2double(get(hObject,'String')) returns contents of edit3 as a double
% --- Executes during object creation, after setting all properties.
function edit3_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit4_Callback(hObject, eventdata, handles)
% hObject handle to edit4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit4 as text
% str2double(get(hObject,'String')) returns contents of edit4 as a double