libeblearntools
|
00001 /*************************************************************************** 00002 * Copyright (C) 2010 by Pierre Sermanet * 00003 * pierre.sermanet@gmail.com * 00004 * All rights reserved. 00005 * 00006 * Redistribution and use in source and binary forms, with or without 00007 * modification, are permitted provided that the following conditions are met: 00008 * * Redistributions of source code must retain the above copyright 00009 * notice, this list of conditions and the following disclaimer. 00010 * * Redistributions in binary form must reproduce the above copyright 00011 * notice, this list of conditions and the following disclaimer in the 00012 * documentation and/or other materials provided with the distribution. 00013 * * Redistribution under a license not approved by the Open Source 00014 * Initiative (http://www.opensource.org) must display the 00015 * following acknowledgement in all advertising material: 00016 * This product includes software developed at the Courant 00017 * Institute of Mathematical Sciences (http://cims.nyu.edu). 00018 * * The names of the authors may not be used to endorse or promote products 00019 * derived from this software without specific prior written permission. 00020 * 00021 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED 00022 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 00023 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00024 * DISCLAIMED. IN NO EVENT SHALL ThE AUTHORS BE LIABLE FOR ANY 00025 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00026 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00027 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 00028 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00029 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00030 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00031 ***************************************************************************/ 00032 00033 #ifndef GRID_DATASET_HPP_ 00034 #define GRID_DATASET_HPP_ 00035 00036 #include <algorithm> 00037 00038 using namespace std; 00039 00040 namespace ebl { 00041 00043 // constructors & initializations 00044 00045 template <class Tdata> 00046 grid_dataset<Tdata>::grid_dataset(const char *name_, 00047 const char *inroot_, uint cellh, uint cellw) 00048 : dataset<Tdata>(name_, inroot_), cell_height(cellh), cell_width(cellw) { 00049 cout << "Grid dataset: using each " << cellh << "x" << cellw 00050 << " patch as new sample." << endl; 00051 } 00052 00053 template <class Tdata> 00054 grid_dataset<Tdata>::~grid_dataset() { 00055 } 00056 00058 // data extraction 00059 00060 template <class Tdata> 00061 intg grid_dataset<Tdata>::count_samples() { 00062 // TODO: implement finding biggest sample size and divide by number of cells 00063 // and return the maximum possible number of samples 00064 dataset<Tdata>::count_samples(); 00065 this->total_samples *= 100; 00066 return this->total_samples; 00067 } 00068 00069 template <class Tdata> 00070 bool grid_dataset<Tdata>:: 00071 add_data(idx<Tdata> &d, const string &class_name, 00072 const char *filename, const rect<int> *r, 00073 pair<uint,uint> *center) { 00074 bool ret; 00075 00076 for (uint i = 0; i <= d.dim(0) - cell_height; i += cell_height) { 00077 for (uint j = 0; j <= d.dim(1) - cell_width; j += cell_width) { 00078 rect<int> roi(i, j, cell_height, cell_width); 00079 cout << "roi: " << roi << endl; 00080 t_label label = this->get_label_from_class(class_name); 00081 midx<Tdata> dd(1); 00082 dd.set(d, 0); 00083 ret = dataset<Tdata>::add_data(dd, label, &class_name, filename, &roi); 00084 dd.clear(); 00085 } 00086 } 00087 return true; 00088 } 00089 00090 } // end namespace ebl 00091 00092 #endif /* GRID_DATASET_HPP_ */