title: How to remove 4th channel from PNG images
body: <p>I am loading images from a URL in OpenCV. Some images are PNG and have four channels. I am looking for a way to remove the 4th channel, if it exists. </p>
  
  <p>This is how I load the image:</p>
  
  <pre><code>def read_image_from_url(self, imgurl):
      req = urllib.urlopen(imgurl)
      arr = np.asarray(bytearray(req.read()), dtype=np.uint8)
      return cv2.imdecode(arr,-1) # 'load it as it is'
  </code></pre>
  
  <p>I don't want to change the <code>cv2.imdecode(arr,-1)</code> but instead I want to check whether the loaded image has a fourth channel, and if so, remove it. </p>
  
  <p>Something like this but I don't know how to actually remove the 4th channel</p>
  
  <pre><code>def read_image_from_url(self, imgurl):
      req = urllib.urlopen(imgurl)
      arr = np.asarray(bytearray(req.read()), dtype=np.uint8)
      image = cv2.imdecode(arr,-1) # 'load it as it is'
      s = image.shape
      #check if third tuple of s is 4
      #if it is 4 then remove the 4th channel and return the image. 
  </code></pre>