⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 train.m

📁 这是用matlab编写的有关图像识别分类方法的源代码
💻 M
字号:
     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   %%                                                            %% %%       Prof. Sclaroff's CS585 Image avd Video Processing       %%%%                         Project  ONE                            %%%%           C H A R A C T E R   R E C O G N I T I O N             %%%%                                                                 %%%%                    by Stanislav Rost                    %% %%                       ID:  31764117                           %%  %%                                                             %%   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% TRAIN.M%% The training program of the letter recognition project.  Loads the% training data, the shows the user each letter and asks the user what% the letter is.  Then it calculates parameters (momnets, compactness, % top-to-bottom area ratio) for each letter.  In the end, the parameters% for all instances of each vowel are used to calculate the mean vector% and the covariance matrix.trainData = im2bw(imread('training.tif','tif'),0.5);trainData = ~trainData;figure;imshow(trainData);colormap(gray);% Label lettersfigure;trainData = bwlabel(trainData, 4);imagesc(trainData);% Extract lettersletters = imfeature(trainData,'Image', ...		'Area', 'BoundingBox');numLetters = max(trainData(:));numAs = 0;numOs = 0;numUs = 0;numEs = 0;fhandle = figure;disp('Enter - for non-letters and non-inportant letters');for i = 1:numLetters,	imshow(letters(i).Image);	letterName = ...		input('Which letter is this ?','s');	if ~strcmp(letterName, '-')		curMoments = invmoments(letters(i).Image);		perImg = bwperim(letters(i).Image);		perArea = bwarea(perImg);		compactness = perArea^2/letters(i).Area;		% Do ratios of top to bottom		midpoint = floor(letters(i).BoundingBox(4) /2);		topPart = letters(i).Image(1:midpoint,:);		bottomPart = letters(i).Image((midpoint+1):end,:);				partRatio = bwarea(topPart)/bwarea(bottomPart);		% Add the vector to arrays of info for each vowel		if strcmp(letterName, 'a')			numAs = numAs + 1;			ainfo(numAs,:) = [ curMoments(1) curMoments(2) curMoments(3) compactness partRatio  ];		elseif strcmp(letterName, 'o')			numOs = numOs + 1;			oinfo(numOs,:) = [ curMoments(1) curMoments(2) curMoments(3) compactness partRatio ];		elseif strcmp(letterName, 'u')			numUs = numUs + 1;			uinfo(numUs,:) = [ curMoments(1) curMoments(2) curMoments(3) compactness partRatio ];			elseif strcmp(letterName, 'e')			numEs = numEs + 1;			einfo(numEs,:) = [ curMoments(1) curMoments(2) curMoments(3) compactness partRatio ];		end	endendclose(fhandle);meanA = mean(ainfo, 1)meanU = mean(uinfo, 1)meanE = mean(einfo, 1)meanO = mean(oinfo, 1)covA = cov(ainfo)covU = cov(uinfo)covE = cov(einfo)covO = cov(oinfo)% Write out information for letter Asave 'a.mat' meanA covA% Write out information for letter Osave 'o.mat' meanO covO% Write out information for letter Esave 'e.mat' meanE covE% Write out information for letter Usave 'u.mat' meanU covU

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -