转自:http://apps.hi.baidu.com/share/detail/33054648
function character_segmentation
% character_segmentation: Returns the digit segments in the supplied binary image.
% The function uses the "segment" function, keeping only the seven
% segments in the result with largest area, and in case less than seven
% segments were found, it attempts to recall the function, making the
% separation between the already found segments clearer (by cleaning the
% bits which are there.
bw = imread('a.jpg');
DIGIT_WIDTH = 80;
MIN_AREA = 100;
load global_var.mat;
seg = segment(bw, DIGIT_WIDTH, MIN_AREA);
[x y] = size(seg);
% If we got less than 7 digits, we try to make the sepration between them
% clearer by cleaning the bits between them, and we call the "segment"
% function again:
if x < 2
for i = 1 : x
bw(:,seg(i,2))=0;
end;
seg = segment(bw, DIGIT_WIDTH, MIN_AREA);
end;
% Keeping in the results the seven segments with the largest area:
area = [];
for i = 1 : x
pic = bw(:, seg(i,1) : seg(i,2), :);
area(i) = bwarea(pic);
end;
area1 = sort(area);
seg = seg;
for j = 1:(length(area1)-2)
i = find(area == area1(j));
len = length(area);
if i == 1
area = [area(2:len)];
seg = [seg(:,2:len)];
elseif i == len
area = [area(1:i-1)];
seg = [seg(:,1:i-1)];
else
area = [area(1:i-1) area(i+1:len)];
seg = [seg(:,1:i-1) seg(:,i+1:len)];
end;
end;
seg = seg;
return;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [segmentation] = segment(im, digit_width, min_area);
% segment: Segment the pictures in digit images according to the variable
% "digit_width" and returns a matrix containing the two bounds of the each
% digit segment. The function keeps in the result only segment whose
% "rectangular" areas is more than "min_area".
segmentation = [];
% Summing the colums of the pic:
t = sum(im);
% Getting the segments in the pic:
seg = clean(find_valleys(t, 2, 1, digit_width), 3);
% Keeping in the result only the segments whose rectangular areas is more than min_area:
j = 1;
for i = 1 : (length(seg) - 1)
band_width = seg(i+1) - seg(i);
maxi = max(t(1, seg(i):seg(i+1)));
if(maxi * band_width > min_area)
segmentation(j, 1) = seg(i);
segmentation(j, 2) = seg(i+1);
j = j + 1;
end;
end;
return;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [s] = find_valleys(t, val, offset, digit_width);
% find_valleys: Uses the method named peak-to-valleyin order to segment the
% pictures in digit images getting the two bounds of the each digit segment
% according to the statistical parameter digit_width = 18.
% The function is recursive; it uses the vector of the sums of the columns
% in the LP binary image supplied in the parameter "t".
% The function passes over the graph corresponding to this vector from left
% to right, bottom-up, incrementing at each recursive step the height that
% is examined on the graph (val). It checks the bandwidth of the first part
% of the signal: if it is greater than DIGIT_WIDTH, the function is
% recursively called after incrementing the height which is examined on
% the graph, (val). Otherwise, if the bandwidth is good, the two bounds of
% the signal with this bandwidth are taken as a digit segment, and the
% function is recursively called for the part of the image which is at
% the right side of the digit segment just found. This is done until the
% whole width of the picture has been passed over.
% Determining the points which are inferior to the examined hieght:
s = find(t < val);
% If no more than one point is found, incrementing val and recursively calling the function again.
if(length(s) < 2)
s = find_valleys(t, val + 1, offset, digit_width);
return;
end;
% If no point is found terminating:
if length(s) == 0
return;
end;
% Arranging the boundaries, so that if we have a big value at the beginning
% or the end of the picture the algorithm still works: in this case, the
% algorithm includes also those points.
if((t(1,1) >= val) & s(1) ~= 1)
s = [1 s];
end;
if((t(1, length(t)) >= val) & s(length(s)) ~= length(t))
s = [s length(t)];
end;
% Updating the real coordinates according to offset:
s = add(s, offset - 1);
% Cleaning points which are very close each other keeping only one of them.
s = clean(s, 3);
% While there is a bad segment in "s", (starting from the left side):
while bad_segm(s, digit_width) == 1
for i = 1: (length(s) - 1)
if (s(i + 1) - s(i)) > digit_width
% The subvector which does not correspond to a valid digit
% segemnt:
sub_vec = t(1, s(i) - offset + 1 : s(i+1) - offset + 1);
% Recursively, separating this bad segment in two or more valid
% digit segments:
s = [s(1 : i) find_valleys(sub_vec, val + 1, s(i), digit_width) s(i+1 : length(s))];
end;
end;
end;
return;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [bool] = bad_segm(s, digit_width);
% bad_segm: Returns true (1) iff there is a bad digit segment in s, namely,
% two points that ar distant one from the other by more than "digit_width".
if length(s) == 0
bool = 0;
return;
end;
tmp = s(1);
bool = 0;
for i = 2 : length(s)
if(s(i) - tmp) > digit_width
bool = 1;
return;
end;
tmp = s(i);
end;
return;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [t] = clean(s, val);
% clean: Cleans form the vector s all the poins which are distant the one
% from the other by less than "val" keeping only one of them.
t = [];
len = length(s);
i = 2;
j = 1;
while i <= len
while(s(i) - s(i-1) <= val)
i = i + 1;
if(i > len)
return;
end;
end;
if j == 1 | (s(i-1) - t(j-1)) > val
t(j) = s(i-1);
j = j + 1;
end;
t(j) = s(i);
j = j + 1;
i = i + 1;
end;
return;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [t] = add(s, val);
% add: Adds "val" to each one of the entries in the vector s and returns the new vector.
len = length(s);
t = [];
for i = 1:len
t(i) = s(i) + val;
end;
return;
分享到:
相关推荐
适合matlab初学者,程序完整功能齐全,含字符模板,大作业,毕设可参考,欢迎下载
发现一个Matlab字符分割的程序发上来给大家分享一下-fenge.rar 这是一个简单的字符分割的程序,将一个图中的字符,分成单个字符,需要的朋友们下着用吧 所含文件: Figure8.jpg
车牌字符分割算法的垂直投影切分matlab程序
运行于MATLAB的车牌字符分割程序。字符分割有承前启后的作用。它在前期牌照定位的基础上进行字符的分割,然后再利用分割的结果进行字符识别。
2、利用垂直投影法进行单行中文光学字符的分割,多行中文光学字符分割; 3、利用连通域法进行单行中文光学字符的分割,多行中文光学字符分割; 4、对比两种方法的优缺点,并且针对缺陷改进算法。 注意,对于拍照存在...
matlab车牌字符分割代码 MATLAB2020 MATLAB 个人文件 2020年太原工业学院老郭的毕业设计 采用BP神经算法进行识别,对车牌的提取,处理,字符分割是其他方法! 如果有大佬可以用MATLAB来进行车牌的定位,欢迎留言 ...
字符识别MATLAB程序-work.rar 运行结果: Figure32.jpg 包括字符分割、特征提取、字符识别部分,有很好的参考价值 Figure33.jpg 包括字符分割、特征提取、...
很实用的MATLAB字符分割源程序代码,有助于字符的识别,使汽车识别系统更简便易行!
适合matlab初学者,程序完整功能齐全,含字符模板,大作业,毕设可参考,欢迎下载
车牌识别的车牌字符分割提取matlab程序,为进一步的字符匹配与识别提供基础。
汽车牌照识别的MATLAB程序,车牌定位,字符分割,字符识别,结果输出
图像分割算法的Matlab源程序matlab.zip 图像压缩.rar 图像处理.rar 图像处理源程序.rar 图像复原matlab程序.rar 图像形态学处理.rar 图像融合+源代码+matlab.rar 图像融合程序代码.rar 图像识别.rar 图像配准算法....
基于matlab开发的车牌检测与字符分割项目完整源码+项目说明+课设报告(数字图像处理课设).zip 【项目实现功能】 车牌定位:输入车辆图片后,输出mask图以及定位到的车牌图片; 字符分割:根据获得的车牌图片进行字符...
一个自己编的车牌中字母的分割程序。matlab语言写的。可以将车牌中的字母分割出来。但需要手动提取车牌。 具体做法是,在弹出的选择匹配点的框中,分别在左图车牌的左上、右上、左下、右下选择车牌的四个点。并且每...
3.内容:基于matlab的车牌提取和字符分割识别仿真。包括图像形态学处理,图像二值化,水平投影,垂直投影,字符模板匹配等 4.注意事项:注意MATLAB左侧当前文件夹路径,必须是程序所在文件夹位置,具体可以参考视频...
图像分割算法的Matlab源程序matlab.zip 图像压缩.rar 图像处理.rar 图像处理源程序.rar 图像复原matlab程序.rar 图像形态学处理.rar 图像融合+源代码+matlab.rar 图像融合程序代码.rar 图像识别.rar 图像配准算法....
matlab图像分割 程序代码说明 P0801:索书号文字图像分割 P0802:粘连字符切分 P0803:文字识别 P0804:彩色车牌分割 P0805:商标文字分割 Recognition:文字识别的识别子函数 StrDetect01:文字识别的结构...
几段matlab的代码,主要是用在车牌识别的,大家需要的话就下载下来
基于matlab的车牌识别的源程序(可以实现),其中包括车牌定位,车牌矫正,字符分割,字符识别4部分。还有已训练好的BP神经网络用于字符识别。