View Javadoc

1   /**
2    * Copyright (c) 2011, The University of Southampton and the individual contributors.
3    * All rights reserved.
4    *
5    * Redistribution and use in source and binary forms, with or without modification,
6    * are permitted provided that the following conditions are met:
7    *
8    *   * 	Redistributions of source code must retain the above copyright notice,
9    * 	this list of conditions and the following disclaimer.
10   *
11   *   *	Redistributions in binary form must reproduce the above copyright notice,
12   * 	this list of conditions and the following disclaimer in the documentation
13   * 	and/or other materials provided with the distribution.
14   *
15   *   *	Neither the name of the University of Southampton nor the names of its
16   * 	contributors may be used to endorse or promote products derived from this
17   * 	software without specific prior written permission.
18   *
19   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20   * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21   * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
23   * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24   * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25   * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26   * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27   * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28   * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29   */
30  package org.openimaj.image.model.asm.datasets;
31  
32  import java.io.File;
33  import java.io.IOException;
34  import java.net.URL;
35  
36  import org.apache.commons.io.FileUtils;
37  import org.openimaj.citation.annotation.Reference;
38  import org.openimaj.citation.annotation.ReferenceType;
39  import org.openimaj.data.DataUtils;
40  import org.openimaj.experiment.annotations.DatasetDescription;
41  import org.openimaj.image.Image;
42  import org.openimaj.io.InputStreamObjectReader;
43  
44  /**
45   * The IMM Face Database (a set of labelled faces with connected points).
46   * 
47   * @author Jonathon Hare (jsh2@ecs.soton.ac.uk)
48   */
49  @DatasetDescription(
50  		name = "The IMM Face Database",
51  		description = "A dataset consisting of 240 annotated monocular " +
52  				"images of 40 different human faces. Points of correspondence are placed " +
53  				"on each image so the dataset can be readily used for building statistical " +
54  				"models of shape.",
55  		creator = "Michael M. Nordstrom, Mads Larsen, Janusz Sierakowski, and Mikkel B. Stegmann",
56  		url = "http://www2.imm.dtu.dk/~aam/datasets/datasets.html",
57  		downloadUrls = {
58  				"http://datasets.openimaj.org/imm_face_db.zip"
59  		})
60  @Reference(
61  		type = ReferenceType.Article,
62  		author = { "M. B. Stegmann", "B. K. Ersb{\\o}ll", "R. Larsen" },
63  		title = "{FAME} -- A Flexible Appearance Modelling Environment",
64  		year = "2003",
65  		journal = "IEEE Trans. on Medical Imaging",
66  		pages = { "1319", "1331" },
67  		number = "10",
68  		publisher = "IEEE",
69  		volume = "22")
70  public class IMMFaceDatabase {
71  	private static final String DATA_ZIP = "imm_face_db.zip";
72  	private static final String DATA_DOWNLOAD_URL = "http://datasets.openimaj.org/imm_face_db.zip";
73  
74  	/**
75  	 * Get a dataset of the IMM images and points. If the dataset hasn't been
76  	 * downloaded, it will be fetched automatically and stored in the OpenIMAJ
77  	 * data directory. The images in the dataset are grouped by their class.
78  	 * 
79  	 * @see DataUtils#getDataDirectory()
80  	 * 
81  	 * @param reader
82  	 *            the reader for images (can be <code>null</code> if you only
83  	 *            care about the points)
84  	 * @return the dataset
85  	 * @throws IOException
86  	 *             if an error occurs
87  	 */
88  	public static <IMAGE extends Image<?, IMAGE>> ShapeModelDataset<IMAGE> load(InputStreamObjectReader<IMAGE> reader)
89  			throws IOException
90  	{
91  		return ShapeModelDatasets.loadASFDataset(downloadAndGetPath(), reader);
92  	}
93  
94  	private static String downloadAndGetPath() throws IOException {
95  		final File dataset = DataUtils.getDataLocation(DATA_ZIP);
96  
97  		if (!(dataset.exists())) {
98  			dataset.getParentFile().mkdirs();
99  			FileUtils.copyURLToFile(new URL(DATA_DOWNLOAD_URL), dataset);
100 		}
101 
102 		return "zip:file:" + dataset.toString();
103 	}
104 
105 }