gusucode.com > matlab程序语言实现的水准网平差程序,使用于测绘人员 > 一种基于极大值稳定区域的文本定位方法matlab源码程序/毕业设计/代码/textlocalization.m
function varargout = textlocalization(varargin) % TEXTLOCALIZATION MATLAB code for textlocalization.fig % TEXTLOCALIZATION, by itself, creates a new TEXTLOCALIZATION or raises the existing % singleton*. % % H = TEXTLOCALIZATION returns the handle to a new TEXTLOCALIZATION or the handle to % the existing singleton*. % % TEXTLOCALIZATION('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in TEXTLOCALIZATION.M with the given input arguments. % % TEXTLOCALIZATION('Property','Value',...) creates a new TEXTLOCALIZATION or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before textlocalization_OpeningFcn gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to textlocalization_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 % Edit the above text to modify the response to help textlocalization % Last Modified by GUIDE v2.5 11-Jun-2018 17:54:16 % Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @textlocalization_OpeningFcn, ... 'gui_OutputFcn', @textlocalization_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 textlocalization is made visible. function textlocalization_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 textlocalization (see VARARGIN) % Choose default command line output for textlocalization handles.output = hObject; % Update handles structure guidata(hObject, handles); % UIWAIT makes textlocalization wait for user response (see UIRESUME) % uiwait(handles.figure1); % --- Outputs from this function are returned to the command line. function varargout = textlocalization_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('*.*','choose a picture'); path = [pathname filename]; colorImage = imread(path); grayImage = rgb2gray(colorImage);%转化成灰度图像 [mserRegions] = detectMSERFeatures(grayImage,'regionAreaRange',[70 4500],'ThresholdDelta',2.6);%提取MSER特称 % [mserRegions] = detectMSERFeatures(grayImage,'ThresholdDelta',1);%提取MSER特称 %联通区像素索引列表 pixelIdxList=cellfun(@(xy)sub2ind(size(grayImage),xy(:,2),xy(:,1)),mserRegions.PixelList,'UniformOutput',false); % 创建结构体mserConnComp存储MSER区域 mserConComp.Connectivity = 8; mserConComp.ImageSize = size(grayImage); mserConComp.NumObjects = mserRegions.Count; mserConComp.PixelIdxList = pixelIdxList; axes(handles.axes1); imshow(colorImage); %基本特征过滤 [mserStats,mserRegions] =conComp_filter(mserConComp,mserRegions,grayImage); %笔画宽度过滤 [mserRegions,mserStats]=line_filter(mserStats,mserRegions,grayImage); %转换 [mserboxes]=change(mserStats,mserConComp); %合并 [mserboxes]=re_define(mserStats,mserboxes,grayImage); broder=[mserboxes.BoundingBox]; axes(handles.axes2); imshow(colorImage); hold on; for i=1:numel(mserStats) leftx=broder((i-1)*4+1); lefty=broder((i-1)*4+2); width=broder((i-1)*4+3); height=broder((i-1)*4+4); rectangle('Position',[leftx,lefty,width,height], 'EdgeColor','g'); end hold off; %分类器 [mserboxes,mserStats]=SVM_filter(mserboxes,mserStats,grayImage); broder=[mserboxes.BoundingBox]; axes(handles.axes3); imshow(colorImage); hold on; for i=1:numel(mserStats) leftx=broder((i-1)*4+1); lefty=broder((i-1)*4+2); width=broder((i-1)*4+3); height=broder((i-1)*4+4); rectangle('Position',[leftx,lefty,width,height], 'EdgeColor','g'); end hold off; %define [newmserboxes]=define(mserStats,mserboxes,grayImage); broder=[newmserboxes.BoundingBox]; axes(handles.axes4); imshow(colorImage); hold on; for i=1:numel(mserStats) leftx=broder((i-1)*4+1); lefty=broder((i-1)*4+2); width=broder((i-1)*4+3); height=broder((i-1)*4+4); rectangle('Position',[leftx,lefty,width,height], 'EdgeColor','g'); end hold off; % --- 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) ReadList1 = textread('cut_list.txt','%s','delimiter','\n');%载入列表 sz1=size(ReadList1); global kk; kk=1; name= char(ReadList1(kk,1)); colorImage=imread(strcat('C:\Users\Administrator\Desktop\一种基于极大值稳定区域的文本定位方法\基于MSER和SVM的文本定位方法\毕业设计\机器学习\k\',name)); grayImage = rgb2gray(colorImage);%转化成灰度图像 [mserRegions] = detectMSERFeatures(grayImage,'regionAreaRange',[70 4500],'ThresholdDelta',2.6);%提取MSER特称 % [mserRegions] = detectMSERFeatures(grayImage,'ThresholdDelta',1);%提取MSER特称 %联通区像素索引列表 pixelIdxList=cellfun(@(xy)sub2ind(size(grayImage),xy(:,2),xy(:,1)),mserRegions.PixelList,'UniformOutput',false); % 创建结构体mserConnComp存储MSER区域 mserConComp.Connectivity = 8; mserConComp.ImageSize = size(grayImage); mserConComp.NumObjects = mserRegions.Count; mserConComp.PixelIdxList = pixelIdxList; axes(handles.axes1); imshow(colorImage); %基本特征过滤 [mserStats,mserRegions] =conComp_filter(mserConComp,mserRegions,grayImage); %笔画宽度过滤 [mserRegions,mserStats]=line_filter(mserStats,mserRegions,grayImage); %转换 [mserboxes]=change(mserStats,mserConComp); %合并 [mserboxes]=re_define(mserStats,mserboxes,grayImage); broder=[mserboxes.BoundingBox]; axes(handles.axes2); imshow(colorImage); hold on; for i=1:numel(mserStats) leftx=broder((i-1)*4+1); lefty=broder((i-1)*4+2); width=broder((i-1)*4+3); height=broder((i-1)*4+4); rectangle('Position',[leftx,lefty,width,height], 'EdgeColor','g'); end hold off; %分类器 [mserboxes,mserStats]=SVM_filter(mserboxes,mserStats,grayImage); broder=[mserboxes.BoundingBox]; axes(handles.axes3); imshow(colorImage); hold on; for i=1:numel(mserStats) leftx=broder((i-1)*4+1); lefty=broder((i-1)*4+2); width=broder((i-1)*4+3); height=broder((i-1)*4+4); rectangle('Position',[leftx,lefty,width,height], 'EdgeColor','g'); end hold off; %define [newmserboxes]=define(mserStats,mserboxes,grayImage); broder=[newmserboxes.BoundingBox]; axes(handles.axes4); imshow(colorImage); hold on; for i=1:numel(mserStats) leftx=broder((i-1)*4+1); lefty=broder((i-1)*4+2); width=broder((i-1)*4+3); height=broder((i-1)*4+4); rectangle('Position',[leftx,lefty,width,height], 'EdgeColor','g'); end hold off; % --- 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) ReadList1 = textread('k_list.txt','%s','delimiter','\n');%载入列表 sz1=size(ReadList1); global kk; kk=kk+1; name= char(ReadList1(kk,1)); colorImage=imread(strcat('D:\daily\样本\机器学习\k\',name)); grayImage = rgb2gray(colorImage);%转化成灰度图像 [mserRegions] = detectMSERFeatures(grayImage,'regionAreaRange',[70 4500],'ThresholdDelta',2.6);%提取MSER特称 % [mserRegions] = detectMSERFeatures(grayImage,'ThresholdDelta',1);%提取MSER特称 %联通区像素索引列表 pixelIdxList=cellfun(@(xy)sub2ind(size(grayImage),xy(:,2),xy(:,1)),mserRegions.PixelList,'UniformOutput',false); % 创建结构体mserConnComp存储MSER区域 mserConComp.Connectivity = 8; mserConComp.ImageSize = size(grayImage); mserConComp.NumObjects = mserRegions.Count; mserConComp.PixelIdxList = pixelIdxList; axes(handles.axes1); imshow(colorImage); %基本特征过滤 [mserStats,mserRegions] =conComp_filter(mserConComp,mserRegions,grayImage); %笔画宽度过滤 [mserRegions,mserStats]=line_filter(mserStats,mserRegions,grayImage); %转换 [mserboxes]=change(mserStats,mserConComp); %合并 [mserboxes]=re_define(mserStats,mserboxes,grayImage); broder=[mserboxes.BoundingBox]; axes(handles.axes2); imshow(colorImage); hold on; for i=1:numel(mserStats) leftx=broder((i-1)*4+1); lefty=broder((i-1)*4+2); width=broder((i-1)*4+3); height=broder((i-1)*4+4); rectangle('Position',[leftx,lefty,width,height], 'EdgeColor','g'); end hold off; %分类器 [mserboxes,mserStats]=SVM_filter(mserboxes,mserStats,grayImage); broder=[mserboxes.BoundingBox]; axes(handles.axes3); imshow(colorImage); hold on; for i=1:numel(mserStats) leftx=broder((i-1)*4+1); lefty=broder((i-1)*4+2); width=broder((i-1)*4+3); height=broder((i-1)*4+4); rectangle('Position',[leftx,lefty,width,height], 'EdgeColor','g'); end hold off; %define [newmserboxes]=define(mserStats,mserboxes,grayImage); broder=[newmserboxes.BoundingBox]; axes(handles.axes4); imshow(colorImage); hold on; for i=1:numel(mserStats) leftx=broder((i-1)*4+1); lefty=broder((i-1)*4+2); width=broder((i-1)*4+3); height=broder((i-1)*4+4); rectangle('Position',[leftx,lefty,width,height], 'EdgeColor','g'); end hold off; if(kk==20) kk=0; end