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

% Last Modified by GUIDE v2.5 26-May-2014 12:43:12

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

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

% Update handles structure
guidata(hObject, handles);

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


% --- Outputs from this function are returned to the command line.
function varargout = guide2_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 Extent.
function Extent_Callback(hObject, eventdata, handles)
% hObject    handle to Extent (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global INFO
POMOC = INFO.POMOC;
% Hint: get(hObject,'Value') returns toggle state of Extent
if get(hObject,'Value')==1
   POMOC(1)=1;
else 
   POMOC(1)=0;
end
INFO.POMOC = POMOC;
% --- Executes on button press in MParea.
function MParea_Callback(hObject, eventdata, handles)
% hObject    handle to MParea (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global INFO
% Hint: get(hObject,'Value') returns toggle state of MParea
POMOC = INFO.POMOC;
if get(hObject,'Value')==1
   POMOC(2)=1;
else 
   POMOC(2)=0;
end
INFO.POMOC = POMOC;
% --- Executes on button press in Circularity.
function Circularity_Callback(hObject, eventdata, handles)
% hObject    handle to Circularity (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global INFO
% Hint: get(hObject,'Value') returns toggle state of Circularity
POMOC = INFO.POMOC;
if get(hObject,'Value')==1
   POMOC(3)=1;
else 
   POMOC(3)=0;
end
INFO.POMOC = POMOC;
% --- Executes on button press in Mass.
function Mass_Callback(hObject, eventdata, handles)
% hObject    handle to Mass (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global INFO
% Hint: get(hObject,'Value') returns toggle state of Mass
POMOC = INFO.POMOC;
if get(hObject,'Value')==1
   POMOC(4)=1;
else 
   POMOC(4)=0;
end
INFO.POMOC = POMOC;
% --- Executes on button press in Area.
function Area_Callback(hObject, eventdata, handles)
% hObject    handle to Area (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global INFO
% Hint: get(hObject,'Value') returns toggle state of Area
POMOC = INFO.POMOC;
if get(hObject,'Value')==1
   POMOC(5)=1;
else 
   POMOC(5)=0;
end
INFO.POMOC = POMOC;
% --- Executes on button press in Perimeter.
function Perimeter_Callback(hObject, eventdata, handles)
% hObject    handle to Perimeter (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global INFO
% Hint: get(hObject,'Value') returns toggle state of Perimeter
POMOC = INFO.POMOC;
if get(hObject,'Value')==1
   POMOC(6)=1;
else 
   POMOC(6)=0;
end
INFO.POMOC = POMOC;


% --- Executes on button press in STD.
function STD_Callback(hObject, eventdata, handles)
% hObject    handle to STD (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global INFO
% Hint: get(hObject,'Value') returns toggle state of STD
POMOC = INFO.POMOC;
if get(hObject,'Value')==1
   POMOC(7)=1;
else 
   POMOC(7)=0;
end
INFO.POMOC = POMOC;
% --- Executes on button press in Trend.
function Trend_Callback(hObject, eventdata, handles)
% hObject    handle to Trend (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
  global T INFO myGLOBAL  
  D = INFO.Detected;
%   MATICA = [INFO.EXTENT; INFO.MASSPAREA; INFO.CIRCULARITY; INFO.MASS; INFO.AREA; INFO.PERMIETER; INFO.STD]
  POMOC = INFO.POMOC;
  pocet = find(POMOC==1);
  
  if length(pocet)>2
      errordlg('Select 2 parameters')
  elseif length(pocet)==2
        switch pocet(1)
            case 1
             MAT(1,:)=INFO.EXTENT; 
             label1 = 'Extent';
            case 2
             MAT(1,:)=INFO.MASSPAREA;
             label1 = 'Mass_Per_Area';
             case 3
             MAT(1,:)=INFO.CIRCULARITY;
             label1 = 'Circularity';
             case 4
             MAT(1,:)=INFO.MASS;
             label1 = 'Mass';
             case 5
             MAT(1,:)=INFO.AREA;
             label1 = 'Area';
            case 6
             MAT(1,:)=INFO.PERIMETER;
             label1 = 'Perimeter';
             case 7
             MAT(1,:)=INFO.STD;
             label1 = 'STD';
        end
        switch pocet(2)
            case 1
             MAT(2,:)=INFO.EXTENT;
             label2 = 'Extent';
            case 2
             MAT(2,:)=INFO.MASSPAREA;
              label2 = 'Mass_Per_Area';
             case 3
             MAT(2,:)=INFO.CIRCULARITY;
              label2 = 'Circularity';
             case 4
             MAT(2,:)=INFO.MASS;
              label2 = 'Mass';
             case 5
             MAT(2,:)=INFO.AREA;
              label2 = 'Area';
            case 6
             MAT(2,:)=INFO.PERIMETER;
              label2 = 'Perimeter';
             case 7
             MAT(2,:)=INFO.STD;
              label2 = 'STD';
        end
       
        MAT = sortrows(MAT,1);
        coeff = polyfit(MAT(1,:),MAT(2,:),1);
        xline = linspace(min(MAT(1,:)),max(MAT(1,:)), 200);
        yline = coeff(1)*xline+coeff(2); 
       
        
        plot(handles.axes2,xline,yline,'r-')
         hold(handles.axes2,'on')
        for j = 1:length(MAT)
             plot(handles.axes2,MAT(1,j),MAT(2,j),'b','Marker','+','LineWidth',1)
        end
%         
        
        xlabel(handles.axes2,label1)
        ylabel(handles.axes2,label2);
%         set(handles.axes2,'XLabel',label1,'YLabel',label2)
        hold(handles.axes2,'off')
  else  errordlg('Select 2 parameters')
  end
% --- Executes on button press in Kmeans.
function Kmeans_Callback(hObject, eventdata, handles)
% hObject    handle to Kmeans (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure wit,h handles and user data (see GUIDATA)
global T INFO myGLOBAL;
MATICA = [INFO.EXTENT(2:end); INFO.MASSPAREA(2:end); INFO.CIRCULARITY(2:end); INFO.MASS(2:end); INFO.AREA(2:end); INFO.PERIMETER(2:end); INFO.STD(2:end)];
POMOC = INFO.POMOC;
pomoc = find(POMOC==1);
pocet = get(handles.slider1,'Value');
    if pocet == length(pomoc)
        if length(pomoc)==2
            KM=[]; 
            for i = 1:length(pomoc)
                KM(i,:) = MATICA(pomoc(i),:);
            end
            switch pomoc(1)
                case 1
                    MAT(1,:)=INFO.EXTENT;
                    label1 = 'Extent';
                case 2
                    MAT(1,:)=INFO.MASSPAREA;
                    label1 = 'Mass_Per_Area';
                case 3
                    MAT(1,:)=INFO.CIRCULARITY;
                    label1 = 'Circularity';
                case 4
                    MAT(1,:)=INFO.MASS;
                    label1 = 'Mass';
                case 5
                    MAT(1,:)=INFO.AREA;
                    label1 = 'Area';
                case 6
                    MAT(1,:)=INFO.PERIMETER;
                    label1 = 'Perimeter';
                case 7
                    MAT(1,:)=INFO.STD;
                    label1 = 'STD';
            end
            switch pomoc(2)
                case 1
                    MAT(2,:)=INFO.EXTENT;
                    label2 = 'Extent';
                case 2
                    MAT(2,:)=INFO.MASSPAREA;
                    label2 = 'Mass_Per_Area';
                case 3
                    MAT(2,:)=INFO.CIRCULARITY;
                    label2 = 'Circularity';
                case 4
                    MAT(2,:)=INFO.MASS;
                    label2 = 'Mass';
                case 5
                    MAT(2,:)=INFO.AREA;
                    label2 = 'Area';
                case 6
                    MAT(2,:)=INFO.PERIMETER;
                    label2 = 'Perimeter';
                case 7
                    MAT(2,:)=INFO.STD;
                    label2 = 'STD';
            end
                    KM=KM';
                    [idx,ctrs] = kmeans(KM,pocet);
                    
%                     plot(handles.axes2,KM(:,1),KM(:,2),'r.','MarkerSize',12)
                    plot(handles.axes2,KM(idx==1,1),KM(idx==1,2),'r.','MarkerSize',12)
                     hold(handles.axes2,'on')
                    plot(handles.axes2,KM(idx==2,1),KM(idx==2,2),'g.','MarkerSize',12)
                    plot(handles.axes2,ctrs(:,1),ctrs(:,2),'kx',...
                         'MarkerSize',12,'LineWidth',2)
                    plot(handles.axes2,ctrs(:,1),ctrs(:,2),'ko',...
                         'MarkerSize',12,'LineWidth',2)
                    legend(handles.axes2,'Cluster 1','Cluster 2','Centroids',...
                           'Location','NW')
                       
        xlabel(handles.axes2,label1)
        ylabel(handles.axes2,label2);
                     hold(handles.axes2,'off')
        elseif length(pomoc)==3
            KM=[]; 
            for i = 1:length(pomoc)
                KM(i,:) = MATICA(pomoc(i),:);
            end
            KM=KM';
                    [idx,ctrs] = kmeans(KM,pocet);
                    
%                     plot(handles.axes2,KM(:,1),KM(:,2),'r.','MarkerSize',12)
                    plot(handles.axes2,KM(idx==1,1),KM(idx==1,2),'r.','MarkerSize',12)
                     hold(handles.axes2,'on')
                    plot(handles.axes2,KM(idx==2,1),KM(idx==2,2),'g.','MarkerSize',12)
                    plot(handles.axes2,KM(idx==3,1),KM(idx==3,2),'b.','MarkerSize',12)
%                     plot(handles.axes2,ctrs(:,1),ctrs(:,2),ctrs(:,3),'kx',...
%                          'MarkerSize',12,'LineWidth',2)
%                     plot(handles.axes2,ctrs(:,1),ctrs(:,2),ctrs(:,3),'ko',...
%                          'MarkerSize',12,'LineWidth',2)
                    legend(handles.axes2,'Cluster 1','Cluster 2','Cluster 3','Centroids',...
                           'Location','NW')
                     hold(handles.axes2,'off')
      elseif length(pomoc)==4
          KM=[]; 
            for i = 1:length(pomoc)
                KM(i,:) = MATICA(pomoc(i),:);
            end
            KM=KM';
                    [idx,ctrs] = kmeans(KM,pocet);
                    
%                     plot(handles.axes2,KM(:,1),KM(:,2),'r.','MarkerSize',12)
                    plot(handles.axes2,KM(idx==1,1),KM(idx==1,2),'r.','MarkerSize',12)
                     hold(handles.axes2,'on')
                    plot(handles.axes2,KM(idx==2,1),KM(idx==2,2),'g.','MarkerSize',12)
                    plot(handles.axes2,KM(idx==3,1),KM(idx==3,2),'b.','MarkerSize',12)
                    plot(handles.axes2,KM(idx==4,1),KM(idx==4,2),'y.','MarkerSize',12)
%                     plot(handles.axes2,ctrs(:,1),ctrs(:,2),ctrs(:,3),ctrs(:,4),'kx',...
%                          'MarkerSize',12,'LineWidth',2)
%                     plot(handles.axes2,ctrs(:,1),ctrs(:,2),ctrs(:,3),ctrs(:,4),'ko',...
%                          'MarkerSize',12,'LineWidth',2)
                    legend(handles.axes2,'Cluster 1','Cluster 2','Cluster 3','Cluster 4','Centroids',...
                           'Location','NW')
                     hold(handles.axes2,'off')
        else
        end
    else errordlg('Pocet parametrov neodpoveda poctu zhlukov')
    end
INFO.Kmeans = idx;
INFO.Kmeanspocet = pocet;
pom(1) = 0;
%% rozsekanie kmeans na roztriedene indexy.
D = INFO.Detected;
for i = 2:length(D)+1
    if length(pom)==1
    pom(i) = length(myGLOBAL(D(i-1)).Properties);
    VECTOR {i-1} = idx(pom(i-1)+1:pom(i)+pom(i-1));
    else 
    pom(i) = length(myGLOBAL(D(i-1)).Properties);
    VECTOR {i-1} = idx(pom(i-1)+1:pom(i)+pom(i-1)+1);
%     pom(i)=pom(i)+1;
    end
end
INFO.KmeansVector = VECTOR;

set(handles.listbox1,'Visible','on');
D = INFO.Detected;
% D = get(handles.listbox3,'Value');
        
        x = 1;
            for i = 1:length(D)
                    Names{i} = ['DET_',T(D(x)).FileName];
                    x = x+1;
            end
        set(handles.listbox1,'String',Names)
% --- Executes on slider movement.
function slider1_Callback(hObject, eventdata, handles)
% hObject    handle to slider1 (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
str = get(handles.slider1,'Value');
set(handles.edit1,'String',num2str(str))

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



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
value = get(handles.edit1,'String');
set(handles.slider1,'Value',str2num(value))

% --- 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


% --- Executes on button press in START.
function START_Callback(hObject, eventdata, handles)
% hObject    handle to START (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
set(handles.Kmeans,'Enable','on')
set(handles.Trend,'Enable','on')
set(handles.uipanel1,'Visible','on')
set(handles.uipanel3,'Visible','on')
set(handles.edit1,'Enable','on')
set(handles.slider1,'Enable','on')
global INFO
POMOC = 5;
INFO.POMOC = POMOC;

sliderMin = 2;
sliderMax = 4; % this is variable
sliderStep = [1/2, 1/2]; % major and minor steps of 1

set(handles.slider1, 'Min', sliderMin,'Max', sliderMax,'SliderStep', sliderStep,'Value',2);
set(handles.listbox1, 'Visible','off');


% --- Executes on button press in AllImages.
function AllImages_Callback(hObject, eventdata, handles)
% hObject    handle to AllImages (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
set(handles.Individ,'Value',0);
set(handles.checkbox3,'Value',0);
set(handles.uitable1,'Visible','on');
global INFO myGLOBAL T
D = INFO.Detected;

% Hint: get(hObject,'Value') returns toggle state of AllImages
rownames = {'Pr. Hmotnost [kDa]', 'Pr. Hm/pl [kDa/nm2]', 'Pocet objektov', ...
          'Okruhle','Pravouhle','Komplexne','Pr. Plocha [nm2]','Pr. Obvod [nm]',...
          'Plocha pozadia [nm2]', 'Pr. hodnota pozadia', 'Pr. hodnota objektu',...
          'Hmotnsot pozadia [kDa]', 'HmB/plB [kDa/nm2]'};
Mass = []; MPA = []; Area = []; Perim = []; Circ = []; Rect = []; Complex = [];
AVBAC = []; AVPAR = []; Bmass= []; Bmassarea = []; Barea= [];
  
for i = 1:length(D)
    if    isempty(myGLOBAL(D(i)).Boundaries)==0; 
    Back=myGLOBAL(D(i)).Background;
    dlz = T(D(i)).HEAD.PIXELSIZE(1);
      Mass = [Mass myGLOBAL(D(i)).GlobalProp.MASS];
      MPA = [MPA myGLOBAL(D(i)).GlobalProp.MASSPAREA];
      Area = [Area myGLOBAL(D(i)).GlobalProp.AREA*(dlz^2)];
      Perim = [Perim myGLOBAL(D(i)).GlobalProp.PERIMETER*dlz];
      Circ = [Circ myGLOBAL(D(i)).Shape1];
      Rect = [Rect myGLOBAL(D(i)).Shape2];
      Complex = [Complex myGLOBAL(D(i)).Shape3];
      AVBAC = [AVBAC myGLOBAL(D(i)).AVBACK];
      AVPAR = [AVPAR myGLOBAL(D(i)).AVPART];
      Bmass = [Bmass Back.Mass];
      Bmassarea = [Bmassarea Back.Mass_Area];
      Barea = [Barea Back.Area];
      
end
end
      numb = length(Mass);
      columnames = { 'Data'};
      data1 = [mean(Mass); mean(MPA); numb; mean(Circ); mean(Rect); mean(Complex); mean(Area); mean(Perim); mean(Barea);  mean(AVBAC); mean(AVPAR); mean(Bmass); mean(Bmassarea)];
      set(handles.uitable1,...
            'BackgroundColor',[0.93 0.93 0.93
                               0.7 0.9 0.9 ],...
            'Units','normalized',...
            'Data',data1,...
            'Enable','on',...
            'RowName',rownames,...
            'CellEditCallback',@inputTable_Callback,...
            'ColumnName', columnames);
% --- Executes on button press in Individ.
function Individ_Callback(hObject, eventdata, handles)
% hObject    handle to Individ (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
set(handles.AllImages,'Value',0);
set(handles.uitable1,'Visible','on');
set(handles.checkbox3,'Value',0);
global T myGLOBAL INFO
D = INFO.Detected;
% Hint: get(hObject,'Value') returns toggle state of Individ
columnnames = {'Pr. Hmotnost', 'Pr. Hmotnost/plocha', 'Pocet objektov', ...
          'Okruhle','Hranate','Komplexne','Pr. Plocha','Pr. Obvod',...
          'Plocha pozadia', 'Hmotnost pozadia','Pr. hodnota pozadia', 'Pr. hodnota obejktu'};

      
for i = 1:length(D)
     if    isempty(myGLOBAL(D(i)).Boundaries)==0; 
      rownames{i} = T(D(i)).FileName;
      GlobalProp = myGLOBAL(D(i)).GlobalProp;
      Back=myGLOBAL(D(i)).Background;
      dlz = T(D(i)).HEAD.PIXELSIZE(1);
%       data{i} = {mean(GlobalProp.MASS),mean(GlobalProp.MASSPAREA), length(GlobalProp.MASS),length(myGLOBAL(D(i)).Shape1),length(myGLOBAL(D(i)).Shape2),length(myGLOBAL(D(i)).Shape3),mean(GlobalProp.AREA),mean(GlobalProp.PERIMETER),Back.Area,Back.Mass,myGLOBAL(D(i)).AVBACK,myGLOBAL(D(i)).AVPART};
      data2(i,:) = [mean(GlobalProp.MASS),mean(GlobalProp.MASSPAREA), length(GlobalProp.MASS),length(myGLOBAL(D(i)).Shape1),length(myGLOBAL(D(i)).Shape2),length(myGLOBAL(D(i)).Shape3),mean(GlobalProp.AREA)*(dlz^2),mean(GlobalProp.PERIMETER)*dlz,Back.Area,Back.Mass,myGLOBAL(D(i)).AVBACK,myGLOBAL(D(i)).AVPART];
     end
end
% data = data';
    set(handles.uitable1,...
            'BackgroundColor',[0.93 0.93 0.93
                               0.7 0.9 0.9 ],...
            'Units','normalized',...
            'Data',data2,...
            'Enable','on',...
            'RowName',rownames,...
            'CellEditCallback',@inputTable_Callback,...
            'ColumnName', columnnames);


% --- Executes on selection change in listbox1.
function listbox1_Callback(hObject, eventdata, handles)
% hObject    handle to listbox1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global myGLOBAL T INFO
% Hints: contents = cellstr(get(hObject,'String')) returns listbox1 contents as cell array
%        contents{get(hObject,'Value')} returns selected item from listbox1
D = INFO.Detected;
VECTOR = INFO.KmeansVector;
pom2 = get(hObject,'Value');

HA = myGLOBAL(D(pom2)).Boundaries;
Im = mat2gray(T(D(pom2)).IMAGE.ORIG);
axes(handles.axes2);
imshow(Im)
hold(handles.axes2,'on')
vector = VECTOR(pom2);
        for ii = 1:length(HA)
            if vector{1,1}(ii)==1
                  hranice1 = HA{ii};
                  plot(handles.axes2,hranice1(:,2), hranice1(:,1),'Color','r', 'LineWidth', 1)
            elseif   vector{1,1}(ii)==2
                  hranice1 = HA{ii};
                  plot(handles.axes2,hranice1(:,2), hranice1(:,1),'Color','g', 'LineWidth', 1)
            elseif     vector{1,1}(ii)==3
                  hranice1 = HA{ii};
                  plot(handles.axes2,hranice1(:,2), hranice1(:,1),'Color','b', 'LineWidth', 1)
            elseif       vector{1,1}(ii)==4
                  hranice1 = HA{ii};
                  plot(handles.axes2,hranice1(:,2), hranice1(:,1),'Color','y', 'LineWidth', 1)
            else disp('chyba vo vykresleni')
            end
        end
        hold(handles.axes2,'off')
        guidata(hObject, handles);
% --- Executes during object creation, after setting all properties.
function listbox1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to listbox1 (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 button press in checkbox3.
function checkbox3_Callback(hObject, eventdata, handles)
% hObject    handle to checkbox3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

set(handles.Individ,'Value',0);
set(handles.AllImages,'Value',0);
set(handles.uitable1,'Visible','on');
global INFO myGLOBAL
D = INFO.Detected;

NORM = INFO.NORM;

% Hint: get(hObject,'Value') returns toggle state of AllImages
% rownames = {'Pr. Hmotnost', 'Pr. Hmotnost/plocha', 'Pocet objektov', ...
%           'Okruhle','Pravouhle','Komplexne','Pr. Plocha','Pr. Obvod',...
%           'Plocha pozadia', 'Hodnota pozadia', 'Pr. hodnota jasu objektu',...
%           'Hmotnsot pozadia', 'Hmotnsot pozadia/plocha'};
%       rownames = {'Pr. Hmotnost [kDa]', 'Pr. Hmotnost/plocha [kDa/nm2]', 'Pocet objektov', ...
%           'Okruhle','Pravouhle','Komplexne','Pr. Plocha [nm2]','Pr. Obvod [nm]',...
%           'Plocha pozadia [nm2]', 'Pr. hodnota pozadia', 'Pr. hodnota objektu',...
%           'Hmotnsot pozadia [kDa]', 'Hmotnsot pozadia/plocha [kDa/nm2]'};
rownames = {'NORMALNA HMOTNOST','Pr. Hmotnost [kDa]', 'Pr. Plocha [nm2]','Pr. Obvod [nm]',...
          'Hmotnsot/plocha [kDa/nm2]', ...
          'NORMALNA PLOCHA','Pr. Hmotnost [kDa]', 'Pr. Plocha [nm2]','Pr. Obvod [nm]',...
          'Hmotnsot/plocha [kDa/nm2]', ...
          'NORMALNA STD','Pr. Hmotnost [kDa]', 'Pr. Plocha [nm2]','Pr. Obvod [nm]',...
          'Hmotnsot/plocha [kDa/nm2]'};   

%   'Pr. hodnota pozadia', 'Pr. hodnota objektu','Hmotnsot pozadia [kDa]',...

%       numb = length(Mass);
      columnames = { 'Data'};
      data1 = [NORM.POCETM; NORM.MASSM; NORM.AREAM; NORM.PERIMM; NORM.MASSPAREAM; ...
               NORM.POCETA; NORM.MASSA; NORM.AREAA; NORM.PERIMA; NORM.MASSPAREAA;...
               NORM.POCETS; NORM.MASSS; NORM.AREAS; NORM.PERIMS; NORM.MASSPAREAS;];
      set(handles.uitable1,...
            'BackgroundColor',[0.93 0.93 0.93
                               0.7 0.9 0.9 ],...
            'Units','normalized',...
            'Data',data1,...
            'Enable','on',...
            'RowName',rownames,...
            'CellEditCallback',@inputTable_Callback,...
            'ColumnName', columnames);
