C++神经网络开发包ANNIE
源代码在线查看: tiles.cpp
#include #include "annie/annie.h" #include "annie/Image.h" #include "annie/Video.h" #include "ImageCompress.h" using namespace std; namespace annie { Images makeSubimages(const Image &i, unsigned xSize, unsigned ySize) { assert(!(i.getHeight() % ySize)); assert(!(i.getWidth() % xSize)); unsigned py = i.getHeight() / ySize; unsigned px = i.getWidth() / xSize; Images outImages(px * py); for(uint y=0; y for(uint x=0; x Image *si = i.subImage(xSize, ySize, x * xSize, y * ySize); ASSERT(si->getWidth() == xSize); ASSERT(si->getHeight() == ySize); if(!si) throw Exception("cannot create sub :("); ///XX outImages[y * px + x] = si; } return outImages; } TrainingSet *makeSubImageExamples(const Images &images, vector &outExamples) { ASSERT(images.size()); outExamples.resize(images.size()); uint pixels = images[0]->getWidth() * images[0]->getHeight(); TrainingSet *ts = new TrainingSet(pixels, pixels); for(uint w=0; w outExamples[w] = images[w]->toVector(Image::GRAY_MASK); ASSERT(outExamples[w].size() == pixels); ts->addIOpair(outExamples[w], outExamples[w]); } return ts; } } //annie