title: openCV: adding transparency to IplImage
body: <p>I have a 3-channel IplImage.  I would like to create a 4-channel image and set the alpha channel for it to a value less than 1.0 to make it semi-transparent.</p>
  
  <p>First I set the alpha channel (the 4-th channel) to 0.5:</p>
  
  <pre><code>cvSet(Image_c4, cvScalar(0,0,0,0.5);
  </code></pre>
  
  <p>Here is the command that I used to copy the 3-channel image into a 4-channel image.</p>
  
  <pre><code>cvCvtColor(Image_c3, Image_c4, CV_RGB2RGBA);
  </code></pre>
  
  <p>The problem: Image_c3 is in color.  Image_c4 becomes a gray scale copy of Image_c3 (and with no transparency).</p>
  
  <p><strong>Update</strong>:
  It turned out that the code above is actually correct and works and is actually more concise than the suggested solutions in the answers below.  I had an unrelated bug somewhere else.</p>