Ask Your Question

CvMat imread alpha

asked 2013-09-25 09:55:51 -0500

drKzs gravatar image

updated 2013-09-25 11:22:10 -0500


I was wondering what was the method to obtain,

  • from a cv::Mat obtained by imread({myFile}, CV_LOAD_IMAGE_UNCHANGED)
  • a cv::Mat identical to the one obtained by imread({myFile}, CV_LOAD_IMAGE_COLOR)

If I well understand, i need to remove the alpha channel from my cv::Mat ? so I have to remove one dimension of my matrix by iterate over cols & rows ?

(I precise if it wasn't obvious, i dunno anything in image treatment ;))

Thanx a lot :)

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2013-09-25 11:10:29 -0500

berak gravatar image

if you load it with :

imread({myFile}, CV_LOAD_IMAGE_COLOR)

you'll force it to return a 3 channel rgb (CV_8UC3) Mat, if it had alpha, it gets discarded already, if it was grey - you get a 3chanel grayscale img.


will return either a 1, 3, or 4 channel img, depending on the file. so you will have to check it:

if ( img.channels() = 3 ) 
// process rgb...
edit flag offensive delete link more


Ouuups I mistook, i wanted to go from CV_LOAD_IMAGE_UNCHANGED to CV_LOAD_IMAGE_COLOR... (i edit my post)

So i guess i need to convert it to 3 channel rgb with convertTo method... What i am wondering is which type to use, since I don't know which type is used when calling imread({myFile}, CV_LOAD_IMAGE_COLOR) .... So you seem to say it's CV_8UC3

drKzs gravatar imagedrKzs ( 2013-09-25 11:20:57 -0500 )edit

Question Tools


Asked: 2013-09-25 09:55:51 -0500

Seen: 436 times

Last updated: Sep 25 '13