Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

FloatImage.cc

Go to the documentation of this file.
00001 #include "FloatImage.h"
00002 #include "Gaussian.h"
00003 #include "DualCoding/Sketch.h"
00004 
00005 namespace AprilTags {
00006 
00007 FloatImage::FloatImage() : width(0), height(0), pixels() {}
00008 
00009 FloatImage::FloatImage(int widthArg, int heightArg) 
00010   : width(widthArg), height(heightArg), pixels(widthArg*heightArg) {}
00011 
00012 FloatImage::FloatImage(int widthArg, int heightArg, const std::vector<float>& pArg) 
00013   : width(widthArg), height(heightArg), pixels(pArg) {}
00014 
00015 FloatImage::FloatImage(const DualCoding::Sketch<DualCoding::uchar>& sketch) 
00016   : width(sketch.width), height(sketch.height), pixels(sketchToFloats(sketch)) {}
00017 
00018 FloatImage& FloatImage::operator=(const FloatImage& other) {
00019   width = other.width;
00020   height = other.height;
00021   if (pixels.size() != other.pixels.size())
00022     pixels.resize(other.pixels.size());
00023   pixels = other.pixels;
00024   return *this;
00025 }
00026 
00027 std::vector<float> FloatImage::sketchToFloats(const DualCoding::Sketch<DualCoding::uchar>& sketch) {
00028   const unsigned char *pix = sketch.data->getRawPixels();
00029   std::vector<float> result(sketch.width*sketch.height);
00030   // converts raw pixels to float array
00031   for (unsigned int i = 0; i < result.size(); i++)
00032     result[i] = float(pix[i]) / 255.0f;
00033   return result;
00034 }
00035 
00036 void FloatImage::decimateAvg() {
00037   int nWidth = width/2;
00038   int nHeight = height/2;
00039 
00040   for (int y = 0; y < nHeight; y++)
00041     for (int x = 0; x < nWidth; x++)
00042       pixels[y*nWidth+x] = pixels[(2*y)*width + (2*x)];
00043 
00044   width = nWidth;
00045   height = nHeight;
00046   pixels.resize(nWidth*nHeight);
00047 }
00048 
00049 void FloatImage::normalize() {
00050   const float maxVal = *max_element(pixels.begin(),pixels.end());
00051   const float minVal = *min_element(pixels.begin(),pixels.end());
00052   const float range = maxVal - minVal;
00053   const float rescale = 1 / range;
00054   for ( unsigned int i = 0; i < pixels.size(); i++ )
00055     pixels[i] = (pixels[i]-minVal) * rescale;
00056 }
00057 
00058 void FloatImage::filterFactoredCentered(const std::vector<float>& fhoriz, const std::vector<float>& fvert) {
00059   // do horizontal
00060   std::vector<float> r(pixels);
00061 
00062   for (int y = 0; y < height; y++) {
00063     Gaussian::convolveSymmetricCentered(pixels, y*width, width, fhoriz, r, y*width);
00064   }
00065 
00066   // do vertical
00067   std::vector<float> tmp(height); // column before convolution
00068   std::vector<float> tmp2(height); // column after convolution
00069 
00070   for (int x = 0; x < width; x++) {
00071 
00072     // copy the column out for locality
00073     for (int y = 0; y < height; y++)
00074       tmp[y] = r[y*width + x];
00075 
00076     Gaussian::convolveSymmetricCentered(tmp, 0, height, fvert, tmp2, 0);
00077 
00078     for (int y = 0; y < height; y++)
00079       pixels[y*width + x] = tmp2[y];
00080   }
00081 }
00082 
00083 void FloatImage::printMinMax() const {
00084   std::cout << "Min: " << *min_element(pixels.begin(),pixels.end()) << ", Max: " << *max_element(pixels.begin(),pixels.end()) << std::endl;
00085   //for (int i = 0; i < getNumFloatImagePixels(); i++)
00086   //  std::cout << "Index[" << i << "]: " << this->normalize().getFloatImagePixels()[i] << endl;
00087 }
00088 
00089 } // namespace

Tekkotsu v5.1CVS
Generated Mon May 9 04:58:39 2016 by Doxygen 1.6.3