Code covered by the BSD License  

Highlights from
image effect

image thumbnail

image effect

by

 

06 Oct 2011 (Updated )

lets you take a picture or browse for it and put some effects on it

invclr(varargin)
function varargout = invclr(varargin)
% INVCLR M-file for invclr.fig
%left x:296
%right x:738
%top y: 480
%botton y: 570
%[296 570 442 90]
%      INVCLR, by itself, creates a new INVCLR or raises the existing
%      singleton*.
%
%      H = INVCLR returns the handle to a new INVCLR or the handle to
%      the existing singleton*.
%
%      INVCLR('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in INVCLR.M with the given input arguments.
%
%      INVCLR('Property','Value',...) creates a new INVCLR or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before invclr_OpeningFunction gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to invclr_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

% Copyright 2002-2003 The MathWorks, Inc.

% Edit the above text to modify the response to help invclr

% Last Modified by GUIDE v2.5 14-Jul-2012 21:51:39

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @invclr_OpeningFcn, ...
                   'gui_OutputFcn',  @invclr_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 invclr is made visible.
function invclr_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 invclr (see VARARGIN)
disp('please ignore all the errors....')
imaqreset
try
stop(imaqfind);
end
try
    load CameraSettings
catch
    WE=CameraSettings;
    save CameraSettings WE
end
try
    handles.vid=videoinput(WE);
    set(handles.vid,'ReturnedColorSpace','RGB')
    triggerconfig(handles.vid,'manual')
    set(handles.vid,'TimerFcn',{@timer_callback,handles})
    set(handles.vid,'Timerperiod',0.05)
catch
    set(handles.Picture,'Visible','Off')
end

set(handles.slider1,'Backgroundcolor',[1 0 0])
set(handles.slider2,'Backgroundcolor',[0 1 0])
set(handles.slider3,'Backgroundcolor',[0 0 1])
set([handles.slider1,handles.slider2,handles.slider3,handles.reset1,handles.reset2,handles.reset3],'Visible','off')
%triggerconfig(handles.vid,'manual');
load DONOTDELETE
set(handles.changedesign,'CData',A)
axes(handles.axes1)
title('input')
axes(handles.axes2)
title('output')
% Choose default command line output for invclr
handles.output = 0;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes invclr wait for user response (see UIRESUME)
uiwait(handles.figure2);

% --- Outputs from this function are returned to the command line.
function varargout = invclr_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
handles.output=0;
varargout{1} = handles.output;


% --- Executes on button press in button.
function button_Callback(hObject, eventdata, handles)
% hObject    handle to button (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
try
B=handles.image;
B=255-B;
axes(handles.axes2)
imshow(B)
handles.image2=B;
catch
errordlg('there was an error','error')
end
guidata(hObject, handles);
function imdir_Callback(hObject, eventdata, handles)
% hObject    handle to imdir (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 imdir as text
%        str2double(get(hObject,'String')) returns contents of imdir as a double

a=get(hObject,'String');
if isempty(a)
    return
else
axes(handles.axes1);
try
handles.image=imread(a);
imshow(handles.image)
catch
set(handles.imdir,'String','')
errordlg('invalid path','error')
end
set([handles.slider1,handles.slider2,handles.slider3],'Value',0.5)
guidata(hObject,handles)
end

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




% --- Executes on button press in browser.
function browser_Callback(hObject, eventdata, handles)
% hObject    handle to browser (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
[b a]=uigetfile('*.jpg;*.tif;*.png;*.bmp');
if a==0 & b==0
    return
end
a=strcat(a,b);
set(handles.imdir,'String',a)
handles.image=imread(a);
axes(handles.axes1)
imshow(handles.image)
set([handles.slider1,handles.slider2,handles.slider3],'Value',0.5)
guidata(hObject,handles)









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

% Number of image frames to acquire. 
if strcmp(get(hObject,'String'),'Take your Picture')
    start(handles.vid)
    set(hObject,'String','Ready Then Press Again...')
else
    stop(handles.vid)
    set(hObject,'String','Take your Picture')
end
set([handles.slider1,handles.slider2,handles.slider3],'Value',0.5)
guidata(hObject,handles)


% --- Executes on button press in edgebutton.
function edgebutton_Callback(hObject, eventdata, handles)
% hObject    handle to edgebutton (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
try
B=handles.image;
if numel(size(B))==2
B=edge(B,'canny');
else
B=edge(B(:,:,2),'canny');
end
C=find(B==1);
D=find(B==0);
B(C)=0;
B(D)=1;
axes(handles.axes2)
imshow(B)
handles.image2=B;
catch
errordlg('there was an error','error')
end
guidata(hObject,handles)

% --- Executes on button press in gray.
function gray_Callback(hObject, eventdata, handles)
% hObject    handle to gray (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
try
B=handles.image;
B=rgb2gray(B);
axes(handles.axes2)
imshow(B)
handles.image2=B;
catch
errordlg('there was an error','error')
end
guidata(hObject,handles)


% --- Executes on button press in saver.
function saver_Callback(hObject, eventdata, handles)
% hObject    handle to saver (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
try
A=handles.image2;
J={'*.jpg', 'JPEG picture';...
    '*.png', 'PNG picture';...
    '*.bmp', 'BMP picture';...
    '*.tif', 'TIF picture'};
[a b c]=uiputfile(J,'save your image');
switch c
    case 0
        return
    case 1
        q='.jpg';
    case 2
        q='.png';
    case 3
        q='.bmp';
    case 4
        q='.tif';
end
filename=[b a q];
imwrite(A,filename,q(2:4))
catch
    errordlg('there was an error','error')
end


% --- Executes on button press in samepic.
function samepic_Callback(hObject, eventdata, handles)
% hObject    handle to samepic (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
try
    B=handles.image;
    axes(handles.axes2)
    imshow(B)
    handles.image2=B;
catch
    errordlg('there was an error','error')
end
guidata(hObject, handles);


% --- Executes on button press in imageview.
function imageview_Callback(hObject, eventdata, handles)
% hObject    handle to imageview (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
try
    A=handles.image2;
    imview(A)
catch
    errordlg('there was an error','error')
end



% --- 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
try
B=handles.image;
x=get([handles.slider1,handles.slider2,handles.slider3],'Value');
for k=1:3
    y=x{k}*510-255;
    B(:,:,k)=B(:,:,k)+y;
end
axes(handles.axes2)
imshow(B)
handles.image2=B;
catch
errordlg('there was an error','error')
end
guidata(hObject,handles)



% --- 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, change
%       'usewhitebg' to 0 to use default.  See ISPC and COMPUTER.
usewhitebg = 1;
if usewhitebg
    set(hObject,'BackgroundColor',[.9 .9 .9]);
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end


% --- Executes on slider movement.
function slider2_Callback(hObject, eventdata, handles)
% hObject    handle to slider2 (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
try
B=handles.image;
x=get([handles.slider1,handles.slider2,handles.slider3],'Value');
for k=1:3
    y=x{k}*510-255;
    B(:,:,k)=B(:,:,k)+y;
end
axes(handles.axes2)
imshow(B)
handles.image2=B;
catch
errordlg('there was an error','error')
end
guidata(hObject,handles)

% --- Executes during object creation, after setting all properties.
function slider2_CreateFcn(hObject, eventdata, handles)
% hObject    handle to slider2 (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, change
%       'usewhitebg' to 0 to use default.  See ISPC and COMPUTER.
usewhitebg = 1;
if usewhitebg
    set(hObject,'BackgroundColor',[.9 .9 .9]);
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end


% --- Executes on slider movement.
function slider3_Callback(hObject, eventdata, handles)
% hObject    handle to slider3 (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
try
B=handles.image;
x=get([handles.slider1,handles.slider2,handles.slider3],'Value');
for k=1:3
    y=x{k}*510-255;
    B(:,:,k)=B(:,:,k)+y;
end
axes(handles.axes2)
imshow(B)
handles.image2=B;
catch
errordlg('there was an error','error')
end
guidata(hObject,handles)

% --- Executes during object creation, after setting all properties.
function slider3_CreateFcn(hObject, eventdata, handles)
% hObject    handle to slider3 (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, change
%       'usewhitebg' to 0 to use default.  See ISPC and COMPUTER.
usewhitebg = 1;
if usewhitebg
    set(hObject,'BackgroundColor',[.9 .9 .9]);
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end




% --- Executes on button press in reset1.
function reset1_Callback(hObject, eventdata, handles)
% hObject    handle to reset1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
set(handles.slider1,'value',0.5)
slider1_Callback(hObject, 0, handles)
% --- Executes on button press in reset2.
function reset2_Callback(hObject, eventdata, handles)
% hObject    handle to reset2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
set(handles.slider2,'value',0.5)
slider1_Callback(hObject, 0, handles)
% --- Executes on button press in reset3.
function reset3_Callback(hObject, eventdata, handles)
% hObject    handle to reset3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
set(handles.slider3,'value',0.5)
slider1_Callback(hObject, 0, handles)


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

% Hint: get(hObject,'Value') returns toggle state of rggcontrol
a=get(hObject,'Value');
if a==1
    set([handles.slider1,handles.slider2,handles.slider3,handles.reset1,handles.reset2,handles.reset3],'Visible','on')
    set([handles.samepic,handles.gray,handles.button,...
         handles.edgebutton,handles.tskuyomi,handles.changedesign],...
         'Visible','off')
elseif a==0
    set([handles.slider1,handles.slider2,handles.slider3,handles.reset1,handles.reset2,handles.reset3],'Visible','off')
    set([handles.samepic,handles.gray,handles.button,...
         handles.edgebutton,handles.rggcontrol,handles.tskuyomi,handles.changedesign],...
         'Visible','on')
end




% --- Executes on button press in tskuyomi.
function tskuyomi_Callback(hObject, eventdata, handles)
% hObject    handle to tskuyomi (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
%try
B=handles.image;
A=B;
A1=A(:,:,1);
A2=A(:,:,2);
A3=A(:,:,3);
type=1;
h=waitbar(0,'Please Wait...');
for i=1:3
eval(['A=A' num2str(i) ';'])
[lnth wdth]=size(A);
if floor(lnth/2)==lnth/2
    A(lnth+1,:)=255;
end
if floor(wdth/2)==wdth/2
    A(:,wdth+1)=255;
end
[lnth wdth]=size(A);
B=A;
if lnth>wdth
    l=lnth;
else
    l=wdth;
end
u=(lnth+1)/2;
r=(wdth+1)/2;
for n=1:(l-1)/2
    waitbar((i-1+2*n/(l-1))/3,h,'finally starting');
    neighbors=[];
    %top
    for k=-n:n
        try
            A(u-n,r+k);
            if isempty(find(neighbors==(r+k-1)*lnth+u-n))
                neighbors=[neighbors (r+k-1)*lnth+u-n];
            end
        catch
        end
    end
    %right
    for k=-n:n
        try
            A(u+k,r+n);
            if isempty(find(neighbors==(r+n-1)*lnth+u+k))
                neighbors=[neighbors (r+n-1)*lnth+u+k];
            end
        catch
        end
    end
    %bottom
    for k=-n:n
        try
            A(u+n,r-k);
            if isempty(find(neighbors==(r-k-1)*lnth+u+n))
                neighbors=[neighbors (r-k-1)*lnth+u+n];
            end
        catch
        end
    end
    %left
    for k=-n:n
        try
            A(u-k,r-n);
            if isempty(find(neighbors==(r-n-1)*lnth+u-k))
                neighbors=[neighbors (r-n-1)*lnth+u-k];
            end
        catch
        end
    end
    num=numel(neighbors);
    ment=rem(n^2,num);
    try
    adj=[neighbors(ment+1:num) neighbors(1:ment)];
    catch
        adj=[neighbors(bb*n+1-num:num) neighbors(1:n*bb-num)];
    end
    if type==1
        B(adj)=A(neighbors);   %rotates right side
    else
        B(neighbors)=A(adj);   %roates left side
    end
    %M(n)=im2frame(B);
end
eval(['B' num2str(i) '=B;'])
end
B(:,:,1)=B1;
B(:,:,2)=B2;
B(:,:,3)=B3;
%movie(M)
axes(handles.axes2)
imshow(B)
handles.image2=B;
close(h)
%catch
%errordlg('there was an error','error')
%end
guidata(hObject,handles)


% --- Executes on button press in CameraSett.
function CameraSett_Callback(hObject, eventdata, handles)
% hObject    handle to CameraSett (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
load CameraSettings
try
WE=CameraSettings(WE);
catch
    WE=CameraSettings
end
save CameraSettings WE
try
    handles.vid=videoinput(WE);
    set(handles.Picture,'Visible','On')
    set(handles.vid,'ReturnedColorSpace','RGB');
    triggerconfig(handles.vid,'manual')
        set(handles.vid,'TimerFcn',{@timer,handles})
    set(handles.vid,'Timerperiod',0.05)
catch
    set(handles.Picture,'Visible','Off')
end
guidata(hObject,handles)

function timer_callback(hObject,eventdata,handles)
if(~isempty(gco))
handles.image=getsnapshot(handles.vid);
set(gcf,'CurrentAxes',handles.axes1)
imshow(handles.image)

else
    delete(imaqfind)
end
guidata(handles.figure2,handles)





% --- Executes on button press in changedesign.
function changedesign_Callback(hObject, eventdata, handles)
% hObject    handle to changedesign (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
try
B=ones(301,401,3);
%B=B*255;
handles.image=handles.image2;
handles.image2=B;
axes(handles.axes1)
imshow(handles.image)
axes(handles.axes2)
imshow(B)
catch
errordlg('There must be a picture','error')
end
guidata(hObject,handles)

Contact us