OpenGL-----Image Green Screening
来源:互联网 发布:空气能热水器 知乎 编辑:程序博客网 时间:2024/06/18 11:54
Green screening is a process whereby a range of colors in an image (typically highly saturated greens) is used to determine an alpha channel for the image, for purposes of compositing.
Two steps:
First, you are to write code to generate an alpha channel mask for an image based upon image color information. Second, you will complete an image compositing program that uses the alpha channel information of a foreground image and computes the over operator.
1.Masking
first convert the color data to HSV and next select the pixels to mask based on those which have a hue near the value 120 (green on a 360 degree scale),set the a=0;
/∗ Code to convert RGB to HSV Adapted from Foley, Van Dam, Feiner, and Hughes, pg. 592.Input RGB color primary values : r, g, and b on scale 0 − 255 Output HSV colors : h on scale 0−360, s and v on scale 0−1∗/#define maximum(x, y, z) ((x) > (y)? ((x) > (z)? (x) : (z)) : ((y) > (z)? (y) : (z)))#define minimum(x, y, z) ((x) < (y)? ((x) < (z)? (x) : (z)) : ((y) < (z)? (y) : (z))) void RGBtoHSV(int r, int g, int b, double &h, double &s, double &v){double red, green, blue;double max, min, delta;red=r/255.0;green=g/255.0;blue=b/255.0; /∗**r,g,b to 0−1 scale**∗/ max = maximum(red, green, blue);min = minimum(red, green, blue);v = max; /∗ value is maximum of r, g, b ∗/if (max == 0) { /∗ saturation and hue 0 if value is 0 ∗/s = 0;h = 0; } else {s = (max - min) / max;delta = max - min; if (delta == 0){h = 0; } else {if (red == max) {h = (green - blue) / delta; /∗ saturation is color purity on scale 0 − 1 ∗/ /∗ hue doesn’t matter if saturation is 0 ∗/ /∗ otherwise , determine hue on scale 0 − 360 ∗/} else if (green == max) {h = 2.0 + (blue - red) / delta;} else { /∗ (blue == max) ∗/h = 4.0 + (red - green) / delta;}h = h * 60.0;if(h < 0) {h = h + 360.0; } }}}
After masking:
2.Composite
Over Operator Defined
Each color channel C treated separated:
CP = aCA+(1-a)CB (Linear interpolation of colors)
if background is transparent
CP = aCA+(1-a)(aB)CB
Before:CP = aACA + (1-aA)aBCB
After: cP = cA + (1-aA)cB
Same for alpha: aP = aA + (1-aA)aB
Interpretation: a premultiplied (r,g,b,a) means that
over with Premultiplied Colors.
the real color is (R,G,B) = (ar, ar, ag)
The correct way to composite is:
**Interpolate foreground and background and then
composite**
PS:the value that you read(read_image OpenImageIO) from image is Premultiplied value.
- OpenGL-----Image Green Screening
- Green~~~
- 试映 test screening
- OpenGL-----Projective Image Warp
- Are Green Concerts Green?
- Call Screening(来电过滤) on Android N
- Simple OpenGL Image Library(soil纹理库)
- Green Sleeves
- Roedy Green
- Green Sleeves
- Green Scrollbar
- Green Day
- Going green
- Green Mutexes
- green uml
- Green threads
- Green vpn
- Green DAO
- 2015届华为校园招聘机试题及参考答案
- spring的极致与管理方法之均衡
- 反射
- 当数据类型为long的变量后面没有L加会有什么后果
- 图解SQL的各种连接join
- OpenGL-----Image Green Screening
- Mybatis insert 返回主键
- JSON-MAPPER
- 一个简单的android电池显示layout
- 1032. Sharing (25)
- CI_我的学习笔记
- 关于函数名与函数指针
- android学习之ListView的基本使用
- 系统设计一:简易的搜索系统