渲染测试

本文用于测试博客显示

markdown渲染测试

这是加粗的文字
这是倾斜的文字
这是斜体加粗的文字
这是加删除线的文字
超链接:百度

分割线





测试表格:

表头 表头 表头
靠左 居中 靠右

代码语法高亮测试

  • 测试bash代码:
1
2
3
function foo() {
console.log('这是一段测试代码')
}
  • 测试C++代码:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <cstdio>
#include <map>
using namespace std;

const int maxn = 10010;
int n, num, time, numtime, dmax = -1, cntmax = -1;
//n为输入行数,num为满足题意结点,time为遍历次数,numtime为满足题意的遍历次数
//dmax记录遍历过程中满足题意的最大深度,cntmax为最大子结点数

struct node {
int data, depth;
node *lchild, *mchild, *rchild;
};

map<int, node*> m; //使用map建立结点数字与结点指针的映射

node* newnode(int x) {
if(x == -1) { //如果输入值为-1,则返回空指针
return NULL;
}
node* root = new node;
root->data = x;
root->lchild = NULL;
root->mchild = NULL;
root->rchild = NULL;
return root;
}

void preOrder(node* root, int d) { //前序遍历输入根节点和深度
if(root == NULL) {
return;
}
root->depth = d;
time++;
int cnt = 0;
if(root->lchild != NULL) cnt++;
if(root->mchild != NULL) cnt++;
if(root->rchild != NULL) cnt++;
if(cnt >= cntmax && d > dmax) {
dmax = d;
cntmax = cnt;
num = root->data;
numtime = time;
}
preOrder(root->lchild, d + 1);
preOrder(root->mchild, d + 1);
preOrder(root->rchild, d + 1);
}

int main() {
scanf("%d", &n);
int n1, n2, n3, n4;
node* root;
for(int i = 0; i < n; i++) {
scanf("%d %d %d %d", &n1, &n2, &n3, &n4);
if(i == 0) {
root = newnode(n1);
m[n1] = root;
}
node* rtemp = m[n1];
rtemp->lchild = newnode(n2);
rtemp->mchild = newnode(n3);
rtemp->rchild = newnode(n4);
m[n2] = rtemp->lchild;
m[n3] = rtemp->mchild;
m[n4] = rtemp->rchild;
}
preOrder(root, 1);
printf("%d %d\n", num, numtime);
return 0;
}

  • 测试python代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import numpy as np
from PIL import Image

def cal_value(x, y, f):
x_decimal = x - np.floor(x)
y_decimal = y - np.floor(y)
x_base = int(np.floor(x))
y_base = int(np.floor(y))

if x_decimal == 0 and y_decimal == 0: # 若为整数点,直接返回对应数值
value = f[x_base][y_base]
elif x_decimal == 0: # 退化为y方向单线性插值
value = f[x_base][y_base] * (1 - y_decimal) + f[x_base][y_base + 1] * y_decimal
elif y_decimal == 0: # 退化为x方向单线性插值
value = f[x_base][y_base] * (1 - x_decimal) + f[x_base + 1][y_base] * x_decimal

else: # 执行双线性插值,value = L*C*R^T
L = [1 - x_decimal, x_decimal]
C = [[f[x_base][y_base], f[x_base][y_base + 1]],
[f[x_base + 1][y_base], f[x_base + 1][y_base + 1]]]
R = [1 - y_decimal, y_decimal]
value = np.dot(np.matmul(L, C), R)
return int(np.round(value))

# 定义原始图像的尺寸为src_x*src_y,现希望将其插值为tar_x*tar_y
def bilinear_interpolate(img, tar_x, tar_y):
x_proj = np.linspace(0, img.shape[0] - 1, tar_x)
y_proj = np.linspace(0, img.shape[1] - 1, tar_y)
temp_img = []
for i in x_proj:
temp_row = []
for j in y_proj:
temp_rgb = []
for k in range(3):
value = cal_value(i, j, img[:, :, k])
temp_rgb.append(value)
temp_row.append(temp_rgb)
temp_img.append(temp_row)
return temp_img

if __name__ == '__main__':
img = Image.open('Lenna.png')
img = np.array(img)
img_new = bilinear_interpolate(img, 256, 256)
img_new = np.uint8(np.array(img_new))
img = Image.fromarray(img_new)
img.show()