Ask Your Question
0

Show the brightness channel for each pixel

asked 2018-10-09 05:05:33 -0600

dadiaar gravatar image

updated 2018-10-09 05:46:00 -0600

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?

Thanks a lot in advance!

EDIT: Original vs Result

Original

Result

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2018-10-09 05:19:34 -0600

berak gravatar image

updated 2018-10-09 05:44:30 -0600

yes, opencv has javascript bindings !

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)

edit flag offensive delete link more

Comments

Thanks for your reply.

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.

dadiaar gravatar imagedadiaar ( 2018-10-09 05:40:02 -0600 )edit

to make that vectorized operation

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

berak gravatar imageberak ( 2018-10-09 05:45:23 -0600 )edit
1

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

dadiaar gravatar imagedadiaar ( 2018-10-09 05:46:20 -0600 )edit

thanks for the edit, btw !

berak gravatar imageberak ( 2018-10-09 05:47:29 -0600 )edit

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

dadiaar gravatar imagedadiaar ( 2018-10-09 05:47:48 -0600 )edit

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

berak gravatar imageberak ( 2018-10-09 06:15:31 -0600 )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.

dadiaar gravatar imagedadiaar ( 2018-10-09 06:22:30 -0600 )edit

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

berak gravatar imageberak ( 2018-10-09 06:25:47 -0600 )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

dadiaar gravatar imagedadiaar ( 2018-10-09 06:33:19 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2018-10-09 05:05:33 -0600

Seen: 960 times

Last updated: Oct 09 '18