001/**
002 * Copyright (c) 2011, The University of Southampton and the individual contributors.
003 * All rights reserved.
004 *
005 * Redistribution and use in source and binary forms, with or without modification,
006 * are permitted provided that the following conditions are met:
007 *
008 *   *  Redistributions of source code must retain the above copyright notice,
009 *      this list of conditions and the following disclaimer.
010 *
011 *   *  Redistributions in binary form must reproduce the above copyright notice,
012 *      this list of conditions and the following disclaimer in the documentation
013 *      and/or other materials provided with the distribution.
014 *
015 *   *  Neither the name of the University of Southampton nor the names of its
016 *      contributors may be used to endorse or promote products derived from this
017 *      software without specific prior written permission.
018 *
019 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
020 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
021 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
022 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
023 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
024 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
025 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
026 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
027 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
028 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
029 */
030package org.openimaj.image.processing.face.recognition.benchmarking.dataset;
031
032import java.io.File;
033import java.io.IOException;
034
035import org.openimaj.citation.annotation.Reference;
036import org.openimaj.citation.annotation.ReferenceType;
037import org.openimaj.data.dataset.ListBackedDataset;
038import org.openimaj.data.dataset.ListDataset;
039import org.openimaj.data.dataset.MapBackedDataset;
040import org.openimaj.experiment.annotations.DatasetDescription;
041import org.openimaj.image.FImage;
042import org.openimaj.image.ImageUtilities;
043
044/**
045 * A Dataset for Our Database of Faces/The ORL Face Database/The AT&T Face
046 * database.
047 * <p>
048 * Note that the faces are already cropped and (fairly well) aligned.
049 * 
050 * @author Jonathon Hare (jsh2@ecs.soton.ac.uk)
051 */
052@DatasetDescription(
053                name = "Our Database of Faces/The ORL Face Database/The AT&T Face database",
054                description = "Our Database of Faces, (formerly 'The ORL Database of Faces'), "
055                                + "contains a set of face images taken between April 1992 and April 1994 "
056                                + "at the lab. The database was used in the context of a face recognition "
057                                + "project carried out in collaboration with the Speech, Vision and "
058                                + "Robotics Group of the Cambridge University Engineering Department. "
059                                + "There are ten different images of each of 40 distinct subjects. "
060                                + "For some subjects, the images were taken at different times, varying "
061                                + "the lighting, facial expressions (open / closed eyes, smiling / not smiling) "
062                                + "and facial details (glasses / no glasses). "
063                                + "All the images were taken against a dark homogeneous background with the "
064                                + "subjects in an upright, frontal position (with tolerance for some side "
065                                + "movement). A preview image of the Database of Faces is available.",
066                url = "http://www.cl.cam.ac.uk/research/dtg/attarchive/facedatabase.html")
067@Reference(
068                type = ReferenceType.Inproceedings,
069                author = { "Samaria, F.S.", "Harter, A.C." },
070                title = "Parameterisation of a stochastic model for human face identification",
071                year = "1994",
072                booktitle = "Applications of Computer Vision, 1994., Proceedings of the Second IEEE Workshop on",
073                pages = { "138 ", "142" },
074                month = "dec")
075public class ATandTDataset extends MapBackedDataset<Integer, ListDataset<FImage>, FImage> {
076        /**
077         * Construct the dataset. The dataset must be in a directory called
078         * "att_faces" within a directory called "Data" within your home directory
079         * (the "user.home" system property).
080         * 
081         * @throws IOException
082         *             if an error occurs.
083         */
084        public ATandTDataset() throws IOException {
085                this(new File(System.getProperty("user.home"), "Data/att_faces"));
086        }
087
088        /**
089         * Construct with the given path to the dataset
090         * 
091         * @param baseDir
092         *            the dataset path
093         * 
094         * @throws IOException
095         *             if an error occurs.
096         */
097        public ATandTDataset(File baseDir) throws IOException {
098                super();
099
100                for (int s = 1; s <= 40; s++) {
101                        final ListBackedDataset<FImage> list = new ListBackedDataset<FImage>();
102                        map.put(s, list);
103
104                        for (int i = 1; i <= 10; i++) {
105                                final File file = new File(baseDir, "s" + s + "/" + i + ".pgm");
106
107                                final FImage image = ImageUtilities.readF(file);
108
109                                list.add(image);
110                        }
111                }
112        }
113}