我是靠谱客的博主 傲娇溪流,这篇文章主要介绍图像运算(五)——混合(blending),现在分享给大家,希望可以做个参考。

描述:两幅图像各占一定比例的进行混合成一个图像,但是两个占的百分比等于1,

公式描述:O(i,j) = P * I1(i,j) + (1-P) * I2(i,j), 其中P就是混合比(blending ratio)


Code:

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
/** *Applies the image Blend operator on the specified image arrays, *with the specified offset and scale value *@param src1_1d The first source image as a pixel array *@param src2_1d The second source image as a pixel array *@param blend The blending factor a float from 0..1 *@param width width of the destination image in pixels *@param height height of the destination image in pixels *@param oset The offset value *@param scale The scale value *@return A pixel array containing the blended image */


复制代码
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
public int [] DoBlend(int [] src1_1d, int [] src2_1d, float blend, int width, int height, float oset, float scale ){ int place1 = -1; int place2 = -1; int src1rgb = 0; int src2rgb = 0; int result = 0; //Get size of image and make 1d_arrays d_w = width; d_h = height; dest_1d = new int[d_w*d_h]; boolean firstwider = false; boolean secondwider = false; int wrap; if (i1_w > d_w){ wrap = ((i1_w + 1) - d_w); firstwider = true; } else if (i2_w > d_w){ wrap = ((i2_w + 1) - d_w); secondwider = true; } else { wrap = 0; } //if you know there is no wrap around, you can save yourself some time if (wrap == 0) { for (int i=0; i< dest_1d. length ; i++){ src2rgb = src2_1d[i] & 0x000000ff; src1rgb = src1_1d[i] & 0x000000ff; result = (int) ((scale * ( blend * src1rgb + ( 1 - blend ) * src2rgb )) + oset); if (result < 0){ result = 0; } else if (result > 255){ result = 255; } //create an int value for dest_1d dest_1d[i ] = 0xff000000 | (result + (result << 16) + (result << 8)); } return dest_1d; } else { for (int i=0; i< dest_1d. length ; i++){ //we might need to skip out some pixels which aren't in the overlap area if ((i %d_w ) == 0 ) { if ( i == 0 ){ place1 = 0; place2 = 0; } else if (secondwider) { place2 = place2 + wrap; place1 ++; } else if (firstwider){ place1 = place1 + wrap; place2 ++; } } else{ place2 ++; place1 ++; } src2rgb = src2_1d[place2] & 0x000000ff; src1rgb = src1_1d[place1] & 0x000000ff; result = (int) ((scale * ( blend * src1rgb + (1 - blend) * src2rgb )) + oset); if (result < 0){ result = 0; } else if (result > 255){ result = 255; } //create an int value for dest_1d dest_1d[i ] = 0xff000000 | (result + (result << 16) + (result << 8)); } return dest_1d; } }

Input Image:



P = 0.5


Output Image:



总结:实际上这个运算的效果是引起我学习图像处理的一个冲击力,感觉视觉效果很好,只是现在说来有点可笑而已。

最后

以上就是傲娇溪流最近收集整理的关于图像运算(五)——混合(blending)的全部内容,更多相关图像运算(五)——混合(blending)内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(76)

评论列表共有 0 条评论

立即
投稿
返回
顶部