title: In OpenCV (Python), why am I getting 3 channel images from a grayscale image?
body: <p>I am using Python (2.7) and bindings for OpenCV 2.4.6 on Ubuntu 12.04</p>
  
  <p>I load an image</p>
  
  <pre><code>    image = cv2.imread('image.jpg')
  </code></pre>
  
  <p>I then check the shape of the image array</p>
  
  <pre><code>    print image.shape
  </code></pre>
  
  <p>I get (480, 640, 3), which I expect for a 640x480 colour image. I then convert the image to grayscale and check the shape again.</p>
  
  <pre><code>    gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
      print gray_image.shape
  </code></pre>
  
  <p>I get (480, 640, 1), which I expect for a 640x480 <strong>grayscale</strong> image. I then save the image:</p>
  
  <pre><code>    cv2.imwrite('gray.jpg', gray_image)
  </code></pre>
  
  <p>I am on linux, so I tried looking at the image with gThumb, which shows all the colour channels. When I bring the gray image back into OpenCV the image has three channels again.
  I am aware of this flag for reading images:</p>
  
  <pre><code>    CV_LOAD_IMAGE_GRAYSCALE - If set, always convert image to the grayscale one
  </code></pre>
  
  <p>But this sounds like it is going to bring in the image as a colour image and then convert it. I am porting this project to RaspberryPi so I don't want unecessary operatioms happening.</p>
  
  <p>EDIT: I have done some timing checks and I have discovered that loading an image using the CV_LOAD_IMAGE_GRAYSCALE flag set results in the image loading twice as fast, irrespective of the image input.</p>
  
  <pre><code>     Using a 3072 x 4608 x 3 image
       0.196774959564 seconds with default loading
       0.0931899547577 seconds with CV_LOAD_IMAGE_GRAYSCALE
  </code></pre>
  
  <p><strong>The problem seems to be that OpenCV is creating a 3 channel JPG output whether I have a grayscale image matrix or not!</strong></p>
  
  <p>What other app can I use to make sure I am getting a single 8 bit channel JPG image out??
  (Perhaps gThumb is reporting the channels incorrectly).</p>
  
  <p>If the image is not single channel, why is OpenCV saving my grayscale image to a 3 channel image at disk write?</p>
  
  <p>Thanks in advance.</p>