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
function assignment_one_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);
function varargout = assignment_one_OutputFcn(hObject, eventdata, handles) 
varargout{1} = handles.output;


% --- this function used for image browsing 
function pushbutton1_Callback(hObject, eventdata, handles)
[filename, pathname] = uigetfile({'*.jpg';'*.bmp';'*.gif';'*.*'}, 'Pick an Image File');
orginal = imread([pathname,filename]);
axes(handles.axes1);
imshow(orginal);
handles.orginal = orginal;
guidata(hObject, handles);
% --- this function used for changing image to grayscale
function pushbutton2_Callback(hObject, eventdata, handles)
image = handles.orginal;
imageflag = isrgb(image);
if imageflag == 1
GIm=uint8(zeros(size(image,1),size(image,2)));
    for i=1:size(image,1)
      for j=1:size(image,2)
          resultim(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(resultim);
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');

%this function used for changing image to logtransformation;
function pushbutton3_Callback(hObject, eventdata, handles)
image = handles.orginal;
imageflag = isrgb(image);
if imageflag == 1
    image = rgb2gray(image);
    Im=im2double(image);
    Jim=2*log(1+Im);
    axes(handles.axes2);
    imshow(Jim);
else
    Im=im2double(image);
    Jim=2*log(1+Im);
    axes(handles.axes2);
    imshow(J);
end
    set(handles.edit1, 'string','this is log transformed image');
    %this is function for changing image to contrast streching; 
function pushbutton4_Callback(hObject, eventdata, handles)
image = handles.orginal;
imageflag = isrgb(image);
if imageflag == 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');

%this function used for changing image to histogram qualization;
function pushbutton5_Callback(hObject, eventdata, handles)
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_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end
% this is function for changing image to bitpane slicing;
function pushbutton6_Callback(hObject, eventdata, handles)
image = handles.orginal;
imageflag = isrgb(image);
if imageflag == 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
resultimage = c{1,1};%we can seee the effect by varying the effect of c.
axes(handles.axes2);
imshow(resultimage);
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
resultimage= c{1,1};%we can seee the effect by varying the effect of c.
axes(handles.axes2);
imshow(resultimage);
end
set(handles.edit1, 'string','this is bitplane sliced image');    
function pushcontrast_Callback(hObject, eventdata, handles)
image = handles.orginal;
imageflag = isrgb(image);
if imageflag == 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');
%this is function 
function pushbutton10_Callback(hObject, eventdata, handles)
image = handles.original;
searchImageHist(image,'model.mat',1);
set(handles.edit1, 'string','here is the searched  image');
