def extract_images(f):
print('<STR_LIT>', f.name)<EOL>with gzip.GzipFile(fileobj=f) as bytestream:<EOL><INDENT>magic = _read32(bytestream)<EOL>if magic != <NUM_LIT>:<EOL><INDENT>raise ValueError(<EOL>'<STR_LIT>' %<EOL>(magic, f.name))<EOL><DEDENT>num_images = _read32(bytestream)<EOL>rows = _read32(bytestream)<EOL>cols = _read32(bytestream)<EOL>buf = bytestream.read(rows * cols * num_images)<EOL>data = numpy.frombuffer(buf, dtype=numpy.uint8)<EOL>data = data.reshape(num_images, rows, cols, <NUM_LIT:1>)<EOL>return data<EOL><DEDENT>
Extract the images into a 4D uint8 numpy array [index, y, x, depth].

    :param: f: A file object that can be passed into a gzip reader.
    :return: data: A 4D unit8 numpy array [index, y, x, depth].
    :raise: ValueError: If the bytestream does not start with 2051.