manipulating luma in YUV color space

一个人想着一个人 提交于 2019-12-04 05:23:44

问题


I wont to set contrast / brightnes on image witch is in form byte[]. The image is in YCbCr_420 color space (android camera). I am geting luma value this way :

for (int j = 0, yp = 0; j < height; j++) {
for (int i = 0; i < width; i++, yp++) {
    int y = (0xff & (yuv420sp[yp])) - 16;
    }
}

How to manipulate y value to set more light? I am also not sure if this is gut way to set back the value :

yuv420sp[yp] = (byte) ((0xff & y) +16);

Thanx for any help.


回答1:


The little that I know from this API is that the values for the 3 channels are concatenated in a byte array. So, likewise in Windows working with RGB, I guess here you have the same, I mean, every 3 bytes representing one pixel. So I GUESS, you could access it jumping every 3 positions to access only one single channel (Luma in your case). I just don't know if the luma is represented by the first, second or third byte.

Second, if I understand you just want to change bright/contrast (increase/decrease) is that correct? Because if so, contrast is just multiplication and brightness is addition.

For instance - pseudo code assuming you are working with 8bits channel:

luma[y] = luma[y] * 1.10; //Increases contrast

or you can have a more generic form:

luma[y] = luma[y] + (luma[y] * contrast); //where contrast ranges from -1.0 to 1.0

Similarly you can do the same with brightness:

luma[y] = luma[y] + bright; //Where bright can range from -255 to 255

In both cases you have to be careful with overflows and underflows before you assign the final pixel result to your image.




回答2:


YUV processing is best demonstrated in the APLEAGLView.m file of this sample app:

https://developer.apple.com/library/ios/samplecode/AVBasicVideoOutput/Listings/AVBasicVideoOutput_APLEAGLView_m.html#//apple_ref/doc/uid/DTS40013109-AVBasicVideoOutput_APLEAGLView_m-DontLinkElementID_6

Proper adjustments to brightness and contrast so that they maintain their relationship in proportion to each other is demonstrated in the Shader.fsh file at:

https://developer.apple.com/library/ios/samplecode/AVBasicVideoOutput/Listings/AVBasicVideoOutput_Shaders_Shader_fsh.html#//apple_ref/doc/uid/DTS40013109-AVBasicVideoOutput_Shaders_Shader_fsh-DontLinkElementID_9

If you need help interpeting the code, I can help. For now, though, using a user-specified luma threshold value, the luma-adjusted Y plane is calculated like this:

Y' = (Y - (16 / 255)) * lumaThreshold;



来源:https://stackoverflow.com/questions/10684220/manipulating-luma-in-yuv-color-space

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!