title: How can I read in a RAW image in MATLAB?
body: <p>I want to open and read a <code>.raw</code> image in MATLAB. My file can be <a href="https://www.dropbox.com/s/yrvpl6nkn7ic5q2/m-001-1.raw?dl=1" rel="nofollow noreferrer">downloaded here</a>.   I have tried the following three code snippets, but neither gives the expected results.</p>
  
  <h1>Code Snippet #1</h1>
  
  <pre><code>    row=576;  col=768;
      fin=fopen('m-001-1.raw','r');
      I=fread(fin,row*col,'uint8=&gt;uint8'); 
      Z=reshape(I,row,col);
      Z=Z';
      k=imshow(Z);
  </code></pre>
  
  <p>It shows this picture: </p>
  
  <p><img src="https://i.stack.imgur.com/uugq5.jpg" alt="first"></p>
  
  <h1>Code Snippet #2</h1>
  
  <pre><code>    f=fopen('m-001-1.raw');
      a=fread(f);
      input_img = reshape(a,768, 576, 3);
      input_img = imrotate(input_img, -90);
      imwrite(input_img, 'm-001-1.jpg'); 
  </code></pre>
  
  <p>This saves a blank (just white) image in <code>.jpg</code> format.  </p>
  
  <h1>Code Snippet #3</h1>
  
  <pre><code>    id = fopen('m-001-1.raw', 'r');
      x = fread(id, [576,768], 'short');
  </code></pre>
  
  <p>When I use <code>imshow(x)</code>, this picture shows:  </p>
  
  <p><img src="https://i.stack.imgur.com/YBV3Z.jpg" alt="third"></p>
  
  <p>How do I read this picture correctly?</p>