离散图 java,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;// 圖像的長(zhǎng)度(寬度)
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;
}
/**
* 寫(xiě)入圖像
*
* @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();
}
}
總結(jié)
以上是生活随笔為你收集整理的离散图 java,Java实现离散Arnold变换(图像处理)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 有没有尉氏县到周口的大巴车,一个人大概多
- 下一篇: 论汽车改装的主要项目及规范1000字左右