function varargout = jpeg(varargin)
% JPEG MATLAB code for jpeg.fig
% JPEG, by itself, creates a new JPEG or raises the existing
% singleton*.
%
% H = JPEG returns the handle to a new JPEG or the handle to
% the existing singleton*.
%
% JPEG('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in JPEG.M with the given input arguments.
%
% JPEG('Property','Value',...) creates a new JPEG or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before jpeg_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to jpeg_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 jpeg
% Last Modified by GUIDE v2.5 20-May-2015 22:09:36
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @jpeg_OpeningFcn, ...
'gui_OutputFcn', @jpeg_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 jpeg is made visible.
function jpeg_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 jpeg (see VARARGIN)
% Choose default command line output for jpeg
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes jpeg wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = jpeg_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 radiobutton1.
function radiobutton1_Callback(hObject, eventdata, handles)
% hObject handle to radiobutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of radiobutton1
global flag;
flag=0;
% --- Executes on button press in radiobutton2.
function radiobutton2_Callback(hObject, eventdata, handles)
% hObject handle to radiobutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of radiobutton2
global flag;
flag=1;
% --- Executes on button press in chonanh.
function chonanh_Callback(hObject, eventdata, handles)
% hObject handle to chonanh (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[FileName,PathName]=uigetfile({'*.tif;*.bmp;*.gif;*.jpg'},'pick an image file');
s=imread([PathName,FileName]); %doc file anh
handles.s=s;
axes(handles.anh1); %hien thi anh
imshow(s);
guidata(hObject,handles);
% --- Executes on button press in nen.
function nen_Callback(hObject, eventdata, handles)
% hObject handle to nen (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global heso;
global flag;
%global fun;
%global invdct;
s=handles.s; %lay anh
axes(handles.anh2);
j=get(handles.edit3, 'string');
j1=str2num(j);
heso = cast(j1, 'int8');
if(isinteger(heso) & (heso<9) & (heso>0)) == false
disp('nhap vao so tu 1-8');
%heso = cast(str2double(get(handles.edit3)), 'int8'); %lay gia tri int8 tu edit3
%if ((heso<9) & (heso>0)) == false
% disp('nhap vao 1-8');
else
T=dctmtx(8); %ma tran dct 8x8
fun = @(x)(T*x*T'); %ham chuyen doi cosin
mask=zeros(8); %tao ma tran zero 8x8
invdct=@(x)(T'*x*T); %ham chuyen doi nguoc
end
if flag==0
s1=0.299.*s(:,:,1)+ 0.587.*s(:,:,2)+ 0.114.*s(:,:,3);
I=im2double(s1);
B=blkproc(I, [8 8], fun); %su ly khoi 8x8
mask(1:heso, 1:heso)=1; %tao ma tran mask
B2=blkproc(B, [8 8], @(x)(mask.*x));
I2=blkproc(B2, [8 8], invdct);
imshow(I2);
handles.B2=B2;
handles.B=B;
handles.I=I;
handles.I2=I2;
elseif flag~=0
I=im2double(s);
for k=1:3
B(:,:,k)=blkproc(I(:,:,k), [8 8], fun); %su ly khoi 8x8 cho 3 thanh phan anh
mask(1:heso , 1:heso)=1;
app=B(:,:,k);
B2(:,:,k)=blkproc(app, [8 8], @(x)(mask.*x));
I2(:,:,k)=blkproc(B2(:,:,k), [8 8], invdct);
end
imshow(I2);
handles.I2=I2;
handles.I=I;
handles.B=B;
end
guidata(hObject,handles);
% --- Executes on button press in tyle.
function tyle_Callback(hObject, eventdata, handles)
% hObject handle to tyle (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
s=handles.s;
B=handles.B;
%[x,y,z]=size(B2);
z1=numel(s);
z2=numel(B);
cr = z1/z2;
set(handles.edit1, 'string', num2str(cr));
set(handles.edit2, 'string', num2str(y));
% --- Executes on button press in tyso.
function tyso_Callback(hObject, eventdata, handles)
% hObject handle to tyso (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
function edit2_Callback(hObject, eventdata, handles)
% hObject handle to edit2 (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 edit2 as text
% str2double(get(hObject,'String')) returns contents of edit2 as a double
% --- Executes during object creation, after setting all properties.
function edit2_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit2 (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 edit1_Callback(hObject, eventdata, handles)
% hObject handle to edit1 (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 edit1 as text
% str2double(get(hObject,'String')) returns contents of edit1 as a doub