Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version
  1. Use inRange() to create alpha.
  2. Invert alpha.
  3. Split source.
  4. Merge source channel to final image including alpha.

      //Laod source and create alpha   
      Mat src=imread("red.png",1);   
      Mat alpha;   
      inRange(src, Scalar(0,0,250),  Scalar(0,0,255),alpha);    
      bitwise_not(alpha,alpha);
    
      //split source  
      Mat bgr[3];   
      split(src,bgr);   
    
      //Merge to final image including alpha   
      Mat tmp[4] = { bgr[0],bgr[1],bgr[2],alpha};   
      Mat dst;   
      merge(tmp,4,dst);   
      imwrite("dst.png",dst);
    

image description

image description