title: saving gray images in JPEG using Matlab imwrite
body: <p>I am new to the world of image processing and would like to seek help with an issue I could not figure out. The issue is as follows:</p>
  
  <p>I have a gray (black and white) image 'grayimage' which I want to save using the <code>imwrite</code> function in Matlab using JPEG format. I am using the following syntax:</p>
  
  <pre><code>imwrite(grayimage,cmap, 'imagename.jpg', 'jpeg');
  </code></pre>
  
  <p>Now, when I open the image file imagename.jpg using image viewers I don't see a gray image.   It's colored and a different image than desired. </p>
  
  <p>Can anyone suggest what I am doing wrong and options /parameters I am missing in <code>imwrite</code>?</p>
  
  <p>I thought of converting the image to RGB and then save it in jpeg format. Will that help? </p>