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

% Last Modified by GUIDE v2.5 30-Nov-2003 14:22:28

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @Third_slide_OpeningFcn, ...
                   'gui_OutputFcn',  @Third_slide_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin & isstr(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 Third_slide is made visible.
function Third_slide_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 Third_slide (see VARARGIN)

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

% Update handles structure
guidata(hObject, handles);

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


% --- Outputs from this function are returned to the command line.
function varargout = Third_slide_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 during object creation, after setting all properties.
function listbox2_CreateFcn(hObject, eventdata, handles)
% hObject    handle to listbox2 (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
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end


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






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

fig = gcf;
   quit_reply = questdlg('Really quit this lame example?');
   if strcmp(quit_reply,'Yes')
      close(fig);

  end


% --- Executes during object creation, after setting all properties.
function listbox3_CreateFcn(hObject, eventdata, handles)
% hObject    handle to listbox3 (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
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end


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


contents = get(hObject,'String'); 
val=get(hObject,'Value'); 

switch(val)
    
    case 2
         D=imread('fig_1.jpg');
         axes(handles.axes3)
         image(D);
         handles.mydata=D
         guidata(hObject, handles)
    case 3
         D=imread('fig_2.jpg');
        axes(handles.axes3)
         image(D);
         handles.mydata=D
         guidata(hObject, handles)
       case 4
         D=imread('fig_3.jpg');
         axes(handles.axes3)
         image(D);
         handles.mydata=D
         guidata(hObject, handles)
    case 5
         D=imread('fig_4.jpg');
         axes(handles.axes3)
         image(D);
         handles.mydata=D
         guidata(hObject, handles)
    case 6
         D=imread('fig_5.jpg');
         axes(handles.axes3)
         image(D);
         handles.mydata=D
         guidata(hObject, handles)
    case 7
         D=imread('fig_6.jpg');
         axes(handles.axes3)
         image(D);
         handles.mydata=D
         guidata(hObject, handles)

     
     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)
X=handles.mydata;

%I1=imread('fig_6.jpg');
I=im2double(X);
% figure;
% imshow(I)

% constraints and initial conditions
% seed pixel is choosen as (45,45)
[rs,cl]=size(I);
temp = zeros(size(I));
temp_out = zeros(size(I));
thres = 0.02;
x=10;
y=80;
temp(x,y) = 1;
done = 0; %flag to stop the iteration

while(done == 0)
   for i = 2:rs-1
      for j = 2:cl-1
         if(temp(i,j)==1)
            if((temp_out(i-1,j)==0)& (abs(I(i,j)-I(i-1,j))<=thres)) % north pixel 
               temp_out(i-1,j) = 1; 
            end
            if((temp_out(i-1,j+1)==0)& (abs(I(i,j)-I(i-1,j+1))<=thres)) % north-east pixel 
               temp_out(i-1,j+1) = 1; 
            end
            if((temp_out(i,j+1)==0)& (abs(I(i,j)-I(i,j+1))<=thres)) % east pixel 
               temp_out(i,j+1) = 1; 
            end
            if((temp_out(i+1,j+1)==0)& (abs(I(i,j)-I(i+1,j+1))<=thres)) % south-east pixel 
               temp_out(i+1,j+1) = 1; 
            end
            if((temp_out(i+1,j)==0)& (abs(I(i,j)-I(i+1,j))<=thres)) % south pixel 
               temp_out(i+1,j) = 1; 
            end
            if((temp_out(i+1,j-1)==0)& (abs(I(i,j)-I(i+1,j-1))<=thres)) % south-west pixel 
               temp_out(i+1,j-1) = 1; 
            end
            if((temp_out(i,j-1)==0)& (abs(I(i,j)-I(i,j-1))<=thres)) % west pixel 
               temp_out(i,j-1) = 1; 
            end
            if((temp_out(i-1,j-1)==0)& (abs(I(i,j)-I(i-1,j-1))<=thres)) % north-west pixel 
               temp_out(i-1,j-1) = 1; 
            end
         end
      end
   end
   if(temp_out==temp)
      done = 1;
   else
      temp = temp_out;
      temp_out = zeros(size(I));
   end
end % end of while

figure;
imshow(temp_out)

axes(handles.axes3)
 image(X);
axes(handles.axes4)
  imshow(temp_out);