📄 kaishishibie.m
字号:
function varargout = kaishishibie(varargin)
% KAISHISHIBIE M-file for kaishishibie.fig
% KAISHISHIBIE, by itself, creates a new KAISHISHIBIE or raises the existing
% singleton*.
%
% H = KAISHISHIBIE returns the handle to a new KAISHISHIBIE or the handle to
% the existing singleton*.
%
% KAISHISHIBIE('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in KAISHISHIBIE.M with the given input arguments.
%
% KAISHISHIBIE('Property','Value',...) creates a new KAISHISHIBIE or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before kaishishibie_OpeningFunction gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to kaishishibie_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 kaishishibie
% Last Modified by GUIDE v2.5 22-Nov-2008 20:20:52
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @kaishishibie_OpeningFcn, ...
'gui_OutputFcn', @kaishishibie_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 kaishishibie is made visible.
function kaishishibie_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 kaishishibie (see VARARGIN)
% Choose default command line output for kaishishibie
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes kaishishibie wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = kaishishibie_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({'*.bmp';'*.jpg';'*.gif';'*.*'}, 'Pick an Image File');%读取图片数据
P= imread([pathname,filename]);
handles.P = P;
guidata(hObject, handles);
%图像边缘清晰化处理
X=im2bw(P);
%寻找边界
%寻找下边界
shang=0;
xia=0;
zuo=0;
you=0;
for i=1:length(X(:,1))
for j=1:length(X(1,:))
if(X(i,j)==0)
xia=i;break;
end
end
end
%寻找右边界
for i=1:length(X(1,:))
for j=1:length(X(:,1))
if(X(j,i)==0)
you=i;break;
end
end
end
X=X';
%寻找左边界
for i=length(X(:,1)):-1:1
for j=length(X(1,:)):-1:1
if(X(i,j)==0)
zuo=i;break;
end
end
end
%寻找上边界
for i=length(X(1,:)):-1:1
for j=length(X(:,1)):-1:1
if(X(j,i)==0)
shang=i;break;
end
end
end
%fprintf('手写文字上下左右边界:\n');
h=[shang xia zuo you] ;
%fprintf('手写文字数据矩阵:\n');
X=X';
%截图
Q=zeros(xia-shang,you-zuo);
for i=shang:xia
for j=zuo:you
Q(i-shang+1,j-zuo+1)=X(i,j);
end
end
Q;
%fprintf('截图并压缩后为Q:\n');
%Q=imresize(Q,[10 6]);%缩放为7行5列的矩阵
A=cell(1,36);
A{1}=[ 255 255 255 255 255 255 0 0 0 0 255 255 255 0 0
255 255 255 255 255 0 0 0 255 255 255 255 0 0 0
255 255 255 255 255 0 0 0 255 255 255 255 0 0 0
255 255 255 0 0 0 255 255 255 255 255 255 0 0 0
255 255 255 0 0 0 255 255 255 255 255 255 0 0 0
255 0 0 0 0 255 255 255 255 255 255 255 0 0 0
255 0 0 0 0 255 255 255 255 255 255 255 255 0 0
255 0 0 0 0 255 255 255 255 255 255 255 255 0 0
0 0 0 0 0 255 255 255 255 255 255 255 0 0 0
0 0 0 255 255 255 255 255 255 255 255 255 0 0 0
0 0 0 255 255 255 255 255 255 255 255 255 0 0 0
0 0 0 255 255 255 255 255 255 255 255 255 0 255 255
0 0 0 255 255 255 255 255 255 255 255 255 0 255 255
0 0 0 255 255 255 255 255 255 255 0 0 0 255 255
0 0 0 255 255 255 255 255 255 255 0 0 0 255 255
0 0 0 255 255 255 255 255 255 255 0 0 255 255 255
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -