# Show the brightness channel for each pixel

I want to shomewho calculate for each pixel which channel is the brightness, so for example, if we have for a specific point, rgba(100, 50, 200, 255), I would like rgba(0, 0, 255, 255) in return

I'm targeting JavaScript. With Python I would probably use numpy, but not sure how to do it in JS as I don't have that library.

Does CV has any in built library? How can I achieve that result whithout looping all the data buffer? In case of having to loop, which is the fastest way?

EDIT: Original vs Result

edit retag close merge delete

Sort by ยป oldest newest most voted

I would like rgba(0, 0, 255, 255) in return

some quite unusual format, and not supported from opencv (if you meant that literally).

but you can use cvtColor():

• to convert to to grayscale
• or to convert it to either LAB,YUV or YCbCr, and split() off the luminance channel (L or Y)

both approaches will result in a single channel, uchar image.

(alpha, being irrelevant in computer-vision, will just get discarded)

more

I can split the channels, but later I don't know how to make that vectorized operation. Looping is too slow.

I want to have blue or red, and discard green. I uploaded an image of the result, maybe there is another way to achieve the same.

( 2018-10-09 05:40:02 -0500 )edit

to make that vectorized operation

what ? try to be more concise. what do you want to do with it ?

( 2018-10-09 05:45:23 -0500 )edit
1

Thanks, I didn't know I could, I tried to add them before by replying my own question.

( 2018-10-09 05:46:20 -0500 )edit

thanks for the edit, btw !

( 2018-10-09 05:47:29 -0500 )edit

By vectorized operation I mean operations that are applied to whole arrays instead of individual elements, just like numpy in Python

( 2018-10-09 05:47:48 -0500 )edit

if the 2nd image is the answer to your question, then i don't understand it.

( 2018-10-09 06:15:31 -0500 )edit

The second one is made by WebGl, which uses the GPU. I wonder if CV has implemented a function that allows this operation natively.

( 2018-10-09 06:22:30 -0500 )edit

but it's not at all showing "the brightness channel"

( 2018-10-09 06:25:47 -0500 )edit

Yes, I know, for the brightness I could do (r,0,0,255) instead of (255, 0,0, 255). My application doesn't require that information.

I can do it with a loop in CV.Mat.data, but that kills the performance to ~1fps

( 2018-10-09 06:33:19 -0500 )edit

Official site

GitHub

Wiki

Documentation