function varargout = assignment_one(varargin)
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @assignment_one_OpeningFcn, ...
                   'gui_OutputFcn',  @assignment_one_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 is made visible.
function assignment_one_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 (see VARARGIN)

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

% Update handles structure
guidata(hObject, handles);

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


% --- Outputs from this function are returned to the command line.
function varargout = assignment_one_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)
[filename, pathname] = uigetfile({'*.jpg';'*.bmp';'*.gif';'*.*'}, 'Pick an Image File');
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)
% 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)
image = handles.orginal;
flag = isrgb(image);
if flag == 1
GIm=uint8(zeros(size(image,1),size(image,2)));
    for i=1:size(image,1)
      for j=1:size(image,2)
          GIm(i,j)=0.2989*image(i,j,1)+0.5870*image(i,j,2)+0.1140*image(i,j,3);
      end
    end
    axes(handles.axes2);
    imshow(GIm);
else
    [row,col] = size(image);

for i=1:1:row
    for j=1:1:col
        if image(i,j)<= 50
            image(i,j) = 0;
        else if image(i,j)>= 150
            image(i,j) = 255;
            end
        end
    end
end
axes(handles.axes2);
imshow(image);
end
set(handles.edit1, 'string','this is gray scaled image');

% --- 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)
image = handles.orginal;
flag = isrgb(image);
if flag == 1
    image = rgb2gray(image);
    I=im2double(image);
    J=2*log(1+I);
    axes(handles.axes2);
    imshow(J);
else
    I=im2double(image);
    J=2*log(1+I);
    axes(handles.axes2);
    imshow(J);
end
    set(handles.edit1, 'string','this is log transformed image');


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

image = handles.orginal;
flag = isrgb(image);
if flag == 1
    image = rgb2gray(image);
    I2=im2double(image);
    m=mean2(I2);
    contrast1=1./(1+(m./(I2+eps)).^4);
    axes(handles.axes2);
    imshow(contrast1);
else
    I2=im2double(image);
    m=mean2(I2);
    contrast1=1./(1+(m./(I2+eps)).^4);
    axes(handles.axes2);
    imshow(contrast1);
end
set(handles.edit1, 'string','this is contrast streched image');

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

image = handles.orginal;
flag = isrgb(image);
if flag == 1
    image = rgb2gray(image);
    im_histeq=histeq(image);
    axes(handles.axes2);
    imshow(im_histeq);
    figure,imhist(im_histeq);
else
    im_histeq=histeq(image);    
    axes(handles.axes2);
    imshow(im_histeq);
    figure,imhist(im_histeq);
end
set(handles.edit1, 'string','this is histogram equalized image');

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


% --- 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)
image = handles.orginal;
flag = isrgb(image);
if flag == 1
    image = rgb2gray(image);
    [m n] = size(image);
    c = cell(1,8);
    for i = 1:m
        for j = 1:n
            b = image(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
f4 = c{1,1};
axes(handles.axes2);
imshow(f4);
else
        [m n] = size(image);
    c = cell(1,8);
    for i = 1:m
        for j = 1:n
            b = image(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
f4 = c{1,1};
axes(handles.axes2);
imshow(f4);
end
set(handles.edit1, 'string','this is bitplane sliced image');    
% --- Executes on button press in pushcontrast.
function pushcontrast_Callback(hObject, eventdata, handles)
% hObject    handle to pushcontrast (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
image = handles.orginal;
flag = isrgb(image);
if flag == 1
    image = rgb2gray(image);
    I2=im2double(image);
    m=mean2(I2);
    contrast1=1./(1+(m./(I2+eps)).^4);
    axes(handles.axes2);
    imshow(contrast1);
else
    I2=im2double(image);
    m=mean2(I2);
    contrast1=1./(1+(m./(I2+eps)).^4);
    axes(handles.axes2);
    imshow(contrast1);
end
set(handles.edit1, 'string','this is contrast streched image');


% --- Executes on button press in pushbutton10.
function pushbutton10_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton10 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
image = handles.original;
searchImageHist(image,'model1Hist.mat',10);
