mnist.tools
Class MnistManager

java.lang.Object
  extended by mnist.tools.MnistManager

public class MnistManager
extends java.lang.Object

Utility class for working with the MNIST database.

Provides methods for traversing the images and labels data files separately, as well as simultaneously.

Provides also method for exporting an image by writing it as a PPM file.

Example usage:

  MnistManager m = new MnistManager("t10k-images.idx3-ubyte", "t10k-labels.idx1-ubyte");
  m.setCurrent(10); //index of the image that we are interested in
  int[][] image = m.readImage();
  System.out.println("Label:" + m.readLabel());
  MnistManager.writeImageToPpm(image, "10.ppm");
 


Constructor Summary
MnistManager(java.lang.String imagesFile, java.lang.String labelsFile)
          Constructs an instance managing the two given data files.
 
Method Summary
 MnistImageFile getImages()
          Get the underlying images file as MnistImageFile.
 MnistLabelFile getLabels()
          Get the underlying labels file as MnistLabelFile.
 int[][] readImage()
          Reads the current image.
 int readLabel()
          Reads the current label.
 void setCurrent(int index)
          Set the position to be read.
static void writeImageToPpm(int[][] image, java.lang.String ppmFileName)
          Writes the given image in the given file using the PPM data format.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MnistManager

public MnistManager(java.lang.String imagesFile,
                    java.lang.String labelsFile)
             throws java.io.IOException
Constructs an instance managing the two given data files. Supports NULL value for one of the arguments in case reading only one of the files (images and labels) is required.

Parameters:
imagesFile - Can be NULL. In that case all future operations using that file will fail.
labelsFile - Can be NULL. In that case all future operations using that file will fail.
Throws:
java.io.IOException
Method Detail

writeImageToPpm

public static void writeImageToPpm(int[][] image,
                                   java.lang.String ppmFileName)
                            throws java.io.IOException
Writes the given image in the given file using the PPM data format.

Parameters:
image -
ppmFileName -
Throws:
java.io.IOException

readImage

public int[][] readImage()
                  throws java.io.IOException
Reads the current image.

Returns:
matrix
Throws:
java.io.IOException

setCurrent

public void setCurrent(int index)
Set the position to be read.

Parameters:
index -

readLabel

public int readLabel()
              throws java.io.IOException
Reads the current label.

Returns:
int
Throws:
java.io.IOException

getImages

public MnistImageFile getImages()
Get the underlying images file as MnistImageFile.

Returns:
MnistImageFile.

getLabels

public MnistLabelFile getLabels()
Get the underlying labels file as MnistLabelFile.

Returns:
MnistLabelFile.