Code covered by the BSD License  

Highlights from
Simple DIP demos

image thumbnail
from Simple DIP demos by Tan Chin Luh
Simple DIP demo using MATLAB 6.1, Image Processing Toolbox and NN Toolbox.

hwrec(varargin)
function varargout = hwrec(varargin)
% HWREC Application M-file for hwrec.fig
%    FIG = HWREC launch hwrec GUI.
%    HWREC('callback_name', ...) invoke the named callback.

% Last Modified by GUIDE v2.0 24-Jun-2002 01:14:29

if nargin == 0  % LAUNCH GUI

	fig = openfig(mfilename,'reuse');

	% Use system color scheme for figure:
	set(fig,'Color',get(0,'defaultUicontrolBackgroundColor'));

	% Generate a structure of handles to pass to callbacks, and store it. 
    
	handles = guihandles(fig);
	guidata(fig, handles);


    % Save data to structure
    handles.thresh=-1;
    guidata(fig,handles);
    
    if nargout > 0
		varargout{1} = fig;
	end

elseif ischar(varargin{1}) % INVOKE NAMED SUBFUNCTION OR CALLBACK

	try
		if (nargout)
			[varargout{1:nargout}] = feval(varargin{:}); % FEVAL switchyard
		else
			feval(varargin{:}); % FEVAL switchyard
		end
	catch
		disp(lasterr);
	end

end




%| ABOUT CALLBACKS:
%| GUIDE automatically appends subfunction prototypes to this file, and 
%| sets objects' callback properties to call them through the FEVAL 
%| switchyard above. This comment describes that mechanism.
%|
%| Each callback subfunction declaration has the following form:
%| <SUBFUNCTION_NAME>(H, EVENTDATA, HANDLES, VARARGIN)
%|
%| The subfunction name is composed using the object's Tag and the 
%| callback type separated by '_', e.g. 'slider2_Callback',
%| 'figure1_CloseRequestFcn', 'axis1_ButtondownFcn'.
%|
%| H is the callback object's handle (obtained using GCBO).
%|
%| EVENTDATA is empty, but reserved for future use.
%|
%| HANDLES is a structure containing handles of components in GUI using
%| tags as fieldnames, e.g. handles.figure1, handles.slider2. This
%| structure is created at GUI startup using GUIHANDLES and stored in
%| the figure's application data using GUIDATA. A copy of the structure
%| is passed to each callback.  You can store additional information in
%| this structure at GUI startup, and you can change the structure
%| during callbacks.  Call guidata(h, handles) after changing your
%| copy to replace the stored original so that subsequent callbacks see
%| the updates. Type "help guihandles" and "help guidata" for more
%| information.
%|
%| VARARGIN contains any extra arguments you have passed to the
%| callback. Specify the extra arguments by editing the callback
%| property in the inspector. By default, GUIDE sets the property to:
%| <MFILENAME>('<SUBFUNCTION_NAME>', gcbo, [], guidata(gcbo))
%| Add any extra arguments after the last argument, before the final
%| closing parenthesis.



% --------------------------------------------------------------------
function varargout = pbLoad_Callback(h, eventdata, handles, varargin)

% Load Image
temp = cd;
% cd c:\MATLAB6p1\work\TestContainer\NNproject;
[filename, pathname] = uigetfile('*.bmp'); 
S = imread([pathname filename]);
cd(temp);

set(handles.pbSave,'enable','off');


if strcmp('trg',filename(1:3))
    uiwait(msgbox('Training Data Loaded!','Data loaded!'));
    axes(handles.axesMain);
    imshow(S);
    set(handles.radioRecog,'value',0);
    set(handles.radioTrain,'value',1);
    set(handles.pbPreprocess,'enable','on');
    set(handles.pbTrain,'enable','on');
    set(handles.pbRecog,'enable','off');
    set(handles.sldThreshold,'enable','on');
    set(handles.tgTV,'enable','on');
    handles.S=S;
    guidata(h,handles);
    
elseif strcmp('sim',filename(1:3))
    uiwait(msgbox('Simulation Data Loaded!','Data loaded!'));
    axes(handles.axesMain);
    imshow(S);
    set(handles.radioRecog,'value',1);
    set(handles.radioTrain,'value',0);
    set(handles.pbPreprocess,'enable','on');
    set(handles.pbTrain,'enable','off');
    set(handles.pbRecog,'enable','on');
    set(handles.sldThreshold,'enable','on');
    set(handles.tgTV,'enable','on');
    handles.S=S;
    guidata(h,handles);

else
    uiwait(error('Error data type!','No Data loaded!'));
    
end
% --------------------------------------------------------------------
function varargout = pbTrain_Callback(h, eventdata, handles, varargin)

NNdata = handles.NNdata;
[NNinput NNtarget]=traindata(NNdata);
%figure;
%dataplot(NNdata);
[net,tr] = creatnn(NNinput,NNtarget)

handles.net=net;
guidata(h,handles);


% --------------------------------------------------------------------
function varargout = pbRecog_Callback(h, eventdata, handles, varargin)

net=handles.net;
NNdata = handles.NNdata;
NNinput=simdata(NNdata);


for cnt = 1:5
 NNoutput=sim(net,NNinput(:,cnt));
 NNoutput=compet(NNoutput);
 answer=find(compet(NNoutput)==1);
 if answer == 10
     answer=0;
 end
 answer=answer+48;
 txtAnswer(cnt)=char(answer);
 set(handles.editText,'string',txtAnswer);
end

set(handles.pbSave,'enable','on');

handles.txtAnswer=txtAnswer;
guidata(h,handles);

% --------------------------------------------------------------------
function varargout = pbSave_Callback(h, eventdata, handles, varargin)

txtAnswer=handles.txtAnswer;
% Load Image
temp = cd;
% cd c:\MATLAB6p1\work\TestContainer\NNproject;
[filename, pathname] = uiputfile('*.txt'); 
fid = fopen([pathname filename],'w');
fprintf(fid,'%s',txtAnswer);
fclose(fid);

cd(temp);


% --------------------------------------------------------------------
function varargout = sldThreshold_Callback(h, eventdata, handles, varargin)

thresh = get(h,'value');
set(handles.tgTV,'string',thresh);
handles.thresh=thresh;
guidata(h,handles);

% --------------------------------------------------------------------
function varargout = tgTV_Callback(h, eventdata, handles, varargin)


if get(h,'value') == 0
    set(h,'value',0);
    set(h,'string','auto');
    set(handles.sldThreshold,'enable','off');
    thresh = -1;
else
    set(h,'value',1);
    set(h,'string','0.75');
    set(handles.sldThreshold,'enable','on');
    set(handles.sldThreshold,'value',0.75);
    thresh = 0.75;
end

% Save data to structure
handles.thresh=thresh;
guidata(h,handles);


% --------------------------------------------------------------------
function varargout = pbPreprocess_Callback(h, eventdata, handles, varargin)

thresh = handles.thresh;
S = handles.S;

if get(handles.radioTrain,'value') == 1
       [NNdata pic_roi]=cropNbox(S,thresh); 
       axes(handles.axesMain);
       imshow(pic_roi);
   else
       NNdata=crop5box(S,thresh);
       axes(handles.axes1);
       imshow(NNdata(:,:,1));
       axes(handles.axes2);
       imshow(NNdata(:,:,2));
       axes(handles.axes3);
       imshow(NNdata(:,:,3));
       axes(handles.axes4);
       imshow(NNdata(:,:,4));
       axes(handles.axes5);
       imshow(NNdata(:,:,5));
 
end

handles.NNdata=NNdata;
guidata(h,handles);


% --------------------------------------------------------------------
function varargout = radioTrain_Callback(h, eventdata, handles, varargin)

set(h,'value',1);
set(handles.radioRecog,'value',0);
set(handles.pbTrain,'enable','on');
set(handles.pbRecog,'enable','off');


% --------------------------------------------------------------------
function varargout = radioRecog_Callback(h, eventdata, handles, varargin)

set(h,'value',1);
set(handles.radioTrain,'value',0);
set(handles.pbTrain,'enable','off');
set(handles.pbRecog,'enable','on');





% --------------------------------------------------------------------
function varargout = editText_Callback(h, eventdata, handles, varargin)

Contact us at files@mathworks.com