字符细化算法

来源:互联网 发布:虚拟机怎么配置网络 编辑:程序博客网 时间:2024/05/21 13:48

图像细化的作用不多说,本算法通常是一个迭代算法,整个迭代过程分为两步:

Step One:循环所有前景像素点,对符合如下条件的像素点标记为删除:

1.      2 <= N(p1) <=6

2.      S(P1) = 1

3.      P2 * P4 * P6 = 0

4.      P4 * P6 * P8 = 0

Step Two:跟Step One很类似,条件1、2完全一致,只是条件3、4稍微不同,满足如下条件的像素P1则标记为删除,条件如下:

1.      2 <= N(p1) <=6

2.      S(P1) = 1

3.      P2 * P4 * P8 = 0

4.      P2 * P6 * P8 = 0

如图:


原代码如下:

/** * 字符细化算法 * @param image */private void refine(BufferedImage image){int k=1;while(k!=0){k=stepOne(image);k=stepTwo(image);}}/** * 字符细化第一步 * @param image * @return */public int stepOne(BufferedImage image){int result=0;int redRGB=Color.red.getRGB();int width=image.getWidth()-1;int height=image.getHeight()-1;int p[]=new int[9];int k[]=new int[9];int s=0;String a=null;int index1=0,index2=0,con3=0,con4=0;for(int x=1;x=2&&s<=6)&&(index1==index2)&&(con3==con4)){image.setRGB(x, y, redRGB);result++;}}for(int i=0;i0){for(int x=0;x=2&&s<=6)&&(index1==index2)&&(con3==con4)){image.setRGB(x, y, redRGB);result++;}}for(int i=0;i0){for(int x=0;x



原创粉丝点击