title: Emgu C# OpenCV: Make Color Black transparent
body: <p>I'm currently trying to implement a function with OpenCV which makes the color black of an image transparent. I used this <a href="http://answers.opencv.org/question/24463/how-to-remove-black-background-from-grabcut-output-image-in-opencv-android/?comment=24786#comment-24786" rel="nofollow noreferrer">thread</a> as a guideline.
  Currently it is not working and I'm not sure if it is because of my transfer to C# or another mistake.</p>
  <pre><code>public Image&lt;Bgr, Byte&gt; BlackTransparent(Image&lt;Bgr, Byte&gt; image)
          {
              Mat imageMat = image.Mat;
              Mat finalMat = new Mat(imageMat.Rows, imageMat.Cols, Emgu.CV.CvEnum.DepthType.Cv8U, 4);
              Mat tmp = new Mat(imageMat.Rows, imageMat.Cols, Emgu.CV.CvEnum.DepthType.Cv8U, 1);
              Mat alpha = new Mat(imageMat.Rows, imageMat.Cols, Emgu.CV.CvEnum.DepthType.Cv8U, 1);
  
              CvInvoke.CvtColor(imageMat, tmp, Emgu.CV.CvEnum.ColorConversion.Bgr2Gray);
              CvInvoke.Threshold(tmp, alpha, 100, 255, Emgu.CV.CvEnum.ThresholdType.Binary);
  
        
              VectorOfMat rgb = new VectorOfMat(3);
  
              CvInvoke.Split(imageMat, rgb);
             
              Mat[] rgba = { rgb[0], rgb[1], rgb[2], alpha };
  
              VectorOfMat vector = new VectorOfMat(rgba);
  
              CvInvoke.Merge(vector, finalMat);
                  
              return finalMat.ToImage&lt;Bgr, Byte&gt;();
          }
  </code></pre>
  <p>If anybody has an idea or suggestion I would appreciate it.</p>
  <p>Bruno</p>