资源预览内容
第1页 / 共6页
第2页 / 共6页
第3页 / 共6页
第4页 / 共6页
第5页 / 共6页
第6页 / 共6页
亲,该文档总共6页全部预览完了,如果喜欢就下载吧!
资源描述
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 SwingConstants 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 println 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 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 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 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 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 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 JFrame 细化 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
收藏 下载该资源
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号