Efficient way to Black and White

scalf's picture

I have been using the stock Black and White patch to render any photo/video in BNW, however, this seems to be very costly to the CPU when used in a live video sense. Iw as wondering if there were any more effective ways to render a image source Black and White?

When I switch to BNW now I lose easily 50% of the frame rate and I know there must be a better way to do this. Any suggestions are much appreciated!

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

dust's picture
Re: Efficient way to Black and White

here is a mono cl kernel which is probably by far going to be the most efficient way of doing this on the gpu. the first image is the stock black and white patch. the second image is of a mono cl kernel. notice how in the test pattern they grey backgrounds are easily matched by messing with this cl kernels luminance settings.

__kernel void test_rgbaFFFF(__rd image2d_t srcimg, float x, float r, float g, float b, float a, __wr image2d_t dstimg)
{
   int2   pos = (int2)(get_global_id(0), get_global_id(1));
   float4   color = read_imagef(srcimg, CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST, pos);
   float mono;
   mono = (r * x * color.x) + (g * x * color.y) + (b * x * color.z);
   color = (float4)(mono,mono,mono,a);
   write_imagef(dstimg, pos, color * a);
}

franz's picture
Re: Efficient way to Black and White

cheap B&W : color controls, no saturation...

gtoledo3's picture
Re: Efficient way to Black and White

If you use color controls, try to use the color controls single patch, as opposed to the one that imports a composition called Color Controls (core image)

The patch that's inside of B/W that really does the process is Color Monochrome (core image).

Color controls is the first thing that came to my mind too, but it seems slightly odd that it would be any quicker than Color Monochrome.

I think I'd try to a/b color controls, color monochrome, the cl route, and maybe rendering directly to a glsl shader/glsl grid set to turn the color to b/w.

I'd guess that which is fastest would totally depend on the computer and gpu - some computers are going to grind badly when running image texture through CL (I'm looking at you ATI). I've had stuff that runs at 60+fps on nVidia's run at around 2-3fps on ATI's, because of the image texture processing with CL specifically (while non image based CL stuff ran fine).

cwright's picture
Re: Efficient way to Black and White

GLSL is most likely the cheapest on-the-fly. luma = 0.11 * b + 0.39 * r + 0.5 * g (one dot product in GLSL - so 1 texture read and 1 math instruction; hard to top that).

Alternatively, if it's static content (an image or video), just process it offline. This might be superior, because there's no chroma plane to decode (so it's less work to decode, and no filtering necessary).