function varargout = signal_dequanting_2D(varargin)
% SIGNAL_DEQUANTING_2D MATLAB code for signal_dequanting_2D.fig
%      SIGNAL_DEQUANTING_2D, by itself, creates a new SIGNAL_DEQUANTING_2D or raises the existing
%      singleton*.
%
%      H = SIGNAL_DEQUANTING_2D returns the handle to a new SIGNAL_DEQUANTING_2D or the handle to
%      the existing singleton*.
%
%      SIGNAL_DEQUANTING_2D('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in SIGNAL_DEQUANTING_2D.M with the given input arguments.
%
%      SIGNAL_DEQUANTING_2D('Property','Value',...) creates a new SIGNAL_DEQUANTING_2D or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before signal_dequanting_2D_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to signal_dequanting_2D_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 signal_dequanting_2D

% Last Modified by GUIDE v2.5 28-May-2014 15:03:34

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @signal_dequanting_2D_OpeningFcn, ...
                   'gui_OutputFcn',  @signal_dequanting_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 signal_dequanting_2D is made visible.
function signal_dequanting_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   command line arguments to signal_dequanting_2D (see VARARGIN)

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

% Update handles structure
guidata(hObject, handles);

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


% --- Outputs from this function are returned to the command line.
function varargout = signal_dequanting_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 kvantovat.
function kvantovat_Callback(hObject, eventdata, handles)
% hObject    handle to kvantovat (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
clc;
global M;
global N;
global delta;
global rozdeleni;

image = cellstr(get(handles.pop_imag,'String'));
image_id = get(handles.pop_imag,'Value');

ridkost = str2double(get(handles.edit_ridkost,'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    = cellstr(get(handles.pop_baze,'String'));
baze_id = get(handles.pop_baze,'Value');
wavelet = cellstr(get(handles.pop_wavelet,'String'));
wavelet_id = get(handles.pop_wavelet,'Value');

hloubka_decom = str2double(get(handles.edit_decom,'String'));
pocet_hladin = str2double(get(handles.edit_kvant_hlad,'String'));

% volani funkce pro vypocet
[signal_in, signal_kvant, signal_out, signal_kvant_out,  psnr, psnr_ok, psnr_kvant] = ... 
     signal_dequanting2D_impl(image{image_id}, ridkost, str2double(rozmer{rozmer_id}),original_picture{original_picture_id},...
     baze{baze_id}, wavelet{wavelet_id}, hloubka_decom, pocet_hladin); 

P = unique(signal_out(:)); 
E = unique(signal_in);

axes(handles.axes1);
imagesc(reshape(signal_in,M,N));
colormap(gray)
axis image
title('Originalni obraz');

axes(handles.axes2);
imagesc(reshape(signal_kvant,M,N));
colormap(gray)
axis image
title('Kvantovany obraz');
 
axes(handles.axes3);
imagesc(reshape(signal_out,M,N));
colormap(gray)
axis image
title('Rekonstrukce');
 
 axes(handles.axes4);
 imagesc(E');
 colormap(gray)
 title('puvodni - skala hodnot');
 
  
 axes(handles.axes5);
 imagesc(rozdeleni);
 colormap(gray)
 title('kvantovany - skala hodnot');
 
  
  axes(handles.axes6);
  imagesc(P');
  colormap(gray)
  title('R');
  title(' rekonstrukce - skala hodnot');
 
 
  axes(handles.axes7);
  imagesc((reshape(signal_in - signal_kvant,M,N)));
  colormap(gray)
  colorbar
  title('Rezidua: puvodni obraz vs. rekonstrukce');
  
  axes(handles.axes9);
  imagesc(reshape(signal_kvant-signal_kvant_out,M,N));
  colormap(gray)
  colorbar
  title('Rezidua: kvant.original vs. kvant.rekonstrukce');

  axes(handles.axes8);
  imagesc(reshape(signal_kvant_out,M,N));
  colormap(gray)
  colorbar
  title('Kvantovana rekonstrukce');
 

set(handles.text_psnr,'String', ['PSNR = ' num2str(psnr) 'dB']);
set(handles.text_psnr_o_k,'String', ['PSNR_OK = ' num2str(psnr_ok) 'dB']);
set(handles.text_psnr_kvant,'String', ['PSNR_kvant = ' num2str(psnr_kvant) 'dB']);
set(handles.text_delta,'String', ['Sirka kvant. hladiny = ' num2str(delta)]);



% --- Executes on selection change in pop_wavelet.
function pop_wavelet_Callback(hObject, eventdata, handles)
% hObject    handle to pop_wavelet (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 contents as cell array
%        contents{get(hObject,'Value')} returns selected item from pop_wavelet



% --- Executes during object creation, after setting all properties.
function pop_wavelet_CreateFcn(hObject, eventdata, handles)
% hObject    handle to pop_wavelet (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.
function pop_baze_Callback(hObject, eventdata, handles)
% hObject    handle to pop_baze (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 contents as cell array
%        contents{get(hObject,'Value')} returns selected item from pop_baze
params = cellstr(get(hObject,'String'));
act_id = get(hObject, 'Value');
if(strcmp(params{act_id}, 'DCT'))
    set(handles.pop_wavelet,'Enable','off') ;
else
    set(handles.pop_wavelet,'Enable','on') ;
end


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


% --- Executes during object creation, after setting all properties.
function edit_decom_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit_decom (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 popupmenu7.
function popupmenu7_Callback(hObject, eventdata, handles)
% hObject    handle to popupmenu7 (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 popupmenu7 contents as cell array
%        contents{get(hObject,'Value')} returns selected item from popupmenu7


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


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



function edit_ridkost_Callback(hObject, eventdata, handles)
% hObject    handle to edit_ridkost (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_ridkost as text
%        str2double(get(hObject,'String')) returns contents of edit_ridkost as a double


% --- Executes during object creation, after setting all properties.
function edit_ridkost_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit_ridkost (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_image_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
% 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_ridkost,'Enable','on') ;
%    
% else
%     set(handles.pop_rozmer,'Enable','off') ;
%     set(handles.edit_ridkost,'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_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_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




% --- Executes on selection change in pop_wavelet.
function popupmenu16_Callback(hObject, eventdata, handles)
% hObject    handle to pop_wavelet (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 contents as cell array
%        contents{get(hObject,'Value')} returns selected item from pop_wavelet


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


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


% --- Executes during object creation, after setting all properties.
function edit5_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit5 (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 popupmenu9.
function popupmenu9_Callback(hObject, eventdata, handles)
% hObject    handle to popupmenu9 (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 popupmenu9 contents as cell array
%        contents{get(hObject,'Value')} returns selected item from popupmenu9


% --- Executes during object creation, after setting all properties.
function popupmenu9_CreateFcn(hObject, eventdata, handles)
% hObject    handle to popupmenu9 (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 popupmenu11.
function popupmenu11_Callback(hObject, eventdata, handles)
% hObject    handle to popupmenu11 (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 popupmenu11 contents as cell array
%        contents{get(hObject,'Value')} returns selected item from popupmenu11


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


% --- Executes during object creation, after setting all properties.
function edit6_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit6 (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_imag.
function pop_imag_Callback(hObject, eventdata, handles)
% hObject    handle to pop_imag (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_imag contents as cell array
%        contents{get(hObject,'Value')} returns selected item from pop_imag
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_ridkost,'Enable','on') ;
   
else
    set(handles.pop_rozmer,'Enable','off') ;
    set(handles.edit_ridkost,'Enable','off') ;
    set(handles.pop_obrazek,'Enable','on') ;
end

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