matlab的文字分割,matlab字符分割方法

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

以下是我编的,您给看一下,往下我就不会了。。。。。希望您能帮帮我

clear all

close all

i=imread('C:\Users\lenovo\Desktop\验证码.bmp')

j=rgb2gray(i)

figure(1),imshow(i),title('原始彩色图像')

figure,imshow(j),title('灰度化后图像')

level=graythresh(j)bw=im2bw(j,level)

figure,imshow(bw),title('二值化后图像')

y=medfilt2(bw,[3,3])figure,imshow(y),title('去除噪点后图像')

[m,n]=size(bw)

z=double(bw)

x1=zeros(1,n)

for h=1:n

for k=1:m

if(z(k,h)==0)

x1(1,h)=x1(1,h)+1

end end

end

figure, plot(0:n-1,x1)

x2 = x1;

x1(x1<=1)=0;

x1(x1>1) = 20;

figure, plot(0:n-1,x1)

nTotalUp = 0;

nTotalBottom = 0;

for i=1:n-1

if (x1(i) == 0 && x1(i+1) == 20)

nTotalUp = nTotalUp + 1;

PosUp(nTotalUp) = i+1;

end

if (x1(i) == 20 && x1(i+1) == 0)

nTotalBottom = nTotalBottom + 1;

PosBottom(nTotalBottom) = i;

end

end

%合并小区域

if (nTotalUp > 5)

for i = 1:nTotalUp

PosWidth(i) = PosBottom(i) - PosUp(i);

end

for i = 1:nTotalUp-1

PosDis(i) = PosUp(i+1) - PosBottom(i);

end

[PosSort, posn] = sort(PosWidth);

end

bw(1:m, PosUp(i)) = 0;

bw(1:m, PosBottom(i)) = 0;

figure, imshow(bw);px0=1px1=1

你可能感兴趣的:(matlab的文字分割)