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

% Last Modified by GUIDE v2.5 14-May-2015 19:58:23

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

% Choose default command line output for rawtotiff3
handles.output = hObject;
set(handles.uipanel18,'selectedobject',handles.HE)
set(handles.colour_output,'selectedobject',handles.RGB_HE)
% Update handles structure
guidata(hObject, handles);

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

% --- Outputs from this function are returned to the command line.
function varargout = rawtotiff3_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 when selected object is changed in uipanel1.
function uipanel1_SelectionChangeFcn(hObject, eventdata, handles)
% hObject    handle to the selected object in uipanel1 
% eventdata  structure with the following fields (see UIBUTTONGROUP)
%	EventName: string 'SelectionChanged' (read only)
%	OldValue: handle of the previously selected object or empty if none was selected
%	NewValue: handle of the currently selected object
% handles    structure with handles and user data (see GUIDATA)
pom=strcmp(get(handles.sb,'String'),'Image converted');
pom2=strcmp(get(handles.sb,'String'),'Image enhanced');
if pom==pom2 && strcmp(get(eventdata.NewValue,'Tag'),'togglebutton2')
    %cyklus pro přepínnání mezi funkcemi programu
    warndlg('You have to convert image to RGB first!');
    set(handles.togglebutton1,'Value',1)
        set(handles.contrast,'Visible', 'off')
        set(handles.info,'Visible', 'off')
        set(handles.raw,'Visible', 'on')
else
switch get(eventdata.NewValue,'Tag') % Get Tag of selected object.
    case 'togglebutton1'
        set(handles.contrast,'Visible', 'off')
        set(handles.info,'Visible', 'off')
        set(handles.raw,'Visible', 'on')
    case 'togglebutton2'
         set(handles.raw,'Visible', 'off')
        set(handles.info,'Visible', 'off')
        set(handles.contrast,'Visible', 'on')
    case 'togglebutton3'
        set(handles.raw,'Visible', 'off')
        set(handles.contrast,'Visible', 'off')
        set(handles.info,'Visible', 'on')
end
end


% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global filename
%načtení souboru
[filename, pathname] = uigetfile({'*.cr2;*.crw;*.raf;*.tif;*.kdc; *.dcr;*.mrw;*.nef;*.orf;*.dng;*.ptx;*.pef;*.arw;*.srf;*.sr2;*.x3f;*.erf','ALL RAW Files';...
    '*.cr2;*.crw','Canon RAW';...
    '*.raf','Fuji RAW';'*.tif;*.kdc; *.dcr','Kodak RAW';...
    '*.mrw','Minolta RAW';'*.nef','Nikon RAW';...
    '*.orf','Olympus RAW';'*.dng','Adobe RAW';...
    '*.ptx;*.pef','Pentax RAW';'*.arw;*.srf;*.sr2','Sony RAW';...
    '*.x3f','Sigma RAW';'*.erf','Epson RAW';...
    '*.*','All Files'}, 'Select RAW image');
set(handles.sb,'Visible', 'on','String','Opening file');
set(handles.figure1, 'pointer', 'watch')
drawnow;
set(handles.filename,'string', filename)
global FilePath
global saturace
global cerna
global skala_cervena
global skala_zelena1
global skala_modra
global fotak
FilePath=fullfile(pathname,filename);
[fotak, cerna, saturace, skala_cervena, skala_zelena1, skala_modra]=nacteni(FilePath);
set(handles.black,'string', cerna)
set(handles.white,'string', saturace)
set(handles.fotak,'string', fotak)
set(handles.cervena,'string', skala_cervena)
set(handles.zelena,'string', skala_zelena1)
set(handles.modra,'string', skala_modra)
set(handles.cervena2,'string', skala_cervena)
set(handles.zelena2,'string', skala_zelena1)
set(handles.modra2,'string', skala_modra)
set(handles.figure1, 'pointer', 'arrow')
set(handles.sb,'String', 'File opened');


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 double


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


% --- Executes during object creation, after setting all properties.
function edit3_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit3 (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 button press in convert.
function convert_Callback(hObject, eventdata, handles)
% hObject    handle to convert (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
%konverze z RAW do TIFF
set(handles.sb,'Visible', 'on','String','Convering file');
set(handles.figure1, 'pointer', 'watch')
drawnow;
WP=get(handles.WP, 'Value');
pom = get(handles.gama_c, 'String');
if ~all(ismember(get(handles.gama_c,'String'), '/.1234567890'))
    warndlg('Use only numbers in Gama Correction. Using default value 1/2.2.');
    gama=1/2.2;
elseif isempty(pom)
    gama=1/2.2;
else
    gama = str2num(get(handles.gama_c, 'String'));
end
global skala_cervena
global skala_zelena1
global skala_modra
pom1 = get(handles.edit1, 'String');
pom2 = get(handles.edit2, 'String');
pom3 = get(handles.edit3, 'String');
if ~all(ismember(get(handles.edit1,'String'), '.1234567890'))
        warndlg('Use only numbers in User defined red multiplier. Using camera multiplier.');
elseif isempty(pom1)
else
    skala_cervena=str2double(get(handles.edit1,'String'));
end
if ~all(ismember(get(handles.edit2,'String'), '.1234567890'))
    warndlg('Use only numbers in User defined blue multiplier. Using camera multiplier.');
elseif isempty(pom2)
else
    skala_modra=str2double(get(handles.edit2,'String'));
end
if ~all(ismember(get(handles.edit3,'String'), '.1234567890'))
    warndlg('Use only numbers in User defined green multiplier. Using camera multiplier.');
elseif isempty(pom3)
else
    skala_zelena1=str2double(get(handles.edit3,'String'));
end
global FilePath
global saturace
global cerna
global fotak
global nl_srgb
[norm_R, norm_G, norm_B]=normalizace(skala_cervena, skala_zelena1, skala_modra, FilePath, saturace, cerna);
rgb=konverze(fotak, norm_R, norm_G, norm_B, WP);
nl_srgb=gama_korekce(rgb, gama);
set(handles.snimek,'Visible', 'on');
 axes(handles.snimek);
 imshow(nl_srgb);
 vel=size(nl_srgb);
 set(handles.size, 'string', [num2str(vel(1)) ' x ' num2str(vel(2)) ' px'])
 set(handles.figure1, 'pointer', 'arrow')
 set(handles.sb,'String', 'Image converted');


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


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


% --- Executes during object creation, after setting all properties.
function gama_c_CreateFcn(hObject, eventdata, handles)
% hObject    handle to gama_c (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 button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
%set(handles.sb,'Visible', 'on');
%Výběr metody pro zlepšení snímku + samotné provedení
set(handles.sb,'String', 'Enhancing image');
set(handles.figure1, 'pointer', 'watch')
drawnow;
global nl_srgb 
global nl_srgb2
global colmap
if get(handles.HE, 'Value')==1
    col_out=get(get(handles.colour_output,'SelectedObject'),'Tag');
neg=get(handles.neg_HE, 'Value');
yuv=get(handles.YUV_HE, 'Value');
colmap=get(handles.colormap_HE, 'Value');
ES=get(handles.ES_HE, 'Value');
nl_srgb2=histogram_equalization(nl_srgb, col_out, neg, yuv);
elseif get(handles.AHE, 'Value')==1
    col_out=get(get(handles.colour_output_AHE,'SelectedObject'),'Tag');
    range=get(get(handles.range,'SelectedObject'),'Tag');
    neg=get(handles.neg_AHE, 'Value');
    yuv=get(handles.YUV_AHE, 'Value');
    colmap=get(handles.colormap_AHE, 'Value');
    ES=get(handles.ES_AHE, 'Value');
    pom1 = get(handles.tiles, 'String');
    pom2 = get(handles.clip, 'String');
    if ~all(ismember(get(handles.tiles,'String'), '1234567890'))
        warndlg('Use only integers as Number of tiles in a row. Using 36 instead.');
        tiles=[36 36];
        elseif isempty(pom1)
            tiles=[36 36];
    elseif pom1=='0'
        tiles=[36 36];
        else
            tiles=[str2double(get(handles.tiles, 'String')) str2double(get(handles.tiles, 'String'))];
    end
    if ~all(ismember(get(handles.clip,'String'), '.1234567890')) || or(str2double(get(handles.clip, 'String'))<0,str2double(get(handles.clip, 'String'))>1)  
        warndlg('Use only numbers in range 0-1 as Clip limit. Using 0.1 instead.');
        clip=0.1;
    elseif or(isempty(pom2), pom2=='0') 
        clip=0.1;
    else
        clip=str2double(get(handles.clip, 'String'));
    end
    nl_srgb2=AHE(nl_srgb,col_out, neg, yuv, tiles, clip, range);
    elseif get(handles.ALCE, 'Value')==1
        col_out=get(get(handles.col_out_ALCE,'SelectedObject'),'Tag');
        neg=get(handles.neg_ALCE, 'Value');
        yuv=get(handles.YUV_ALCE, 'Value');
        colmap=get(handles.colormap_ALCE, 'Value');
        ES=get(handles.ES_ALCE, 'Value');
        pom1 = get(handles.mask, 'String');
        if or(~all(ismember(get(handles.mask,'String'), '1234567890')), rem(str2double(get(handles.mask, 'String')),2)==0)
        warndlg('Use only odd positive integers as Size of the mask. Using 49 instead.');
        mask=ones(49,49);
        elseif isempty(pom1)
            mask=ones(49,49);
        elseif pom1=='0'
            mask=ones(49,49);
        else
            mask=ones(str2double(get(handles.mask, 'String')), str2double(get(handles.mask, 'String')));
        end
        nl_srgb2=ALCE(nl_srgb,col_out, neg, yuv, mask);
end
 axes(handles.snimek);
 if ES==1
     velikost=size(nl_srgb2(:,:,1));
pom=zeros(velikost(1), velikost(2));
for i=2:(velikost(1)-1)
    for j=2:(velikost(2)-1)
        pom2=max(max(nl_srgb2(i-1:i+1,j-1:j+1)));
        pom3=min(min(nl_srgb2(i-1:i+1,j-1:j+1)));
        pom4=pom2-nl_srgb2(i,j);
        pom5=nl_srgb2(i,j)-pom3;
        if pom4<pom5
            pom(i,j)=pom2;
        else
            pom(i,j)=pom3;
        end
    end
end
nl_srgb2=medfilt2(pom, [5 5]);
 end
 if colmap==1
     imshow(nl_srgb2);
     colormap(jet);
 else
     imshow(nl_srgb2);
     
 end
 set(handles.figure1, 'pointer', 'arrow')
 set(handles.sb,'String', 'Image enhanced');
 set(handles.enlarge,'Visible', 'on')


% --- Executes on button press in neg_HE.
function neg_HE_Callback(hObject, eventdata, handles)
% hObject    handle to neg_HE (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 neg_HE


% --- Executes on button press in YUV_HE.
function YUV_HE_Callback(hObject, eventdata, handles)
% hObject    handle to YUV_HE (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 YUV_HE


% --- Executes when selected object is changed in uipanel18.
function uipanel18_SelectionChangeFcn(hObject, eventdata, handles)
% hObject    handle to the selected object in uipanel18 
% eventdata  structure with the following fields (see UIBUTTONGROUP)
%	EventName: string 'SelectionChanged' (read only)
%	OldValue: handle of the previously selected object or empty if none was selected
%	NewValue: handle of the currently selected object
% handles    structure with handles and user data (see GUIDATA)
switch get(eventdata.NewValue,'Tag') % Get Tag of selected object.
    case 'HE'
        set(handles.uipanel23,'Visible', 'off')
        set(handles.uipanel21,'Visible', 'off')
        set(handles.uipanel19,'Visible', 'on')
    case 'AHE'
         set(handles.uipanel19,'Visible', 'off')
        set(handles.uipanel23,'Visible', 'off')
        set(handles.uipanel21,'Visible', 'on')
    case 'ALCE'
        set(handles.uipanel19,'Visible', 'off')
        set(handles.uipanel21,'Visible', 'off')
        set(handles.uipanel23,'Visible', 'on')
end


% --- Executes on button press in neg_AHE.
function neg_AHE_Callback(hObject, eventdata, handles)
% hObject    handle to neg_AHE (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 neg_AHE


% --- Executes on button press in YUV_AHE.
function YUV_AHE_Callback(hObject, eventdata, handles)
% hObject    handle to YUV_AHE (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 YUV_AHE



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


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


% --- Executes during object creation, after setting all properties.
function clip_CreateFcn(hObject, eventdata, handles)
% hObject    handle to clip (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 button press in neg_ALCE.
function neg_ALCE_Callback(hObject, eventdata, handles)
% hObject    handle to neg_ALCE (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 neg_ALCE


% --- Executes on button press in YUV_ALCE.
function YUV_ALCE_Callback(hObject, eventdata, handles)
% hObject    handle to YUV_ALCE (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 YUV_ALCE



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


% --- Executes during object creation, after setting all properties.
function mask_CreateFcn(hObject, eventdata, handles)
% hObject    handle to mask (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 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)
%Ukládání souboru
global filename 
global nl_srgb2
i=length(filename)-2;
if filename(i-1)=='t'
else
    filename(i)='t';
    filename(i+1)='i';
    filename(i+2)='f';
    filename(i+3)='f';
end
imwrite(nl_srgb2,filename)
set(handles.sb,'string',['Image saved to file: ' filename])


% --- Executes on button press in enlarge.
function enlarge_Callback(hObject, eventdata, handles)
% hObject    handle to enlarge (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
%Zvěšení snímku + otevření v novém okně
global nl_srgb2
global colmap
if colmap==1
    figure(2)
imshow(nl_srgb2)
colormap(jet)
else
figure(2)
imshow(nl_srgb2)
end

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

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


% --- Executes during object creation, after setting all properties.
function preset_CreateFcn(hObject, eventdata, handles)
% hObject    handle to preset (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 apply.
function apply_Callback(hObject, eventdata, handles)
% hObject    handle to apply (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
%kód pro aplikaci presetu
preset=get(handles.preset,'Value');
switch preset
    case 2
        set(handles.uipanel19,'Visible', 'off')
        set(handles.uipanel23,'Visible', 'off')
        set(handles.uipanel21,'Visible', 'on')
        set(handles.AHE,'Value',1)
        set(handles.tiles,'String',8)
        set(handles.clip,'String',0.1)
        set(handles.RGB_AHE,'Value',1)
        set(handles.YUV_AHE,'Value',0)
        set(handles.neg_AHE,'Value',0)
        set(handles.colormap_AHE,'Enable','off')
        set(handles.colormap_AHE,'Value',0)
        set(handles.ES_AHE,'Enable','off')
        set(handles.ES_AHE,'Value',0)
    case 3
        set(handles.uipanel19,'Visible', 'off')
        set(handles.uipanel23,'Visible', 'on')
        set(handles.uipanel21,'Visible', 'off')
        set(handles.ALCE,'Value',1)
        set(handles.mask,'String',101)
        set(handles.RGB_ALCE,'Value',1)
        set(handles.YUV_ALCE,'Value',0)
        set(handles.neg_ALCE,'Value',0)
        set(handles.colormap_ALCE,'Enable','off')
        set(handles.colormap_ALCE,'Value',0)
        set(handles.ES_ALCE,'Enable','off')
        set(handles.ES_ALCE,'Value',0)
        case 4
        set(handles.uipanel19,'Visible', 'off')
        set(handles.uipanel23,'Visible', 'off')
        set(handles.uipanel21,'Visible', 'on')
        set(handles.AHE,'Value',1)
        set(handles.tiles,'String',40)
        set(handles.clip,'String',0.1)
        set(handles.G_AHE,'Value',1)
        set(handles.YUV_AHE,'Value',0)
        set(handles.neg_AHE,'Value',0)
        set(handles.colormap_AHE,'Enable','on')
        set(handles.colormap_AHE,'Value',0)
        set(handles.ES_AHE,'Enable','on')
        set(handles.ES_AHE,'Value',0)
        case 5
        set(handles.uipanel19,'Visible', 'off')
        set(handles.uipanel23,'Visible', 'on')
        set(handles.uipanel21,'Visible', 'off')
        set(handles.ALCE,'Value',1)
        set(handles.mask,'String',55)
        set(handles.G_ALCE,'Value',1)
        set(handles.YUV_ALCE,'Value',0)
        set(handles.neg_ALCE,'Value',0)
        set(handles.colormap_ALCE,'Enable','on')
        set(handles.colormap_ALCE,'Value',0)
        set(handles.ES_ALCE,'Enable','on')
        set(handles.ES_ALCE,'Value',0)
end
    


% --- Executes on button press in colormap_HE.
function colormap_HE_Callback(hObject, eventdata, handles)
% hObject    handle to colormap_HE (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 colormap_HE


% --- Executes on button press in colormap_AHE.
function colormap_AHE_Callback(hObject, eventdata, handles)
% hObject    handle to colormap_AHE (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 colormap_AHE


% --- Executes on button press in colormap_ALCE.
function colormap_ALCE_Callback(hObject, eventdata, handles)
% hObject    handle to colormap_ALCE (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 colormap_ALCE


% --- Executes when selected object is changed in col_out_ALCE.
function col_out_ALCE_SelectionChangeFcn(hObject, eventdata, handles)
% hObject    handle to the selected object in col_out_ALCE 
% eventdata  structure with the following fields (see UIBUTTONGROUP)
%	EventName: string 'SelectionChanged' (read only)
%	OldValue: handle of the previously selected object or empty if none was selected
%	NewValue: handle of the currently selected object
% handles    structure with handles and user data (see GUIDATA)
%kód pro zpřístupnění metod použitelných pouze pro některé barevné kanály
rb=get(eventdata.NewValue,'tag');
switch rb
    case 'RGB_ALCE'
        set(handles.colormap_ALCE,'Enable','off')
        set(handles.ES_ALCE,'Enable','off')
            case 'G_ALCE'
        set(handles.colormap_ALCE,'Enable','on')
        set(handles.ES_ALCE,'Enable','on')
            case 'B_ALCE'
        set(handles.colormap_ALCE,'Enable','on')
        set(handles.ES_ALCE,'Enable','on')
            case 'GB_ALCE'
        set(handles.colormap_ALCE,'Enable','on')
        set(handles.ES_ALCE,'Enable','on')
            case 'R_ALCE'
        set(handles.colormap_ALCE,'Enable','on')
        set(handles.ES_ALCE,'Enable','on')
end


% --- Executes when selected object is changed in colour_output.
function colour_output_SelectionChangeFcn(hObject, eventdata, handles)
% hObject    handle to the selected object in colour_output 
% eventdata  structure with the following fields (see UIBUTTONGROUP)
%	EventName: string 'SelectionChanged' (read only)
%	OldValue: handle of the previously selected object or empty if none was selected
%	NewValue: handle of the currently selected object
% handles    structure with handles and user data (see GUIDATA)
%kód pro zpřístupnění metod použitelných pouze pro některé barevné kanály
rb=get(eventdata.NewValue,'tag');
switch rb
    case 'RGB_HE'
        set(handles.colormap_HE,'Enable','off')
        set(handles.ES_HE,'Enable','off')
            case 'G_HE'
        set(handles.colormap_HE,'Enable','on')
        set(handles.ES_HE,'Enable','on')
            case 'B_HE'
        set(handles.colormap_HE,'Enable','on')
        set(handles.ES_HE,'Enable','on')
            case 'GB_HE'
        set(handles.colormap_HE,'Enable','on')
        set(handles.ES_HE,'Enable','on')
            case 'R_HE'
        set(handles.colormap_HE,'Enable','on')
        set(handles.ES_HE,'Enable','on')
end

% --- Executes when selected object is changed in colour_output_AHE.
function colour_output_AHE_SelectionChangeFcn(hObject, eventdata, handles)
% hObject    handle to the selected object in colour_output_AHE 
% eventdata  structure with the following fields (see UIBUTTONGROUP)
%	EventName: string 'SelectionChanged' (read only)
%	OldValue: handle of the previously selected object or empty if none was selected
%	NewValue: handle of the currently selected object
% handles    structure with handles and user data (see GUIDATA)
%kód pro zpřístupnění metod použitelných pouze pro některé barevné kanály
rb=get(eventdata.NewValue,'tag');
switch rb
    case 'RGB_AHE'
        set(handles.colormap_AHE,'Enable','off')
        set(handles.ES_AHE,'Enable','off')
            case 'G_AHE'
        set(handles.colormap_AHE,'Enable','on')
        set(handles.ES_AHE,'Enable','on')
            case 'B_AHE'
        set(handles.colormap_AHE,'Enable','on')
        set(handles.ES_AHE,'Enable','on')
            case 'GB_AHE'
        set(handles.colormap_AHE,'Enable','on')
        set(handles.ES_AHE,'Enable','on')
            case 'R_AHE'
        set(handles.colormap_AHE,'Enable','on')
        set(handles.ES_AHE,'Enable','on')
end


% --- Executes on button press in ES_AHE.
function ES_AHE_Callback(hObject, eventdata, handles)
% hObject    handle to ES_AHE (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 ES_AHE


% --- Executes on button press in ES_ALCE.
function ES_ALCE_Callback(hObject, eventdata, handles)
% hObject    handle to ES_ALCE (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 ES_ALCE


% --- Executes on button press in ES_HE.
function ES_HE_Callback(hObject, eventdata, handles)
% hObject    handle to ES_HE (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 ES_HE
