Skip to content

Commit a8f5167

Browse files
update
1 parent 100ce52 commit a8f5167

File tree

9 files changed

+269
-41
lines changed

9 files changed

+269
-41
lines changed

.idea/misc.xml

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/workspace.xml

Lines changed: 23 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src_code/README-Chinese.md

Lines changed: 62 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -399,10 +399,69 @@ public class MAIN1 {
399399
public static void main(String[] args) throws MalformedURLException {
400400
// 准备图像的URL对象
401401
URL url = new URL("https://user-images.githubusercontent.com/113756063/194830221-abe24fcc-484b-4769-b3b7-ec6d8138f436.png");
402-
// 解析URL获取到矩阵
403-
ColorMatrix parse = ColorMatrix.parse(url);
402+
// 解析URL获取到图像矩阵
403+
ColorMatrix parse1 = ColorMatrix.parse(url);
404+
// 解析URL获取到图像的灰度矩阵
405+
ColorMatrix parse2 = ColorMatrix.parseGrayscale(url);
404406
// 查看图像
405-
parse.show("image");
407+
parse1.show("image");
408+
parse2.show("image");
409+
}
410+
}
411+
```
412+
413+
* 支持进行色彩规整覆盖,能够通过指定通道的色彩数值,显示出更多的图像特征,或去除更多的冗余特征。
414+
415+
```java
416+
package zhao.algorithmMagic;
417+
418+
import zhao.algorithmMagic.operands.matrix.ColorMatrix;
419+
420+
import java.net.MalformedURLException;
421+
import java.net.URL;
422+
423+
public class MAIN1 {
424+
public static void main(String[] args) throws MalformedURLException {
425+
// 准备图像的URL对象
426+
URL url = new URL("https://user-images.githubusercontent.com/113756063/194830221-abe24fcc-484b-4769-b3b7-ec6d8138f436.png");
427+
// 解析URL获取到图像矩阵
428+
ColorMatrix parse1 = ColorMatrix.parse(url);
429+
// 将 URL 图像矩阵中所有 G 通道颜色数值大于 40 的颜色变更为黑色,反之变更为白色
430+
// 在这里由于选择了 G 通道 因此 绿色越深 越有可能变为白色
431+
parse1.regularity(ColorMatrix._G_, 40, 0, 0xffffff);
432+
// 也可以使用其它颜色通道进行色彩的调整
433+
parse1.regularity(ColorMatrix._R_, 40, 0, 0xffffff);
434+
parse1.regularity(ColorMatrix._B_, 40, 0, 0xffffff);
435+
// 查看结果图像
436+
parse1.show("image");
437+
}
438+
}
439+
```
440+
441+
* 支持进行图像 ASCII 图的构造,您可以快速的将一个图片的 ASCII 构造出来,不过请您确保图像尺寸足够小。
442+
443+
```java
444+
package zhao.algorithmMagic;
445+
446+
import zhao.algorithmMagic.operands.matrix.ColorMatrix;
447+
448+
import java.io.File;
449+
import java.net.MalformedURLException;
450+
import java.net.URL;
451+
452+
public class MAIN1 {
453+
public static void main(String[] args) throws MalformedURLException {
454+
// 准备图像的URL对象
455+
URL url = new URL("https://user-images.githubusercontent.com/113756063/194830221-abe24fcc-484b-4769-b3b7-ec6d8138f436.png");
456+
// 解析URL获取到图像矩阵
457+
ColorMatrix parse1 = ColorMatrix.parse(url);
458+
// 查看结果图像
459+
parse1.show("image");
460+
// 输出图像的 ASCII 数值,输出规则为 G 通道颜色数值 大于 40 的 输出符号 'A' 其它输出符号 ' '
461+
parse1.save(
462+
new File("C:\\Users\\zhao\\Desktop\\fsdownload\\res.txt"),
463+
ColorMatrix._G_, 40, 'A', ' '
464+
);
406465
}
407466
}
408467
```

src_code/README.md

Lines changed: 65 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ public class MAIN1 {
383383
}
384384
```
385385

386-
* 支持通过一个网络 URL 对象获取到有关图像的数据,并将其转换成为一个图像矩阵。
386+
* Support for obtaining image related data through a web URL object and converting it into an image matrix.
387387

388388
```java
389389
package zhao.algorithmMagic;
@@ -397,10 +397,71 @@ public class MAIN1 {
397397
public static void main(String[] args) throws MalformedURLException {
398398
// 准备图像的URL对象
399399
URL url = new URL("https://user-images.githubusercontent.com/113756063/194830221-abe24fcc-484b-4769-b3b7-ec6d8138f436.png");
400-
// 解析URL获取到矩阵
401-
ColorMatrix parse = ColorMatrix.parse(url);
400+
// 解析URL获取到图像矩阵
401+
ColorMatrix parse1 = ColorMatrix.parse(url);
402+
// 解析URL获取到图像的灰度矩阵
403+
ColorMatrix parse2 = ColorMatrix.parseGrayscale(url);
402404
// 查看图像
403-
parse.show("image");
405+
parse1.show("image");
406+
parse2.show("image");
407+
}
408+
}
409+
```
410+
411+
*Support for color normalization coverage, which can display more image features or remove more redundant features by
412+
specifying the color values of the channel.
413+
414+
```java
415+
package zhao.algorithmMagic;
416+
417+
import zhao.algorithmMagic.operands.matrix.ColorMatrix;
418+
419+
import java.net.MalformedURLException;
420+
import java.net.URL;
421+
422+
public class MAIN1 {
423+
public static void main(String[] args) throws MalformedURLException {
424+
// 准备图像的URL对象
425+
URL url = new URL("https://user-images.githubusercontent.com/113756063/194830221-abe24fcc-484b-4769-b3b7-ec6d8138f436.png");
426+
// 解析URL获取到图像矩阵
427+
ColorMatrix parse1 = ColorMatrix.parse(url);
428+
// 将 URL 图像矩阵中所有 G 通道颜色数值大于 40 的颜色变更为黑色,反之变更为白色
429+
// 在这里由于选择了 G 通道 因此 绿色越深 越有可能变为白色
430+
parse1.regularity(ColorMatrix._G_, 40, 0, 0xffffff);
431+
// 也可以使用其它颜色通道进行色彩的调整
432+
parse1.regularity(ColorMatrix._R_, 40, 0, 0xffffff);
433+
parse1.regularity(ColorMatrix._B_, 40, 0, 0xffffff);
434+
// 查看结果图像
435+
parse1.show("image");
436+
}
437+
}
438+
```
439+
440+
* Supports the construction of image ASCII images. You can quickly construct an image in ASCII, but please ensure that
441+
the image size is small enough.
442+
443+
```java
444+
package zhao.algorithmMagic;
445+
446+
import zhao.algorithmMagic.operands.matrix.ColorMatrix;
447+
448+
import java.io.File;
449+
import java.net.MalformedURLException;
450+
import java.net.URL;
451+
452+
public class MAIN1 {
453+
public static void main(String[] args) throws MalformedURLException {
454+
// 准备图像的URL对象
455+
URL url = new URL("https://user-images.githubusercontent.com/113756063/194830221-abe24fcc-484b-4769-b3b7-ec6d8138f436.png");
456+
// 解析URL获取到图像矩阵
457+
ColorMatrix parse1 = ColorMatrix.parse(url);
458+
// 查看结果图像
459+
parse1.show("image");
460+
// 输出图像的 ASCII 数值,输出规则为 G 通道颜色数值 大于 40 的 输出符号 'A' 其它输出符号 ' '
461+
parse1.save(
462+
new File("C:\\Users\\zhao\\Desktop\\fsdownload\\res.txt"),
463+
ColorMatrix._G_, 40, 'A', ' '
464+
);
404465
}
405466
}
406467
```

src_code/src/main/java/zhao/algorithmMagic/MAIN1.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,17 @@
22

33
import zhao.algorithmMagic.operands.matrix.ColorMatrix;
44

5+
import java.io.File;
56
import java.net.MalformedURLException;
6-
import java.net.URL;
77

88
public class MAIN1 {
99
public static void main(String[] args) throws MalformedURLException {
10-
// 准备图像的URL对象
11-
URL url = new URL("https://user-images.githubusercontent.com/113756063/194830221-abe24fcc-484b-4769-b3b7-ec6d8138f436.png");
12-
// 解析URL获取到矩阵
13-
ColorMatrix parse = ColorMatrix.parse(url);
14-
// 查看图像
15-
parse.show("image");
10+
// 解析URL获取到图像矩阵
11+
ColorMatrix parse1 = ColorMatrix.parse("C:\\Users\\zhao\\Desktop\\fsdownload\\test.bmp");
12+
// 输出图像的 ASCII 数值,输出规则为 G 通道颜色数值 大于 40 的 输出符号 'A' 其它输出符号 ' '
13+
parse1.save(
14+
new File("C:\\Users\\zhao\\Desktop\\fsdownload\\res.txt"),
15+
ColorMatrix._G_, 220, ' ', '-'
16+
);
1617
}
1718
}

src_code/src/main/java/zhao/algorithmMagic/operands/matrix/ColorMatrix.java

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,24 @@
2424
*/
2525
public class ColorMatrix extends Matrix<ColorMatrix, Color, Color[], Color[], Color[][]> implements SaveMatrix {
2626

27+
/**
28+
* 红色通道编码,用于定位颜色通道的数值常量
29+
*/
30+
public final static byte _R_ = 16;
31+
32+
/**
33+
* 绿色通道编码,用于定位颜色通道的数值常量
34+
*/
35+
public final static byte _G_ = 8;
36+
37+
/**
38+
* 蓝色通道编码,用于定位颜色通道的数值常量
39+
*/
40+
public final static byte _B_ = 0;
41+
42+
/**
43+
* 白色RGB常量数值
44+
*/
2745
public final static int WHITE_NUM = 0xffffff;
2846
public final static short SINGLE_CHANNEL_MAXIMUM = 0xff;
2947
private boolean isGrayscale;
@@ -950,6 +968,38 @@ public void merge(ColorMatrix colorMatrix, int x1, int y1) {
950968
}
951969
}
952970

971+
/**
972+
* 将图像矩阵中的指定通道的色彩数值进行规整计算,能够显著提升图像的某些特征,同时可以有效去除图像的无用特征。
973+
* <p>
974+
* Regularizing the color values of the specified channels in the image matrix can significantly improve some features of the image, while effectively removing unwanted features from the image.
975+
*
976+
* @param Mode 在进行通道色彩的获取的时候,需要指定规整时的颜色通道标准,在指定通道的基础上进行规整,该参数可以直接从 ColorMatrix 类中获取到。
977+
* <p>
978+
* When obtaining channel colors, it is necessary to specify the color channel standard for regularization, which is based on the specified channel. This parameter can be directly obtained from the ColorMatrix class.
979+
* @param colorBoundary 颜色边界阈值,当被判断的颜色数值达到了阈值,则判断当前坐标颜色为真,返回为假。
980+
* <p>
981+
* The color boundary threshold value. When the judged color value reaches the threshold value, the current coordinate color is judged to be true, and the return value is false.
982+
* @param trueColor 图像中所有颜色为真的坐标,需要变更为的新颜色对象。
983+
* <p>
984+
* Coordinates where all colors in the image are true and need to be changed to a new color object for.
985+
* @param falseColor 图像中所有颜色为假的坐标,需要变更为的新颜色对象。
986+
* <p>
987+
* All colors in the image are fake coordinates and need to be changed to a new color object for.
988+
*/
989+
public void regularity(byte Mode, int colorBoundary, int trueColor, int falseColor) {
990+
if (colorBoundary < 0 || colorBoundary > 0xff) return;
991+
Color color1 = new Color(trueColor);
992+
Color color2 = new Color(falseColor);
993+
for (Color[] colors : this.toArrays()) {
994+
int index = -1;
995+
for (Color color : colors) {
996+
if (((color.getRGB() >> Mode) & 0xFF) > colorBoundary) {
997+
colors[++index] = color1;
998+
} else colors[++index] = color2;
999+
}
1000+
}
1001+
}
1002+
9531003
/**
9541004
* 将图像矩阵展示出来,使得在矩阵的图像数据能够被展示出来。
9551005
* <p>
@@ -1025,6 +1075,42 @@ public void save(File path, char sep) {
10251075
});
10261076
}
10271077

1078+
/**
1079+
* 将图像的 ASCII 图像输出到指定的目录中。
1080+
*
1081+
* @param path 需要保存的目录路径。
1082+
* <p>
1083+
* Directory path to save.
1084+
* @param Mode 在进行通道色彩的获取的时候,需要指定规整时的颜色通道标准,在指定通道的基础上进行规整,该参数可以直接从 ColorMatrix 类中获取到。
1085+
* <p>
1086+
* When obtaining channel colors, it is necessary to specify the color channel standard for regularization, which is based on the specified channel. This parameter can be directly obtained from the ColorMatrix class.
1087+
* @param colorBoundary 颜色边界阈值,当被判断的颜色数值达到了阈值,则判断当前坐标颜色为真,返回为假。
1088+
* <p>
1089+
* The color boundary threshold value. When the judged color value reaches the threshold value, the current coordinate color is judged to be true, and the return value is false.
1090+
* @param imageAscii1 ASCII 符号 在输出的 ASCII 图像文件中,针对大于阈值的坐标,图像的构成字符对应的ASCII数值。
1091+
* <p>
1092+
* ASCII Symbol In the output ASCII image file, the ASCII value corresponding to the constituent characters of the image for coordinates greater than the threshold value.
1093+
* @param imageAscii2 ASCII 符号 在输出的 ASCII 图像文件中,针对小于阈值的坐标,图像的构成字符对应的ASCII数值。
1094+
* <p>
1095+
* ASCII Symbol In the output ASCII image file, the ASCII value corresponding to the constituent characters of the image for coordinates that are less than the threshold value.
1096+
*/
1097+
public void save(File path, byte Mode, int colorBoundary, char imageAscii1, char imageAscii2) {
1098+
ASIO.writer(path, bufferedWriter -> {
1099+
try {
1100+
for (Color[] colors : this.toArrays()) {
1101+
for (Color color : colors) {
1102+
if (((color.getRGB() >> Mode) & 0xFF) > colorBoundary) {
1103+
bufferedWriter.write(imageAscii1);
1104+
} else bufferedWriter.write(imageAscii2);
1105+
}
1106+
bufferedWriter.newLine();
1107+
}
1108+
} catch (IOException e) {
1109+
throw new OperatorOperationException("Write data exception!", e);
1110+
}
1111+
});
1112+
}
1113+
10281114
/**
10291115
* 将图像矩阵展示出来,使得在矩阵的图像数据能够被展示出来。
10301116
* <p>

src_code/src/main/java/zhao/algorithmMagic/operands/vector/SparkVector.scala

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,6 @@ final class SparkVector(sparkContext: SparkContext, vector: org.apache.spark.mll
5151
else throw new OperatorOperationException("'DoubleVector1 multiply DoubleVector2' 时,两个'DoubleVector'的向量所包含的数量不同,DoubleVector1=[" + length1 + "],DoubleVector2=[" + length2 + "]\n" + "When 'DoubleVector1 multiply DoubleVector2', the two vectors of 'DoubleVector' contain different quantities, DoubleVector1=[" + length1 + "], DoubleVector2=[" + length2 + "]")
5252
}
5353

54-
/**
55-
*
56-
* @return 将本对象中存储的向量序列数组拷贝到一个新数组并将新数组返回,这里返回的是一个新数组,支持修改等操作。
57-
*
58-
* Copy the vector sequence array stored in this object to a new array and return the new array. Here, a new array is returned, which supports modification and other operations.
59-
*/
60-
override def copyToNewArray(): Array[Double] = vector.toArray
61-
6254
/**
6355
* 计算两个向量的内积,也称之为数量积,具体实现请参阅api说明
6456
* <p>
@@ -113,6 +105,21 @@ final class SparkVector(sparkContext: SparkContext, vector: org.apache.spark.mll
113105
else throw new OperatorOperationException("'DoubleVector1 add DoubleVector2' 时,两个'DoubleVector'的向量所包含的数量不同,DoubleVector1=[" + numberOfDimensions1 + "],DoubleVector2=[" + numberOfDimensions2 + "]\n" + "When 'DoubleVector1 add DoubleVector2', the two vectors of 'DoubleVector' contain different quantities, DoubleVector1=[" + numberOfDimensions1 + "], DoubleVector2=[" + numberOfDimensions2 + "]")
114106
}
115107

108+
/**
109+
*
110+
* @return 将本对象中存储的向量序列数组拷贝到一个新数组并将新数组返回,这里返回的是一个新数组,支持修改等操作。
111+
*
112+
* Copy the vector sequence array stored in this object to a new array and return the new array. Here, a new array is returned, which supports modification and other operations.
113+
*/
114+
override def copyToNewArray(): Array[Double] = vector.toArray
115+
116+
/**
117+
* @return 向量中包含的维度数量
118+
* <p>
119+
* the number of dimensions contained in the vector
120+
*/
121+
override def getNumberOfDimensions: Int = size
122+
116123
/**
117124
* 在两个操作数之间做差的方法,具体用法请参阅API说明。
118125
* <p>
@@ -137,13 +144,6 @@ final class SparkVector(sparkContext: SparkContext, vector: org.apache.spark.mll
137144
else throw new OperatorOperationException("'DoubleVector1 diff DoubleVector2' 时,两个'DoubleVector'的向量所包含的数量不同,DoubleVector1=[" + numberOfDimensions1 + "],DoubleVector2=[" + numberOfDimensions2 + "]\n" + "When 'DoubleVector1 diff DoubleVector2', the two vectors of 'DoubleVector' contain different quantities, DoubleVector1=[" + numberOfDimensions1 + "], DoubleVector2=[" + numberOfDimensions2 + "]")
138145
}
139146

140-
/**
141-
* @return 向量中包含的维度数量
142-
* <p>
143-
* the number of dimensions contained in the vector
144-
*/
145-
override def getNumberOfDimensions: Int = size
146-
147147
/**
148148
*
149149
* @return 第三方向量中所维护的向量序列,通过此函数您可以直接获取到第三方库中的对象。

src_code/src/main/java/zhao/algorithmMagic/utils/ASIO.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ public static Color[][] parseImageGetColorArray(String inputString) {
135135
return parseImageGetColorArray(new File(inputString));
136136
} catch (IOException e) {
137137
throw new OperatorOperationException("尝试获取您所给定路径图像的像素矩阵时发生了错误\nAn error occurred while trying to get the pixel matrix of the path image you gave\nERROR => " +
138-
inputString
138+
inputString, e
139139
);
140140
}
141141
}

src_code/src/main/java/zhao/algorithmMagic/utils/Mapper.java

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)