Skip to content

Commit f4439f1

Browse files
committed
图片处理知识讲解
1 parent a4f7d5c commit f4439f1

File tree

10 files changed

+92
-0
lines changed

10 files changed

+92
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
.idea
22
*.iml
3+
.DS_Store

Colors/index.html

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Title</title>
6+
</head>
7+
<body style="background-color: blue;">
8+
<div style="background-color: rgba(255,0,0,0.7);width: 100px;height: 100px;"></div>
9+
</body>
10+
</html>

LoadPhoto/app.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
(function () {
2+
3+
let img = new Image();
4+
img.onload = e => {
5+
document.body.appendChild(img);
6+
};
7+
img.src = "dog.jpg";
8+
9+
})();

LoadPhoto/dog.jpg

7.78 KB
Loading

LoadPhoto/index.html

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Title</title>
6+
</head>
7+
<body>
8+
<!--<img src="dog.jpg">-->
9+
10+
<script src="app.js"></script>
11+
</body>
12+
</html>

PhotoData/app.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
(function () {
2+
3+
let canvas = document.querySelector("canvas");
4+
5+
function loadImage(src) {
6+
return new Promise((resolve, reject) => {
7+
let img = new Image();
8+
img.onload = () => {
9+
resolve(img);
10+
};
11+
img.onerror = reject;
12+
img.src = src;
13+
});
14+
}
15+
16+
async function main() {
17+
let img = await loadImage("dog.jpg");
18+
19+
//draw image
20+
/**
21+
* @type {CanvasRenderingContext2D | null}
22+
*/
23+
let context2d = canvas.getContext("2d");
24+
context2d.drawImage(img, 0, 0);
25+
26+
let imageData = context2d.getImageData(0, 0, 200, 200);
27+
// console.log(imageData.data.length);
28+
console.log(imageData.data);
29+
30+
let rImageData = context2d.createImageData(200, 200);
31+
for (let i = 0; i < imageData.data.length; i += 4) {
32+
let r = imageData.data[i];
33+
let g = imageData.data[i + 1];
34+
let b = imageData.data[i + 2];
35+
let value = Math.round((r + g + b) / 3);
36+
rImageData.data[i] = value;
37+
rImageData.data[i + 1] = value;
38+
rImageData.data[i + 2] = value;
39+
rImageData.data[i + 3] = 255;
40+
}
41+
42+
context2d.putImageData(rImageData, 200, 0);
43+
}
44+
45+
main();
46+
})();

PhotoData/dog.jpg

7.78 KB
Loading

PhotoData/index.html

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Title</title>
6+
</head>
7+
<body>
8+
9+
<canvas width="400" height="400" style="border-style: solid;"></canvas>
10+
11+
12+
<script src="app.js"></script>
13+
</body>
14+
</html>

机器学习之手写识别.pptx

147 KB
Binary file not shown.

资源/dog.jpg

7.78 KB
Loading

0 commit comments

Comments
 (0)