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

% Last Modified by GUIDE v2.5 04-Dec-2011 02:38:50

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

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

% Update handles structure
guidata(hObject, handles);

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


% --- Outputs from this function are returned to the command line.
function varargout = assignment_one_slic_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 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 orginal
[filename, pathname] = uigetfile({ '*.jpg'; '*.jpeg'; '*.bmp'; '*.gif'; '*.tiff'; '*.png' }, 'Select an Image...');
orginal = imread([pathname,filename]);
%orginal = rgb2gray(orginal);
axes(handles.axes1);
imshow(orginal);

handles.orginal = orginal;
guidata(hObject, handles);


% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
sl = handles.orginal;
[m n] = size(sl);
c = cell(1,8);
for i = 1:m
for j = 1:n
b = sl(i,j);
if ( b >= 128)
b = b-128; c{1,1}(i,j) = 1;
else
c{1,1}(i,j) = 0;
end
if (b >= 64)
b = b - 64; c{1,2}(i,j) = 1;
else
c{1,2}(i,j) = 0;
end
if (b >= 32)
b = b - 32; c{1,3}(i,j) = 1;
else
c{1,3}(i,j) = 0;
end
if (b >= 16)
b = b - 16; c{1,4}(i,j) = 1;
else
c{1,4}(i,j) = 0;
end
if (b >= 8)
b = b - 8; c{1,5}(i,j) = 1;
else
c{1,5}(i,j) = 0;
end
if (b >= 4)
b = b - 4; c{1,6}(i,j) = 1;
else
c{1,6}(i,j) = 0;
end
if (b >= 2)
b = b - 2; c{1,7}(i,j) = 1;
else
c{1,3}(i,j) = 0;
end
if (b >= 1)
b = b - 1; c{1,8}(i,j) = 1;
else
c{1,8}(i,j) = 0;
end
end
end
sl1 = c{1,1}; sl2 = c{1,2}; sl3 = c{1,3}; sl4 = c{1,4};
sl5 = c{1,5}; sl6 = c{1,6}; sl7 = c{1,7}; sl8 = c{1,8};

axes(handles.axes2);
imshow(sl1),title('Bit-Plane 0');
axes(handles.axes3);
imshow(sl2),title('Bit-Plane 1');
axes(handles.axes4);
imshow(sl3),title('Bit-Plane 2');
axes(handles.axes5);
imshow(sl4),title('Bit-Plane 3');
axes(handles.axes6);
imshow(sl5),title('Bit-Plane 4');
axes(handles.axes7);
imshow(sl6),title('Bit-Plane 5');
axes(handles.axes8);
imshow(sl7),title('Bit-Plane 6');
 axes(handles.axes9);
 imshow(sl8),title('Bit-Plane 7');
