mnist.tools
Class MnistImageFile

java.lang.Object
  extended by java.io.RandomAccessFile
      extended by mnist.tools.MnistDbFile
          extended by mnist.tools.MnistImageFile
All Implemented Interfaces:
java.io.Closeable, java.io.DataInput, java.io.DataOutput

public class MnistImageFile
extends MnistDbFile

MNIST database image file. Contains additional header information for the number of rows and columns per each entry.


Constructor Summary
MnistImageFile(java.lang.String name, java.lang.String mode)
          Creates new MNIST database image file ready for reading.
 
Method Summary
 int getCols()
          Number of columns per image.
 int getEntryLength()
          Number of bytes for each entry.
 int getHeaderSize()
           
 int getRows()
          Number of rows per image.
 void nextImage()
          Move the cursor to the next image.
 void prevImage()
          Move the cursor to the previous image.
 int[][] readImage()
          Reads the image at the current position.
 
Methods inherited from class mnist.tools.MnistDbFile
getCount, getCurrentIndex, next, prev, setCurrentIndex
 
Methods inherited from class java.io.RandomAccessFile
close, getChannel, getFD, getFilePointer, length, read, read, read, readBoolean, readByte, readChar, readDouble, readFloat, readFully, readFully, readInt, readLine, readLong, readShort, readUnsignedByte, readUnsignedShort, readUTF, seek, setLength, skipBytes, write, write, write, writeBoolean, writeByte, writeBytes, writeChar, writeChars, writeDouble, writeFloat, writeInt, writeLong, writeShort, writeUTF
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MnistImageFile

public MnistImageFile(java.lang.String name,
                      java.lang.String mode)
               throws java.io.FileNotFoundException,
                      java.io.IOException
Creates new MNIST database image file ready for reading.

Parameters:
name - the system-dependent filename
mode - the access mode
Throws:
java.io.IOException
java.io.FileNotFoundException
Method Detail

readImage

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

Returns:
matrix representing the image
Throws:
java.io.IOException

nextImage

public void nextImage()
               throws java.io.IOException
Move the cursor to the next image.

Throws:
java.io.IOException

prevImage

public void prevImage()
               throws java.io.IOException
Move the cursor to the previous image.

Throws:
java.io.IOException

getRows

public int getRows()
Number of rows per image.

Returns:
int

getCols

public int getCols()
Number of columns per image.

Returns:
int

getEntryLength

public int getEntryLength()
Description copied from class: MnistDbFile
Number of bytes for each entry. Defaults to 1.

Overrides:
getEntryLength in class MnistDbFile
Returns:
int

getHeaderSize

public int getHeaderSize()
Overrides:
getHeaderSize in class MnistDbFile