Extract images from .idx3-ubyte file or GZIP via Python
<p>I have created a simple function for facerecognition by using the facerecognizer from OpenCV. It works all fine with images from people.</p>

<p>Now I would like to make a test by using handwritten characters instead of people. I came across MNIST dataset, but they store images in a weird file which I have never seen before.</p>

<p>I simply need to extract a few images from:</p>

<pre><code>train-images.idx3-ubyte
</code></pre>

<p>and save them in a folder as <code>.gif</code> </p>

<p>Or am I missunderstand this MNIST thing. If yes where could I get such a dataset?</p>

<p><strong>EDIT</strong></p>

<p>I also have the gzip file:</p>

<pre><code>train-images-idx3-ubyte.gz
</code></pre>

<p>I am trying to read the content, but <code>show()</code> does not work and if I <code>read()</code> I see random symbols.</p>

<pre><code>images = gzip.open("train-images-idx3-ubyte.gz", 'rb')
print images.read()
</code></pre>

<p><strong>EDIT</strong></p>

<p>Managed to get some usefull output by using:</p>

<pre><code>with gzip.open('train-images-idx3-ubyte.gz','r') as fin:
    for line in fin:
        print('got line', line)
</code></pre>

<p>Somehow I have to convert this now to an image, output:</p>

<p><a href="https://i.stack.imgur.com/cpwvv.png" rel="noreferrer"><img src="https://i.stack.imgur.com/cpwvv.png" alt="enter image description here"></a></p>