Java实现离散Arnold变换(图像处理)

原始124×124pix

原图1次2次3次

15次

周期表:

N

2

3

4

5

6

7

8

9

10

11

12

周期

3

4

3

10

12

8

6

12

30

5

12

N

13

14

15

16

17

18

19

20

21

22

23

周期

14

24

20

12

18

12

9

30

8

15

24

N

25

50

60

100

120

125

128

256

480

512

1024

周期

50

150

60

150

60

250

96

192

120

384

768

 


package com.zeph.j2se.arnold;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

/**
 * Arnold's Cat Map(Arnold变换)
 * 
 * @author BenZeph
 * 
 */
public class Arnold {
	private File srcImageFile, desImageFile;
	private BufferedImage srcImage, desImage;
	private int[][] srcMatrix, desMatrix;
	private int N;// 图像的长度(宽度)
	private int time;// 周期

	/**
	 * Arnold's Cat Map(Arnold变换)
	 * 
	 * @param srcImageFile
	 * @param desImageFile
	 * @param time
	 *            周期
	 */
	public Arnold(File srcImageFile, File desImageFile, int time) {
		this.srcImageFile = srcImageFile;
		this.desImageFile = desImageFile;
		this.time = time;
	}

	/**
	 * 读取图像
	 * 
	 * @param imageFile
	 * @return
	 */
	public BufferedImage readImage(File imageFile) {
		BufferedImage image = null;
		try {
			image = ImageIO.read(imageFile);
		} catch (IOException e) {
			e.printStackTrace();
		}
		return image;
	}

	/**
	 * 获取图像RGB矩阵
	 * 
	 * @param image
	 * @return
	 */
	public int[][] getMatrixRGB(BufferedImage image) {
		int width = image.getWidth();
		int height = image.getHeight();
		int[][] imageMatrix = new int[height][width];
		for (int i = 0; i < height; i++) {
			for (int j = 0; j < width; j++) {
				imageMatrix[i][j] = image.getRGB(i, j);
			}
		}
		return imageMatrix;
	}

	/**
	 * 写入图像
	 * 
	 * @param filePath
	 */
	public void writeImage(File imageFile, BufferedImage image) {
		try {
			ImageIO.write(image, "jpg", imageFile);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * Arnold变换初始化
	 * 
	 * @param image
	 * @return
	 */
	public boolean initArnold(BufferedImage image) {
		int width = image.getWidth();
		int height = image.getHeight();
		if (width != height) {
			return false;
		} else {
			N = width;
			srcMatrix = getMatrixRGB(image);
			desMatrix = new int[N][N];
			desImage = new BufferedImage(width, height, srcImage.getType());
			return true;
		}
	}

	/**
	 * Arnold变换
	 */
	public void arnoldTransform() {
		srcImage = readImage(srcImageFile);
		if (initArnold(srcImage)) {
			for (int n = 0; n < time; n++) {
				if (n != 0) {
					srcMatrix = desMatrix;
					desMatrix = new int[N][N];
				}
				for (int i = 0; i < N; i++) {
					for (int j = 0; j < N; j++) {
						desMatrix[(i + j) % N][(i + 2 * j) % N] = srcMatrix[i][j];
					}
				}
			}
			for (int i = 0; i < N; i++) {
				for (int j = 0; j < N; j++) {
					desImage.setRGB(i, j, desMatrix[i][j]);
				}
			}
		}
		writeImage(desImageFile, desImage);
	}

	public static void main(String[] args) {
		File srcImageFile = new File("D://lena124.jpg");
		File desImageFile = new File("D://15.jpg");
		Arnold arnold = new Arnold(srcImageFile, desImageFile, 15);
		arnold.arnoldTransform();
	}
}




  • 4
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值