Ask Your Question
0

How to access alpha value at pixel using Mat.data?

asked 2018-02-27 19:23:01 -0600

Blath gravatar image

updated 2018-02-27 21:14:55 -0600

I found the following piece of code in this question. In which there is a piece of code to acces the alpha value that looks like this:

double opacity = (double)image.data[y*image.step + x * image.channels () +3]

I can't understand how this piece of code works, from what I have found, Mat.data is used to access a pixel at some location, and I can't understand why x*image.channels () is in the code.

Hopefully someone can explain me the code.

Thanks in advance.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2018-02-28 02:17:01 -0600

LBerger gravatar image

updated 2018-02-28 03:01:33 -0600

You can find answer tou your question in opencv tutorials: storing method it's https://docs.opencv.org/trunk/d6/d6d/... and How is the image matrix stored in memory? https://docs.opencv.org/trunk/db/da5/...

There is no specific function in opencv to use alpha channel : you will have to write everything yourself. There is no alpha values in image processing.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2018-02-27 19:23:01 -0600

Seen: 825 times

Last updated: Feb 28 '18