《ZHANG快速并行细化算法JAVA实现》由会员分享,可在线阅读,更多相关《ZHANG快速并行细化算法JAVA实现(6页珍藏版)》请在金锄头文库上搜索。
1、import java awt image BufferedImage import java io BufferedWriter import java io File import java io FileWriter import java io IOException import javax imageio ImageIO import javax swing ImageIcon import javax swing JFrame import javax swing JLabel import javax swing JPanel import javax swing SwingC
2、onstants public class Image int pixel 像素 File fin new File E img before png BufferedImage bi File fout new File E img after png int width int height int minx int miny void init throws IOException bi ImageIO read fin width bi getWidth height bi getHeight minx bi getMinX miny bi getMinY System out pri
3、ntln width width height height System out println minx minx miniy miny pixel new int width height for int i minx i width i for int j miny j height j pixel i j bi getRGB i j 1 1 0 1 为白色 void ZhangThinning throws IOException init int neighbor new int 8 8 领域 int markNum 0 int mark new int width height
4、boolean loop true while loop loop false markNum 0 for int y miny 1 y 1 height y for int x minx 1 x 1 width x if pixel x y 0 continue neighbor 0 pixel x 1 y neighbor 1 pixel x 1 y 1 neighbor 2 pixel x y 1 neighbor 3 pixel x 1 y 1 neighbor 4 pixel x 1 y neighbor 5 pixel x 1 y 1 neighbor 6 pixel x y 1
5、neighbor 7 pixel x 1 y 1 条件 2 2 N p 6 int np neighbor 0 neighbor 1 neighbor 2 neighbor 3 neighbor 4 neighbor 5 neighbor 6 neighbor 7 if np 6 continue 条件 3 S p 1 int sp 0 for int i 1 i 0 for int y miny y 1 height y for int x minx x 1 width x 删除标记点 if mark x y 1 pixel x y 0 mark x y 0 bi setRGB x y 0
6、markNum 0 for int y miny 1 y 1 height y for int x minx 1 x 1 width x if pixel x y 0 continue neighbor 0 pixel x 1 y neighbor 1 pixel x 1 y 1 neighbor 2 pixel x y 1 neighbor 3 pixel x 1 y 1 neighbor 4 pixel x 1 y neighbor 5 pixel x 1 y 1 neighbor 6 pixel x y 1 neighbor 7 pixel x 1 y 1 条件 2 2 N p 6 in
7、t np neighbor 0 neighbor 1 neighbor 2 neighbor 3 neighbor 4 neighbor 5 neighbor 6 neighbor 7 if np 6 continue 条件 3 S p 1 int sp 0 for int i 1 i 0 for int y miny y height y for int x minx x width x 删除标记点 if mark x y 1 pixel x y 0 bi setRGB x y 0 ImageIO write bi png fout void show JFrame frame new JF
8、rame 细化 JPanel panel new JPanel ImageIcon img1 new ImageIcon E img before png JLabel label1 new JLabel 细化前 img1 SwingConstants LEFT panel add label1 ImageIcon img2 new ImageIcon E img after png JLabel label2 new JLabel 细化后 img2 SwingConstants LEFT panel add label2 frame setSize 700 700 frame add panel frame setVisible true param args throws IOException public static void main String args throws IOException TODO Auto generated method stub Image temp new Image temp ZhangThinning temp show