function varargout = decomposition_2D(varargin)
%DECOMPOSITION_2D M-file for decomposition_2D.fig
%      DECOMPOSITION_2D, by itself, creates a new DECOMPOSITION_2D or raises the existing
%      singleton*.
%
%      H = DECOMPOSITION_2D returns the handle to a new DECOMPOSITION_2D or the handle to
%      the existing singleton*.
%
%      DECOMPOSITION_2D('Property','Value',...) creates a new DECOMPOSITION_2D using the
%      given property value pairs. Unrecognized properties are passed via
%      varargin to decomposition_2D_OpeningFcn.  This calling syntax produces a
%      warning when there is an existing singleton*.
%
%      DECOMPOSITION_2D('CALLBACK') and DECOMPOSITION_2D('CALLBACK',hObject,...) call the
%      local function named CALLBACK in DECOMPOSITION_2D.M with the given input
%      arguments.
%
%      *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 decomposition_2D

% Last Modified by GUIDE v2.5 27-May-2014 10:01:42

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @decomposition_2D_OpeningFcn, ...
                   'gui_OutputFcn',  @decomposition_2D_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 decomposition_2D is made visible.
function decomposition_2D_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   unrecognized PropertyName/PropertyValue pairs from the
%            command line (see VARARGIN)

% Choose default command line output for decomposition_2D
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes decomposition_2D wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = decomposition_2D_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 push_decomposition.
function push_decomposition_Callback(hObject, eventdata, handles)
% hObject    handle to push_decomposition (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% original_picture = cellstr(get(handles.pop_obrazek,'String'));

global M;
global N;
image = cellstr(get(handles.pop_image,'String'));
image_id = get(handles.pop_image,'Value');

ridkost_k1 = str2double(get(handles.edit_k1,'String'));
ridkost_k2 = str2double(get(handles.edit_k2,'String'));

rozmer = cellstr(get(handles.pop_rozmer,'String'));
rozmer_id = (get(handles.pop_rozmer,'Value'));


original_picture = cellstr(get(handles.pop_obrazek,'String'));
original_picture_id = get(handles.pop_obrazek,'Value');


baze_1    = cellstr(get(handles.pop_baze_1,'String'));
baze_1_id = get(handles.pop_baze_1,'Value');
baze_2    = cellstr(get(handles.pop_baze_2,'String'));
baze_2_id = get(handles.pop_baze_2,'Value');

wavelet_1 = cellstr(get(handles.pop_wavelet_1,'String'));
wavelet_1_id = get(handles.pop_wavelet_1,'Value');
wavelet_2 = cellstr(get(handles.pop_wavelet_2,'String'));
wavelet_2_id = get(handles.pop_wavelet_2,'Value');

hloubka_decom_1 = str2double(get(handles.edit_decom_1,'String'));%handles    structure with handles and user data (see GUIDATA)
hloubka_decom_2 = str2double(get(handles.edit_decom_2,'String'));%handles    structure with handles and user data (see GUIDATA)

% volani funkce pro vypocet
[signal_in, signal_tex, signal_car, signal_out, psnr] = ... 
     decomposition_2D_impl(image{image_id}, ridkost_k1, ridkost_k2,str2double(rozmer{rozmer_id}), original_picture{original_picture_id}, baze_1{baze_1_id}, baze_2{baze_2_id},...
     wavelet_1{wavelet_1_id}, wavelet_2{wavelet_2_id}, hloubka_decom_1, hloubka_decom_2);


 
axes(handles.axes1);
imagesc(reshape(signal_in,M,N));
colormap(gray)
axis image
title('Puvodni obraz');
 
 
 axes(handles.axes2);
 
imagesc(reshape(signal_out,M,N));
colormap(gray)
axis image
title('Zpetne slozeny obraz');
 
 
 axes(handles.axes3);
imagesc(reshape(signal_tex,M,N));
colormap(gray)
axis image
colorbar
title('1. Komponenta ');
 
kontrola =  signal_car-signal_tex;

 axes(handles.axes4);
imagesc(reshape(signal_car,M,N));
colormap(gray)
colorbar
axis image
title('2. Komponenta');

 axes(handles.axes5);
imagesc(reshape(signal_in-signal_out,M,N));
colorbar
colormap(gray)
axis image
title('Rezidua: Original - Zpetne slozeni');
 
axes(handles.axes6);
imagesc(reshape(signal_in,M,N));
colorbar
colormap(gray)
axis image
title('Original - skala barev');
 set(handles.text_psnr,'String', ['PSNR = ' num2str(psnr) 'dB']);
 
 
 
% --- Executes on selection change in pop_wavelet_1.
function pop_wavelet_1_Callback(hObject, eventdata, handles)
% hObject    handle to pop_wavelet_1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = cellstr(get(hObject,'String')) returns pop_wavelet_1 contents as cell array
%        contents{get(hObject,'Value')} returns selected item from pop_wavelet_1


% --- Executes during object creation, after setting all properties.
function pop_wavelet_1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to pop_wavelet_1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu 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


% --- Executes on selection change in pop_baze_1.
function pop_baze_1_Callback(hObject, eventdata, handles)
% hObject    handle to pop_baze_1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

params = cellstr(get(hObject,'String'));
act_id = get(hObject, 'Value');
if(strcmp(params{act_id}, 'DCT'))
    set(handles.pop_wavelet_1,'Enable','off') ;
    set(handles.edit_decom_1,'Enable','off') ;
    
else
    set(handles.pop_wavelet_1,'Enable','on') ;
    set(handles.edit_decom_1,'Enable','on') ;
end


% --- Executes during object creation, after setting all properties.
function pop_baze_1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to pop_baze_1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu 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


% --- Executes on selection change in pop_baze_2.
function pop_baze_2_Callback(hObject, eventdata, handles)
% hObject    handle to pop_baze_2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = cellstr(get(hObject,'String')) returns pop_baze_2 contents as cell array
%        contents{get(hObject,'Value')} returns selected item from pop_baze_2
params = cellstr(get(hObject,'String'));
act_id = get(hObject, 'Value');
if(strcmp(params{act_id}, 'DCT'))
    set(handles.pop_wavelet_2,'Enable','off') ;
    set(handles.edit_decom_2,'Enable','off') ;
else
    set(handles.pop_wavelet_2,'Enable','on') ;
    set(handles.edit_decom_2,'Enable','on') ;
end


% --- Executes during object creation, after setting all properties.
function pop_baze_2_CreateFcn(hObject, eventdata, handles)
% hObject    handle to pop_baze_2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu 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 edit_decom_1_Callback(hObject, eventdata, handles)
% hObject    handle to edit_decom_1 (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 edit_decom_1 as text
%        str2double(get(hObject,'String')) returns contents of edit_decom_1 as a double


% --- Executes during object creation, after setting all properties.
function edit_decom_1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit_decom_1 (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


% --- Executes on selection change in pop_obrazek.
function pop_obrazek_Callback(hObject, eventdata, handles)
% hObject    handle to pop_obrazek (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = cellstr(get(hObject,'String')) returns pop_obrazek contents as cell array
%        contents{get(hObject,'Value')} returns selected item from pop_obrazek


% --- Executes during object creation, after setting all properties.
function pop_obrazek_CreateFcn(hObject, eventdata, handles)
% hObject    handle to pop_obrazek (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu 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




% --- Executes on selection change in pop_wavelet_2.
function pop_wavelet_2_Callback(hObject, eventdata, handles)
% hObject    handle to pop_wavelet_2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = cellstr(get(hObject,'String')) returns pop_wavelet_2 contents as cell array
%        contents{get(hObject,'Value')} returns selected item from pop_wavelet_2


% --- Executes during object creation, after setting all properties.
function pop_wavelet_2_CreateFcn(hObject, eventdata, handles)
% hObject    handle to pop_wavelet_2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu 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 edit_decom_2_Callback(hObject, eventdata, handles)
% hObject    handle to edit_decom_2 (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 edit_decom_2 as text
%        str2double(get(hObject,'String')) returns contents of edit_decom_2 as a double


% --- Executes during object creation, after setting all properties.
function edit_decom_2_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit_decom_2 (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 edit_k1_Callback(hObject, eventdata, handles)
% hObject    handle to edit_k1 (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 edit_k1 as text
%        str2double(get(hObject,'String')) returns contents of edit_k1 as a double


% --- Executes during object creation, after setting all properties.
function edit_k1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit_k1 (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


% --- Executes on selection change in pop_image.
function pop_image_Callback(hObject, eventdata, handles)
% hObject    handle to pop_image (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = cellstr(get(hObject,'String')) returns pop_image contents as cell array
%        contents{get(hObject,'Value')} returns selected item from pop_image
params = cellstr(get(hObject,'String'));
act_id = get(hObject, 'Value');
if(strcmp(params{act_id}, 'nahodny'))
    set(handles.pop_obrazek,'Enable','off') ;
    set(handles.pop_rozmer,'Enable','on') ;
    set(handles.edit_k1,'Enable','on') ;
    set(handles.edit_k2,'Enable','on') ;
else
    set(handles.pop_rozmer,'Enable','off') ;
    set(handles.edit_k1,'Enable','off') ;
    set(handles.edit_k2,'Enable','off') ;
    set(handles.pop_obrazek,'Enable','on') ;
end


% --- Executes during object creation, after setting all properties.
function pop_image_CreateFcn(hObject, eventdata, handles)
% hObject    handle to pop_image (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu 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


% --- Executes on selection change in pop_rozmer.
function pop_rozmer_Callback(hObject, eventdata, handles)
% hObject    handle to pop_rozmer (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = cellstr(get(hObject,'String')) returns pop_rozmer contents as cell array
%        contents{get(hObject,'Value')} returns selected item from pop_rozmer


% --- Executes during object creation, after setting all properties.
function pop_rozmer_CreateFcn(hObject, eventdata, handles)
% hObject    handle to pop_rozmer (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu 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 edit_k2_Callback(hObject, eventdata, handles)
% hObject    handle to edit_k2 (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 edit_k2 as text
%        str2double(get(hObject,'String')) returns contents of edit_k2 as a double


% --- Executes during object creation, after setting all properties.
function edit_k2_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit_k2 (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
