function varargout = GUI(varargin)
% GUI M-file 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_OpeningFunction 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 20-Mar-2009 15:27: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;


% --------------------------------------------------------------------
function Soubor_Callback(hObject, eventdata, handles)
% hObject    handle to Soubor (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --------------------------------------------------------------------
function Pomoc_Callback(hObject, eventdata, handles)
% hObject    handle to Pomoc (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --------------------------------------------------------------------
function nacist_obrazek_Callback(hObject, eventdata, handles)
% hObject    handle to nacist_obrazek (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
obrazek = uigetfile( ...
{'*.jpg;*.jpeg;*.jpe;','JPEG (*.jpg,*.jpeg,*.jpe)';    %typy k otevreni; zobrazeni v openboxu
   '*.gif',  'GIF (*.GIF)'; ...
   '*.png','PNG (*.PNG)'; ...
   '*.bmp','bitmapy (*.bmp)'; ...
   '*.*',  'All Files (*.*)'}, ...      
   'Otevřít obrázek');                  %Popis open boxu
imshow(obrazek);                  %zobrazeni obrazku v axes
set(handles.original,'UserData',obrazek);     %ulozi obraz do axes1

% --------------------------------------------------------------------
function konec_Callback(hObject, eventdata, handles)
% hObject    handle to konec (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

konec = questdlg('Opravdu chcete ukončit aplikaci?','Ukončení programu','Ano','Ne','Ano');
switch konec,
   case 'Ano',
   clear all;
   close all;
   case 'Ne'
     return
end

% --------------------------------------------------------------------
function o_programu_Callback(hObject, eventdata, handles)
% hObject    handle to o_programu (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

o_programu;


% --------------------------------------------------------------------
function pomoc_Callback(hObject, eventdata, handles)
% hObject    handle to pomoc (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --- Executes on button press in nacist_obrazek.
function na_Callback(hObject, eventdata, handles)
% hObject    handle to nacist_obrazek (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)



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

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


% --- Executes during object creation, after setting all properties.
function klasicky_detektor_CreateFcn(hObject, eventdata, handles)
% hObject    handle to klasicky_detektor (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 aplikuj.
function aplikuj_Callback(hObject, eventdata, handles)
% hObject    handle to aplikuj (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

if get(handles.original, 'UserData') ~= 0       %kontrola nacteni obrazku

prah1 = get(handles.nastaveni_prahu, 'Value');      %do promenne prah1 ulozi hodnotu prahu
obrazek = get(handles.original,'UserData');     %ulozi do promenne nacteny obraz v axes1
I = imread(obrazek);      %precte obraz a ulozi ho do promenne
I=rgb2gray(I);      %prevede obraz na sedotonovy

%nastaveni sumu v obrazku
noise = get(handles.nastaveni_sumu, 'Value');
if get(handles.nastaveni_sumu, 'Value') ~= 0
    if get(handles.sum, 'Value') == 1
        I = imnoise(I,'salt & pepper',noise);
    elseif get(handles.sum, 'Value') == 2
        I = imnoise(I,'speckle',noise);
    elseif get(handles.sum, 'Value') == 3
        I = imnoise(I,'poisson');
    else
        I=imnoise(I,'gaussian',noise,0.01);
    end        
set(handles.original,'UserData', I);
end

a = get(handles.klasicky_detektor, 'Value');       %ziska hodnotu, ktera urcuje metodu v pop-up menu

if a == 1
    detObr = edge(I,'canny', prah1);        %provede detekci hran 
elseif a == 2
    detObr = edge(I,'prewitt', prah1);
elseif a == 3
    detObr = edge(I,'sobel', prah1);
elseif a == 4
    detObr = edge(I,'roberts', prah1);
elseif a == 5
    detObr = edge(I,'log', prah1);
elseif a == 6
    detObr = edge(I,'zerocross', prah1);
end

figure, imshow(detObr);        %zobrazi obraz v novem okne

set(handles.original,'UserData',obrazek);

else
    errordlg('Není načtený obraz','Chyba programu');
end

% --- Executes on button press in pushbutton4.
function pushbutton4_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)




% --- Executes on slider movement.
function nastaveni_prahu_Callback(hObject, eventdata, handles)
% hObject    handle to nastaveni_prahu (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,'Value') returns position of slider
%        get(hObject,'Min') and get(hObject,'Max') to determine range of slider

prah1 = get(handles.nastaveni_prahu, 'Value');
set(handles.hodnota_prahu, 'String', prah1);

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

% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor',[.9 .9 .9]);
end




% --- Executes on slider movement.
function slider6_Callback(hObject, eventdata, handles)
% hObject    handle to slider6 (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,'Value') returns position of slider
%        get(hObject,'Min') and get(hObject,'Max') to determine range of slider


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

% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor',[.9 .9 .9]);
end




% --- Executes on button press in pushbutton6.
function pushbutton6_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton6 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --- Executes on button press in pushbutton7.
function pushbutton7_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton7 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --- Executes on button press in det_wavelet.
function det_wavelet_Callback(hObject, eventdata, handles)
% hObject    handle to det_wavelet (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

%%%%%%nastaveni vlnky pro transformaci
if get(handles.vlnky, 'Value') ~= 1
    
vlnkai = get(handles.vlnky, 'Value');  
switch lower(vlnkai)
    case (2)
        vlnka = 'db';
    case (3)
        vlnka = 'haar';
    case (4)
        vlnka = 'coif';
    case (5)
        vlnka = 'sym';
    case (6)
        vlnka = 'dmey';
    case (7)
        vlnka = 'bior';
    case (8)    
        vlnka = 'rbio';
end


uroven = get(handles.urovne_vlnek, 'String');
index = get(handles.urovne_vlnek, 'Value');
uroven = num2str(uroven(index,:));

if vlnkai == 3 || vlnkai == 6
    typvlnky = vlnka;
else
    typvlnky = [vlnka, uroven];
end

%%%%%%ziskani hodnot promennych z GUI
prah = get(handles.nastaveni_prahu_w, 'Value');
maxScale = get(handles.max_scale, 'Value');
sigma = get(handles.nastaveni_sigma, 'Value');
obrazek = get(handles.original,'UserData'); 
noise = get(handles.nastaveni_sumu, 'Value');

if get(handles.original, 'UserData') ~= 0

I = imread(obrazek);      %precte obraz a ulozi ho do promenne
I = rgb2gray(I);      %prevede obraz na sedotonovy

%nastaveni sumu v obrazku
if get(handles.nastaveni_sumu, 'Value') ~= 0
    if get(handles.sum, 'Value') == 1
        I = imnoise(I,'salt & pepper',noise);
    elseif get(handles.sum, 'Value') == 2
        I = imnoise(I,'speckle',noise);
    elseif get(handles.sum, 'Value') == 3
        I = imnoise(I,'poisson');
    else
        I=imnoise(I,'gaussian',noise,0.01);
    end        
set(handles.original,'UserData', I);
end

if get(handles.nastaveni_sigma, 'Value') ~= 0
    
filtr = fspecial('gaussian', [3 3], sigma);          %vytvori masku pro Gaussuv filtr
I = imfilter(I, filtr, 'symmetric', 'conv');    %aplikace gaussova filtru
I = double(I);

[c,s] = wavedec2(I,maxScale,typvlnky);     %vlnkova transformace zadane urovne       



%%%%%%ulozeni horizontalnich a vertikalnich koeficientu do matic Wh a Wv v
%jednotlivych meritkach
scale = 1;      %exponent meritka
Wh = ones( s(maxScale+1,1) , s(maxScale+1,2) , maxScale );     %vytvori 3 matice, ktera se v nasledujicim algoritmu 
Wv = ones( s(maxScale+1,1) , s(maxScale+1,2) , maxScale );     %naplni hodnotama vlnkovych koeficientu  

while scale <= maxScale 
[Whh] = detcoef2('h',c,s,scale);        %ulozeni hor. a ver. vlnkovych koeficientu 
[Wvv] = detcoef2('v',c,s,scale);
for j = 1 : s(maxScale - scale + 2,2)     
    for i = 1 : s(maxScale - scale + 2,1)         
        Wh(i,j,scale) = Whh(i,j);
        Wv(i,j,scale) = Wvv(i,j);
    end
end
scale = scale + 1; 
end


%%%%%%vypocet modulu a smeru gradientu v jednotlivych meritkach
scale = 1;      
while scale <= maxScale
    for j = 1 : s(maxScale-scale+2,2)     
        for i = 1 : s(maxScale-scale+2,1)
            M(i,j,scale) = sqrt( abs(Wh(i,j,scale))^2 + abs(Wv(i,j,scale))^2 );     %vypocet modulu gradientu v meritku "scale"
            A(i,j,scale) = atan2(Wh(i,j,scale) , Wv(i,j,scale) );      %vypocet smeru gradientu
            As(i,j,scale) = A(i,j,scale)*180/pi;      %prevod radianu na stupne
            %zaokrouhleni stupnu
                if (As(i,j,scale) >= -180 && As(i,j,scale) < -157.5);
                    Az(i,j,scale) = -180;
                    uhel(i,j,scale) = 0;        %označení směru gradientu
                elseif (As(i,j) >= -157.5 && As(i,j,scale) < -112.5);
                    Az(i,j,scale) = -135;
                    uhel(i,j,scale) = 1;
                elseif (As(i,j,scale) >= -112.5 && As(i,j,scale) < -67.5);
                    Az(i,j,scale) = -90;
                    uhel(i,j,scale) = 2;
                elseif (As(i,j,scale) >= -67.5 && As(i,j,scale) < -22.5);
                    Az(i,j,scale) = -45;   
                    uhel(i,j,scale) = 3;
                elseif (As(i,j,scale) >= -22.5 && As(i,j,scale) < 22.5);
                    Az(i,j,scale) = 0;
                    uhel(i,j,scale) = 0;
                elseif (As(i,j,scale) >= 22.5 && As(i,j,scale) < 67.5);
                    Az(i,j,scale) = 45;
                    uhel(i,j,scale) = 1;
                elseif (As(i,j,scale) >= 67.5 && As(i,j,scale) < 112.5);
                    Az(i,j,scale) = 90;
                    uhel(i,j,scale) = 2;
                elseif (As(i,j,scale) >= 112.5 && As(i,j,scale) < 157.5);
                    Az(i,j,scale) = 135;    
                    uhel(i,j,scale) = 3;
                else Az(i,j,scale) = 180;
                    uhel(i,j,scale) = 0;
                end
        end
    end
scale = scale + 1;      
end

%%%%%%vyber lokalnich maxim
scale = maxScale;      
Mm = ones( s(maxScale+1,1) , s(maxScale+1,2) , maxScale );
while scale <= maxScale
for j = 2 : (s(1,2) - 1)
    for i = 2 : (s(1,1) - 1)
         switch lower(uhel(i,j,scale))
            case (0)
                if M(i,j,scale) < M(i-1,j,scale) && M(i,j,scale) < M(i+1,j,scale);      
                Mm(i,j,scale) = 0;  
                else Mm(i,j,scale) = M(i,j,scale); 
                end
            case (1)
                if M(i,j,scale) < M(i+1,j+1,scale) && M(i,j,scale) < M(i-1,j-1,scale);
                Mm(i,j,scale) = 0;
                else Mm(i,j,scale) = M(i,j,scale); 
                end
            case (2)
                if M(i,j,scale) < M(i+1,j,scale) && M(i,j,scale) < M(i-1,j,scale);
                Mm(i,j,scale) = 0;   
                else Mm(i,j,scale) = M(i,j,scale); 
                end
            case (3)
                if M(i,j,scale) < M(i-1,j+1,scale) && M(i,j,scale) < M(i+1,j-1,scale);      
                Mm(i,j,scale) = 0;   
                else Mm(i,j,scale) = M(i,j,scale); 
                end
         end
    end
end
maxx = max(max(Mm(:,:,scale)));
prah = maxx*prah;
Mm(:,:,scale) = wthresh(Mm(:,:,scale),'h',prah);        %tvrde prahovani (provadi se pro kazdou uroven dekompozice)
scale = scale + 1; 
end

%%%%%%zvetseni obrazku na puvodni velikost
for j = 1 : (s(1,2))
    for i = 1 : (s(1,1))
        Mresized(i,j) = Mm(i,j,maxScale);
    end
end


Mresized = bwmorph(Mresized,'bridge');  
%Mresized = bwmorph(Mresized,'fill');


maxScale = 2*maxScale;
Mresized = imresize(Mresized,maxScale);

figure, imshow(Mresized),title('Detekce hran pomocí vlnkové transformace');

set(handles.original,'UserData',obrazek);   %znovu nacte data, aby bylo mozno s nimi ihned pracovat

else
    errordlg('Není nastavený Gausův filtr','Chyba programu');
end

else
    errordlg('Není načtený obraz','Chyba programu');
end

else
    errordlg('Není nastavena vlnka pro transformaci','Chyba programu');
end

% --- Executes on slider movement.
function nastaveni_prahu_w_Callback(hObject, eventdata, handles)
% hObject    handle to nastaveni_prahu_w (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,'Value') returns position of slider
%        get(hObject,'Min') and get(hObject,'Max') to determine range of slider
prah2 = get(handles.nastaveni_prahu_w, 'Value');
set(handles.hodnota_prahu_w, 'String', prah2);

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

% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor',[.9 .9 .9]);
end




% --- Executes on slider movement.
function max_scale_Callback(hObject, eventdata, handles)
% hObject    handle to max_scale (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,'Value') returns position of slider
%        get(hObject,'Min') and get(hObject,'Max') to determine range of slider


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

% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor',[.9 .9 .9]);
end




% --- Executes on slider movement.
function slider11_Callback(hObject, eventdata, handles)
% hObject    handle to slider11 (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,'Value') returns position of slider
%        get(hObject,'Min') and get(hObject,'Max') to determine range of slider


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

% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor',[.9 .9 .9]);
end


% --- Executes on slider movement.
function slider12_Callback(hObject, eventdata, handles)
% hObject    handle to max_scale (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,'Value') returns position of slider
%        get(hObject,'Min') and get(hObject,'Max') to determine range of slider


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

% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor',[.9 .9 .9]);
end




% --- Executes on slider movement.
function nastaveni_sigma_Callback(hObject, eventdata, handles)
% hObject    handle to nastaveni_sigma (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,'Value') returns position of slider
%        get(hObject,'Min') and get(hObject,'Max') to determine range of slider

sigma = get(handles.nastaveni_sigma, 'Value');
set(handles.sigma, 'String', sigma);

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

% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor',[.9 .9 .9]);
end




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

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


% --- Executes during object creation, after setting all properties.
function popupmenu6_CreateFcn(hObject, eventdata, handles)
% hObject    handle to klasicky_detektor (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 listbox4.
function listbox4_Callback(hObject, eventdata, handles)
% hObject    handle to listbox4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

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


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

% Hint: listbox 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 vlnky.
function vlnky_Callback(hObject, eventdata, handles)
% hObject    handle to vlnky (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = get(hObject,'String') returns vlnky contents as cell array
%        contents{get(hObject,'Value')} returns selected item from vlnky
set(handles.urovne_vlnek, 'Enable', 'on');
vlnkai = get(handles.vlnky, 'Value');

%nastaveni urovni vlnek
switch lower(vlnkai)
    case (1)
        set(handles.urovne_vlnek, 'Enable', 'off');
    case (2)
        set(handles.urovne_vlnek, 'String', [1; 2; 3; 4; 5; 6; 7; 8; 9; 10; 20; 30; 45]);
        vlnka = 'db';
    case (3)
        set(handles.urovne_vlnek, 'Enable', 'off');
        vlnka = 'haar';
    case (4)
        set(handles.urovne_vlnek, 'String', [1; 2; 3; 4; 5]);
        vlnka = 'coif';
    case (5)
        set(handles.urovne_vlnek, 'String', [2; 3; 4; 5; 6; 7; 8]);
        vlnka = 'sym';
    case (6)
        set(handles.urovne_vlnek, 'Enable', 'off');
        vlnka = 'dmey';
    case (7)
        set(handles.urovne_vlnek, 'String', [1.1; 1.3; 1.5; 2.2; 2.4; 2.6; 2.8; 3.1; 3.3; 3.5; 3.7; 3.9; 4.4; 5.5; 6.8]);
        vlnka = 'bior';
    case (8)
        set(handles.urovne_vlnek, 'String', [1.1; 1.3; 1.5; 2.2; 2.4; 2.6; 2.8; 3.1; 3.3; 3.5; 3.7; 3.9; 4.4; 5.5; 6.8]);     
        vlnka = 'rbio';
end
        

% --- Executes during object creation, after setting all properties.
function vlnky_CreateFcn(hObject, eventdata, handles)
% hObject    handle to vlnky (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 urovne_vlnek.
function urovne_vlnek_Callback(hObject, eventdata, handles)
% hObject    handle to urovne_vlnek (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

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


% --- Executes during object creation, after setting all properties.
function urovne_vlnek_CreateFcn(hObject, eventdata, handles)
% hObject    handle to urovne_vlnek (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 sum.
function sum_Callback(hObject, eventdata, handles)
% hObject    handle to sum (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

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




% --- Executes during object creation, after setting all properties.
function sum_CreateFcn(hObject, eventdata, handles)
% hObject    handle to sum (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 slider movement.
function nastaveni_sumu_Callback(hObject, eventdata, handles)
% hObject    handle to nastaveni_sumu (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,'Value') returns position of slider
%        get(hObject,'Min') and get(hObject,'Max') to determine range of slider

nastsum = get(handles.nastaveni_sumu, 'Value');
set(handles.hodnota_sumu, 'String', nastsum);

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

% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor',[.9 .9 .9]);
end


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

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


% --- Executes during object creation, after setting all properties.
function popupmenu10_CreateFcn(hObject, eventdata, handles)
% hObject    handle to popupmenu10 (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 pushbutton9.
function pushbutton9_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton9 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --- Executes on button press in aplikace_sumu.
function aplikace_sumu_Callback(hObject, eventdata, handles)
% hObject    handle to aplikace_sumu (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

noise = get(handles.nastaveni_sumu, 'Value');
obrazek = get(handles.original,'UserData'); 
obrazek = imread(obrazek);
obrazek = rgb2gray(obrazek);
obrazek = imnoise(obrazek,'salt & pepper',noise);
%set(handles.original,'UserData', obrazek);
figure, imshow(obrazek);
