FloatImage.cc
Go to the documentation of this file.
00001 #include "FloatImage.h"
00002 #include "Gaussian.h"
00003 #include <iostream>
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::operator=(const FloatImage& other) {
00016   width = other.width;
00017   height = other.height;
00018   if (pixels.size() != other.pixels.size())
00019     pixels.resize(other.pixels.size());
00020   pixels = other.pixels;
00021   return *this;
00022 }
00023 
00024 void FloatImage::decimateAvg() {
00025   int nWidth = width/2;
00026   int nHeight = height/2;
00027 
00028   for (int y = 0; y < nHeight; y++)
00029     for (int x = 0; x < nWidth; x++)
00030       pixels[y*nWidth+x] = pixels[(2*y)*width + (2*x)];
00031 
00032   width = nWidth;
00033   height = nHeight;
00034   pixels.resize(nWidth*nHeight);
00035 }
00036 
00037 void FloatImage::normalize() {
00038   const float maxVal = *max_element(pixels.begin(),pixels.end());
00039   const float minVal = *min_element(pixels.begin(),pixels.end());
00040   const float range = maxVal - minVal;
00041   const float rescale = 1 / range;
00042   for ( unsigned int i = 0; i < pixels.size(); i++ )
00043     pixels[i] = (pixels[i]-minVal) * rescale;
00044 }
00045 
00046 void FloatImage::filterFactoredCentered(const std::vector<float>& fhoriz, const std::vector<float>& fvert) {
00047   // do horizontal
00048   std::vector<float> r(pixels);
00049 
00050   for (int y = 0; y < height; y++) {
00051     Gaussian::convolveSymmetricCentered(pixels, y*width, width, fhoriz, r, y*width);
00052   }
00053 
00054   // do vertical
00055   std::vector<float> tmp(height); // column before convolution
00056   std::vector<float> tmp2(height); // column after convolution
00057 
00058   for (int x = 0; x < width; x++) {
00059 
00060     // copy the column out for locality
00061     for (int y = 0; y < height; y++)
00062       tmp[y] = r[y*width + x];
00063 
00064     Gaussian::convolveSymmetricCentered(tmp, 0, height, fvert, tmp2, 0);
00065 
00066     for (int y = 0; y < height; y++)
00067       pixels[y*width + x] = tmp2[y];
00068   }
00069 }
00070 
00071 void FloatImage::printMinMax() const {
00072   std::cout << "Min: " << *min_element(pixels.begin(),pixels.end()) << ", Max: " << *max_element(pixels.begin(),pixels.end()) << std::endl;
00073   //for (int i = 0; i < getNumFloatImagePixels(); i++)
00074   //  std::cout << "Index[" << i << "]: " << this->normalize().getFloatImagePixels()[i] << endl;
00075 }
00076 
00077 } // namespace


apriltags
Author(s): Mitchell Wills
autogenerated on Thu Aug 27 2015 12:23:28