edu.toronto.psi.vincent.util
Class ImageReaderWriter

java.lang.Object
  extended by edu.toronto.psi.vincent.util.ImageReaderWriter

public class ImageReaderWriter
extends java.lang.Object

Class for reading images from files to multidimensional arrays and writing multidimensional arrays to image files. The supported image formats are those natively supported by Java, i.e. JPEG, GIF, PNG

 Copyright (C) 2005  Vincent Cheung (vincent@psi.toronto.edu, http://www.vincentcheung.ca/research/)
 
 This program is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License
 as published by the Free Software Foundation; either version 2
 of the License, or (at your option) any later version.
 
 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

Version:
1.5 11/23/05
Author:
Vincent Cheung

Constructor Summary
ImageReaderWriter()
           
 
Method Summary
static double[][][] read(java.lang.String filename)
          Reads an image from a file.
static double[][][][] read(java.lang.String prefix, java.lang.String postfix, int numFrames)
          Reads a video sequence from a set of image files.
static float[][][] readFloat(java.lang.String filename)
          Reads an image from a file.
static float[][][][] readFloat(java.lang.String prefix, java.lang.String postfix, int numFrames)
          Reads a video sequence from a set of image files.
static int[][][] readInt(java.lang.String filename)
          Reads an image from a file.
static int[][][][] readInt(java.lang.String prefix, java.lang.String postfix, int numFrames)
          Reads a video sequence from a set of image files.
static void write(boolean[][][] samples, java.lang.String prefix, java.lang.String postfix)
          Writes a video sequence as a set of images.
static void write(boolean[][] samples, java.lang.String filename)
          Writes an image to a file.
static void write(double[][][][] samples, java.lang.String prefix, java.lang.String postfix)
          Writes a video sequence as a set of images.
static void write(double[][][] samples, java.lang.String filename)
          Writes an image to a file.
static void write(double[][] samples, java.lang.String filename)
          Writes a gray scale image to a file.
static void write(float[][][][] samples, java.lang.String prefix, java.lang.String postfix)
          Writes a video sequence as a set of images.
static void write(float[][][] samples, java.lang.String filename)
          Writes an image to a file.
static void write(float[][] samples, java.lang.String filename)
          Writes a gray scale image to a file.
static void write(int[][][][] samples, java.lang.String prefix, java.lang.String postfix)
          Writes a video sequence as a set of images.
static void write(int[][][] samples, java.lang.String filename)
          Writes an image to a file.
static void write(int[][] samples, java.lang.String filename)
          Writes a gray scale image to a file.
static void writeScaledGray(double[][][][] samples, java.lang.String prefix, java.lang.String postfix)
          Writes a video as a set of gray scale images by summing over the RGB values, then rescaling to use the full gray scale.
static void writeScaledGray(double[][][] samples, java.lang.String filename)
          Writes an image as a gray scale image by summing over the RGB values, then rescaling to use the full gray scale.
static void writeScaledGray(double[][] gray, double maxVal, double minVal, java.lang.String filename)
          Writes an image as a gray scale image by summing over the RGB values, then rescaling to use the full gray scale
static void writeScaledGray(float[][][][] samples, java.lang.String prefix, java.lang.String postfix)
          Writes a video as a set of gray scale images by summing over the RGB values, then rescaling to use the full gray scale.
static void writeScaledGray(float[][][] samples, java.lang.String filename)
          Writes an image as a gray scale image by summing over the RGB values, then rescaling to use the full gray scale.
static void writeScaledGray(int[][][][] samples, java.lang.String prefix, java.lang.String postfix)
          Writes a video as a set of gray scale images by summing over the RGB values, then rescaling to use the full gray scale.
static void writeScaledGray(int[][][] samples, java.lang.String filename)
          Writes an image as a gray scale image by summing over the RGB values, then rescaling to use the full gray scale.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ImageReaderWriter

public ImageReaderWriter()
Method Detail

read

public static double[][][] read(java.lang.String filename)
                         throws java.io.IOException
Reads an image from a file. The pixels are normalized between 0 and 1.

Parameters:
filename - the name of the image file
Returns:
a multidimensional array holding the separate RGB components normalized between 0 and 1
Throws:
java.io.IOException

read

public static double[][][][] read(java.lang.String prefix,
                                  java.lang.String postfix,
                                  int numFrames)
                           throws java.io.IOException
Reads a video sequence from a set of image files. The pixels are normalized between 0 and 1. The filename of the images are formatted as: prefix + frame# + postfix

Parameters:
prefix - the prefix of the name of the image file
postfix - the postfix of the name of the image file
numFrames - the number of frames to read
Throws:
java.io.IOException

write

public static void write(double[][][] samples,
                         java.lang.String filename)
                  throws java.io.IOException
Writes an image to a file. The image can be gray scale where samples[0][0].length == 1 instead of 3. The pixels must be normalized between 0 and 1.

Parameters:
samples - a multidimensional array holding the separate RGB components normalized between 0 and 1
filename - the name of the image file
Throws:
java.io.IOException

write

public static void write(double[][] samples,
                         java.lang.String filename)
                  throws java.io.IOException
Writes a gray scale image to a file. The pixels must be normalized between 0 and 1.

Parameters:
samples - a multidimensional array holding the gray values normalized between 0 and 1
filename - the name of the image file
Throws:
java.io.IOException

write

public static void write(double[][][][] samples,
                         java.lang.String prefix,
                         java.lang.String postfix)
                  throws java.io.IOException
Writes a video sequence as a set of images. The video can be gray scale where samples[0][0][0].length == 1 instead of 3. The pixels must be normalized between 0 and 1. The filename of the images are formatted as: prefix + frame# + postfix

Parameters:
samples - a multidimensional array holding the separate RGB components normalized between 0 and 1, where the first dimension indexes the frame and the remaining dimensions represent the frame image
prefix - the prefix of the name of the image file
postfix - the postfix of the name of the image file
Throws:
java.io.IOException

writeScaledGray

public static void writeScaledGray(double[][][] samples,
                                   java.lang.String filename)
                            throws java.io.IOException
Writes an image as a gray scale image by summing over the RGB values, then rescaling to use the full gray scale.

Parameters:
samples - a multidimensional array holding the separate RGB components normalized between 0 and 1
filename - the base filename of the image file
Throws:
java.io.IOException

writeScaledGray

public static void writeScaledGray(double[][] gray,
                                   double maxVal,
                                   double minVal,
                                   java.lang.String filename)
                            throws java.io.IOException
Writes an image as a gray scale image by summing over the RGB values, then rescaling to use the full gray scale

Parameters:
gray - a multidimensional array holding the summed RGB components
filename - the base filename of the image file
Throws:
java.io.IOException

writeScaledGray

public static void writeScaledGray(double[][][][] samples,
                                   java.lang.String prefix,
                                   java.lang.String postfix)
                            throws java.io.IOException
Writes a video as a set of gray scale images by summing over the RGB values, then rescaling to use the full gray scale.

Parameters:
samples - a multidimensional array holding the separate RGB components normalized between 0 and 1, where the first dimension indexes the frame and the remaining dimensions represent the frame image
prefix - the prefix of the name of the image file
postfix - the postfix of the name of the image file
Throws:
java.io.IOException

readInt

public static int[][][] readInt(java.lang.String filename)
                         throws java.io.IOException
Reads an image from a file.

Parameters:
filename - the name of the image file
Returns:
a multidimensional array holding the separate RGB components with values between 0 and 255
Throws:
java.io.IOException

readInt

public static int[][][][] readInt(java.lang.String prefix,
                                  java.lang.String postfix,
                                  int numFrames)
                           throws java.io.IOException
Reads a video sequence from a set of image files. The filename of the images are formatted as: prefix + frame# + postfix

Parameters:
prefix - the prefix of the name of the image file
postfix - the postfix of the name of the image file
numFrames - the number of frames to read
Throws:
java.io.IOException

write

public static void write(int[][][] samples,
                         java.lang.String filename)
                  throws java.io.IOException
Writes an image to a file. The image can be gray scale where samples[0][0].length == 1 instead of 3.

Parameters:
samples - a multidimensional array holding the separate RGB components with values between 0 and 255
filename - the name of the image file
Throws:
java.io.IOException

write

public static void write(int[][] samples,
                         java.lang.String filename)
                  throws java.io.IOException
Writes a gray scale image to a file.

Parameters:
samples - a multidimensional array holding the gray values with values between 0 and 255
filename - the name of the image file
Throws:
java.io.IOException

write

public static void write(int[][][][] samples,
                         java.lang.String prefix,
                         java.lang.String postfix)
                  throws java.io.IOException
Writes a video sequence as a set of images. The video can be gray scale where samples[0][0][0].length == 1 instead of 3. The filename of the images are formatted as: prefix + frame# + postfix

Parameters:
samples - a multidimensional array holding the separate RGB components with values between 0 and 255, where the first dimension indexes the frame and the remaining dimensions represent the frame image
prefix - the prefix of the name of the image file
postfix - the postfix of the name of the image file
Throws:
java.io.IOException

writeScaledGray

public static void writeScaledGray(int[][][] samples,
                                   java.lang.String filename)
                            throws java.io.IOException
Writes an image as a gray scale image by summing over the RGB values, then rescaling to use the full gray scale.

Parameters:
samples - a multidimensional array holding the separate RGB components with values between 0 and 255
filename - the base filename of the image file
Throws:
java.io.IOException

writeScaledGray

public static void writeScaledGray(int[][][][] samples,
                                   java.lang.String prefix,
                                   java.lang.String postfix)
                            throws java.io.IOException
Writes a video as a set of gray scale images by summing over the RGB values, then rescaling to use the full gray scale.

Parameters:
samples - a multidimensional array holding the separate RGB components with values between 0 and 255, where the first dimension indexes the frame and the remaining dimensions represent the frame image
prefix - the prefix of the name of the image file
postfix - the postfix of the name of the image file
Throws:
java.io.IOException

readFloat

public static float[][][] readFloat(java.lang.String filename)
                             throws java.io.IOException
Reads an image from a file. The pixels are normalized between 0 and 1.

Parameters:
filename - the name of the image file
Returns:
a multidimensional array holding the separate RGB components normalized between 0 and 1
Throws:
java.io.IOException

readFloat

public static float[][][][] readFloat(java.lang.String prefix,
                                      java.lang.String postfix,
                                      int numFrames)
                               throws java.io.IOException
Reads a video sequence from a set of image files. The pixels are normalized between 0 and 1. The filename of the images are formatted as: prefix + frame# + postfix

Parameters:
prefix - the prefix of the name of the image file
postfix - the postfix of the name of the image file
numFrames - the number of frames to read
Throws:
java.io.IOException

write

public static void write(float[][][] samples,
                         java.lang.String filename)
                  throws java.io.IOException
Writes an image to a file. The image can be gray scale where samples[0][0].length == 1 instead of 3. The pixels must be normalized between 0 and 1.

Parameters:
samples - a multidimensional array holding the separate RGB components normalized between 0 and 1
filename - the name of the image file
Throws:
java.io.IOException

write

public static void write(float[][][][] samples,
                         java.lang.String prefix,
                         java.lang.String postfix)
                  throws java.io.IOException
Writes a video sequence as a set of images. The video can be gray scale where samples[0][0][0].length == 1 instead of 3. The pixels must be normalized between 0 and 1. The filename of the images are formatted as: prefix + frame# + postfix

Parameters:
samples - a multidimensional array holding the separate RGB components normalized between 0 and 1, where the first dimension indexes the frame and the remaining dimensions represent the frame image
prefix - the prefix of the name of the image file
postfix - the postfix of the name of the image file
Throws:
java.io.IOException

write

public static void write(float[][] samples,
                         java.lang.String filename)
                  throws java.io.IOException
Writes a gray scale image to a file. The pixels must be normalized between 0 and 1.

Parameters:
samples - a multidimensional array holding the gray values normalized between 0 and 1
filename - the name of the image file
Throws:
java.io.IOException

writeScaledGray

public static void writeScaledGray(float[][][] samples,
                                   java.lang.String filename)
                            throws java.io.IOException
Writes an image as a gray scale image by summing over the RGB values, then rescaling to use the full gray scale.

Parameters:
samples - a multidimensional array holding the separate RGB components normalized between 0 and 1
filename - the base filename of the image file
Throws:
java.io.IOException

writeScaledGray

public static void writeScaledGray(float[][][][] samples,
                                   java.lang.String prefix,
                                   java.lang.String postfix)
                            throws java.io.IOException
Writes a video as a set of gray scale images by summing over the RGB values, then rescaling to use the full gray scale.

Parameters:
samples - a multidimensional array holding the separate RGB components normalized between 0 and 1, where the first dimension indexes the frame and the remaining dimensions represent the frame image
prefix - the prefix of the name of the image file
postfix - the postfix of the name of the image file
Throws:
java.io.IOException

write

public static void write(boolean[][] samples,
                         java.lang.String filename)
                  throws java.io.IOException
Writes an image to a file.

Parameters:
samples - a multidimensional array holding the separate RGB components normalized between 0 and 1
filename - the name of the image file
Throws:
java.io.IOException

write

public static void write(boolean[][][] samples,
                         java.lang.String prefix,
                         java.lang.String postfix)
                  throws java.io.IOException
Writes a video sequence as a set of images. The filename of the images are formatted as: prefix + frame# + postfix

Parameters:
samples - a multidimensional array holding the separate RGB components normalized between 0 and 1, where the first dimension indexes the frame and the remaining dimensions represent the frame image
prefix - the prefix of the name of the image file
postfix - the postfix of the name of the image file
Throws:
java.io.IOException