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

% Last Modified by GUIDE v2.5 19-May-2012 11:57:24

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @srGUI_OpeningFcn, ...
                   'gui_OutputFcn',  @srGUI_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 srGUI is made visible.
function srGUI_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 srGUI (see VARARGIN)

         handles.HIm = 0;
         guidata(hObject,handles);

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

% Update handles structure
guidata(hObject, handles);

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


% --- Outputs from this function are returned to the command line.
function varargout = srGUI_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 startButton.
function startButton_Callback(hObject, eventdata, handles)
% hObject    handle to startButton (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% fname = 'Data/Test/L1SR.bmp';
% img = imread(fname);
% axes(handles.axes2);
% imagesc(img);
% axis off;

met=get (handles.metoda,'Value');
%set(handles.slovnik,'String',met);
if met == 1
         set(handles.slovnik,'String',' ');
         set(handles.met,'String','Nejbližší soused');
         A = handles.obrazek;
         B = imresize(A,1/3, 'bicubic');
         axes(handles.axes3);
         imagesc(B);colormap(gray);
         axis off;
         B = imresize(B,3, 'nearest');
         axes(handles.axes2);
         imagesc(B);colormap(gray);
         axis off;
         handles.HIm = B ;
         guidata(hObject,handles);
         %===========================Hodnocení kvality
         [HodPSNR] = psnr(A,B);
         set(handles.psnr,'String', HodPSNR);
         
         mK = [0.01 0.03];
         mwindow = fspecial('gaussian', 11, 1.5);
         mL = 255;
         [SS, map] = ssim_index(A,B,mK,mwindow,mL);
         set(handles.ssim,'String', SS);
         
       elseif met == 2
         set(handles.slovnik,'String',' ');
         set(handles.met,'String','Bilineární');
         A = handles.obrazek;
         B = imresize(A,1/3, 'bicubic');
         axes(handles.axes3);
         imagesc(B);colormap(gray);
         axis off;
         B = imresize(B,3, 'bilinear');
         axes(handles.axes2);
         imagesc(B);colormap(gray);
         axis off;
         handles.HIm = B ;
         guidata(hObject,handles);
         %===========================Hodnocení kvality
         [HodPSNR] = psnr(A,B);
         set(handles.psnr,'String', HodPSNR);
         
         mK = [0.01 0.03];
         mwindow = fspecial('gaussian', 11, 1.5);
         mL = 255;
         [SS, map] = ssim_index(A,B,mK,mwindow,mL);
         set(handles.ssim,'String', SS);
         
       elseif met == 3
         set(handles.slovnik,'String',' ');
         set(handles.met,'String','Bikubická');
         A = handles.obrazek;
         B = imresize(A,1/3, 'bicubic');
         axes(handles.axes3);
         imagesc(B);colormap(gray);
         axis off;
         B = imresize(B,3, 'bicubic');
         axes(handles.axes2);
         imagesc(B);colormap(gray);
         axis off;
         handles.HIm = B ;
         guidata(hObject,handles);
         %===========================Hodnocení kvality
         [HodPSNR] = psnr(A,B);
         set(handles.psnr,'String', HodPSNR);
         
         mK = [0.01 0.03];
         mwindow = fspecial('gaussian', 11, 1.5);
         mL = 255;
         [SS, map] = ssim_index(A,B,mK,mwindow,mL);
         set(handles.ssim,'String', SS);
         
       elseif met == 4
         set(handles.met,'String','Spec. slovníky');
         A = handles.obrazek;
         B = imresize(A,1/3, 'bicubic');
         axes(handles.axes3);
         imagesc(B);colormap(gray);
         axis off;
         [B,sl] = SpecSlov(A);
         set(handles.slovnik,'String',sl);
         axes(handles.axes2);
         imagesc(B);colormap(gray);
         axis off;
         handles.HIm = B ;
         guidata(hObject,handles);
         
         %===========================Hodnocení kvality
         [HodPSNR] = psnr(A,B);
         set(handles.psnr,'String', HodPSNR);
         
         mK = [0.01 0.03];
         mwindow = fspecial('gaussian', 11, 1.5);
         mL = 255;
         [SS, map] = ssim_index(A,B,mK,mwindow,mL);
         set(handles.ssim,'String', SS);
         
       end

% --- Executes on button press in nactiObr.
function nactiObr_Callback(hObject, eventdata, handles)
% hObject    handle to nactiObr (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('*.jpg; *.bmp; *.tif; *.png','Otevri obrazek');

if isequal(FileName,0)
warndlg('Nebyl zvolen zadny obrazek','Warning!')
else
    
handles.obrazek = imread([PathName FileName]);

obrazek = handles.obrazek;
axes(handles.axes1);
imagesc(obrazek);colormap(gray);
handles.obrazek = obrazek ;
axis off;
guidata(hObject,handles);
end


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


% --- Executes during object creation, after setting all properties.
function metoda_CreateFcn(hObject, eventdata, handles)
% hObject    handle to metoda (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 button press in save.
function save_Callback(hObject, eventdata, handles)
% hObject    handle to save (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
if isequal(handles.HIm,0)
warndlg('Nebyl zvětšen žádný obrázek','Warning!')
else
    [FileName,PathName] = uiputfile('*.bmp','Otevri obrazek');
    S = handles.HIm;
    imwrite(S,[PathName FileName],'BMP');
end
