title: How to convert binary data into an image in matlab
body: <p>I'm using the following code to convert an image into binary form.</p>
  
  <pre><code>% lets suppose that the name of image file is caption with an extension .jpg
  X=imread('caption.jpg');
  g=reshape((dec2bin(typecast(X(:),'uint8'),8)-'0').',1,[])
  </code></pre>
  
  <p>After running the code, I'm getting 1xn matrix of type double, having a series of 0's and 1's.</p>
  
  <p>Now I want to convert this matrix <code>g</code> back into an image.</p>
  
  <p>The converted image should be similar to caption.jpg.</p>