title: Trying to remove background and make it transparent in c++, using magick++
body: <p>I am having an image "objects.png" with a red background and I'm trying to make the background transparent. The code is straight forward but somehow I am not able to get the desired result. I am quite new to this ImageMagick business and this is my first program using Magick++. So, it would be great if you can explain things in detail. Thanks in advance. Code goes like this,</p>
  
  <pre><code>    #include &lt;iostream&gt;
      #include &lt;Magick++.h&gt;
  
      using namespace std;
      using namespace Magick;
  
      int main(){
          Image my_image("objects.png");
          Color bg_color = my_image.pixelColor(0,0);
          Color new_bg_color(0, MaxRGB, 0, MaxRGB);
  
          for (int i=0;i&lt;my_image.columns();i++){
              for (int j=0;j&lt;my_image.rows();j++){
                  //cout&lt;&lt;"(i,j) : ("&lt;&lt;i&lt;&lt;","&lt;&lt;j&lt;&lt;")\n";
                  if (my_image.pixelColor(i,j) == bg_color){
                      my_image.pixelColor(i,j,new_bg_color);
                  }
              }
          }
          my_image.write("new_objects.png"); 
      }
  </code></pre>
  
  <p>Image objects.png is
  <img src="https://i.stack.imgur.com/3HL4t.png" alt="input image"></p>
  
  <p>and I'm getting this as output 
  <img src="https://i.stack.imgur.com/P0hNK.png" alt="enter image description here"></p>