radiometric.cpp
Go to the documentation of this file.
00001 
00004 #include "radiometric.hpp"
00005 
00006 rScheme::rScheme() {
00007         // ...
00008 }
00009 
00010 rScheme::rScheme(const cv::Mat &mM, const double &minT, const double &maxT, const double &minG, const double &maxG) {
00011         
00012         update(mM, minT, maxT, minG, maxG);
00013         
00014 }
00015 
00016 rScheme::~rScheme() { 
00017                 
00018         mappingMatrix.release();
00019         
00020 }
00021 
00022 void rScheme::update(const cv::Mat &mM, const double &minT, const double &maxT, const double &minG, const double &maxG) {
00023 
00024         minTemp = minT;
00025         maxTemp = maxT;
00026         
00027         minGraylevel = minG;
00028         maxGraylevel = maxG;
00029         
00030         mM.copyTo(mappingMatrix);
00031 
00032 }
00033 
00034 void rScheme::apply(const cv::Mat& src, cv::Mat& dst, float thermistorTemp, float interpolateVal) {
00035 
00036         if (dst.rows == 0) {
00037                 dst = cv::Mat::zeros(src.size(), CV_32FC1);
00038         }
00039         
00040         //printf("%s << mappingMatrix.size() = (%d,%d)\n", __FUNCTION__, mappingMatrix.rows, mappingMatrix.cols);
00041         
00042         // Find index for thermistorTemp:
00043         float thermistorIndex = ((std::max(std::min(thermistorTemp, maxTemp), minTemp) - minTemp) / (maxTemp - minTemp)) * float(mappingMatrix.cols - 1);
00044         
00045         //printf("%s << thermistor of (%f) out of (%f -> %f) gets index (%f)\n", __FUNCTION__, thermistorTemp, minTemp, maxTemp, thermistorIndex);
00046         
00047         float graylevelIndex;
00048         
00049         
00050         
00051         
00052         
00053         if (interpolateVal) {
00054                 
00055                 unsigned int tI[2], gI[2];
00056                 tI[0] = (unsigned int) (floor(thermistorIndex));
00057                 tI[1] = (unsigned int) (ceil(thermistorIndex));
00058                 
00059                 float v[4], d[4], final_val;
00060                 
00061                 /*
00062                 unsigned int tX, gX;
00063                 tX = (unsigned int) (floor(thermistorIndex + 0.5));
00064                 */
00065                 
00066                 for (unsigned int iii = 0; iii < src.rows; iii++) {
00067                         for (unsigned int jjj = 0; jjj < src.cols; jjj++) {
00068                                 
00069                                 final_val = 0.0;
00070                                 
00071                                 graylevelIndex = ((std::max(std::min(float(src.at<unsigned short>(iii,jjj)), maxGraylevel), minGraylevel) - minGraylevel) / (maxGraylevel - minGraylevel)) * float(mappingMatrix.rows - 1);
00072                                 gI[0] = (unsigned int) (floor(graylevelIndex));
00073                                 gI[1] = (unsigned int) (ceil(graylevelIndex));
00074                                 
00075                                 v[0] = mappingMatrix.at<double>(gI[0], tI[0]);
00076                                 v[1] = mappingMatrix.at<double>(gI[0], tI[1]);
00077                                 v[2] = mappingMatrix.at<double>(gI[1], tI[0]);
00078                                 v[3] = mappingMatrix.at<double>(gI[1], tI[1]);
00079                                 
00080                                 d[0] = pow(abs(gI[0] - float(graylevelIndex)), 2.0) + pow(abs(tI[0] - float(thermistorIndex)), 2.0);
00081                                 d[1] = pow(abs(gI[0] - float(graylevelIndex)), 2.0) + pow(abs(tI[1] - float(thermistorIndex)), 2.0);
00082                                 d[2] = pow(abs(gI[1] - float(graylevelIndex)), 2.0) + pow(abs(tI[0] - float(thermistorIndex)), 2.0);
00083                                 d[3] = pow(abs(gI[1] - float(graylevelIndex)), 2.0) + pow(abs(tI[1] - float(thermistorIndex)), 2.0);
00084                                 
00085                                 if (d[0] == 0.0) {
00086                                         dst.at<float>(iii,jjj) = v[0];
00087                                 } else if (d[1] == 0.0) {
00088                                         dst.at<float>(iii,jjj) = v[1];
00089                                 } else if (d[2] == 0.0) {
00090                                         dst.at<float>(iii,jjj) = v[2];
00091                                 } else if (d[3] == 0.0) {
00092                                         dst.at<float>(iii,jjj) = v[3];
00093                                 } else {
00094                                         final_val += v[0] * 1.0 / d[0];
00095                                         final_val += v[1] * 1.0 / d[1];
00096                                         final_val += v[2] * 1.0 / d[2];
00097                                         final_val += v[3] * 1.0 / d[3];
00098                                         
00099                                         dst.at<float>(iii,jjj) = final_val / ((1.0/d[0]) + (1.0/d[1]) + (1.0/d[2]) + (1.0/d[3]));
00100                                 }
00101 
00102                                 /*
00103                                 
00104                                 graylevelIndex = ((std::max(std::min(float(src.at<unsigned short>(iii,jjj)), maxGraylevel), minGraylevel) - minGraylevel) / (maxGraylevel - minGraylevel)) * float(mappingMatrix.rows - 1);
00105                                 gX = (unsigned int) (floor(graylevelIndex + 0.5));
00106                                 
00107                                 if (((iii % 100) == 0) && ((jjj % 100) == 0)) {
00108                                         printf("%s << [%d,%d] << [%f] (%d, %d) [%f] (%d, %d)<< (%f,%f) & (%f,%f) & (%f,%f) & (%f,%f) : [%f]\n", __FUNCTION__, iii, jjj, graylevelIndex, gI[0], gI[1], thermistorIndex, tI[0], tI[1], v[0], d[0], v[1], d[1], v[2], d[2], v[3], d[3], dst.at<float>(iii,jjj));
00109                                         printf("interp vs NN = (%f) vs (%f)\n", __FUNCTION__, dst.at<float>(iii,jjj), mappingMatrix.at<double>(gX, tX));
00110                                         
00111                                 }
00112                                 */
00113 
00114                         }
00115                 }
00116                 
00117         } else {
00118                 
00119                 unsigned int tI, gI;
00120                 tI = (unsigned int) (floor(thermistorIndex + 0.5));
00121 
00122         
00123                 for (unsigned int iii = 0; iii < src.rows; iii++) {
00124                         for (unsigned int jjj = 0; jjj < src.cols; jjj++) {
00125                                 
00126                                 graylevelIndex = ((std::max(std::min(float(src.at<unsigned short>(iii,jjj)), maxGraylevel), minGraylevel) - minGraylevel) / (maxGraylevel - minGraylevel)) * float(mappingMatrix.rows - 1);
00127                                 gI = (unsigned int) (floor(graylevelIndex + 0.5));
00128                                 dst.at<float>(iii,jjj) = mappingMatrix.at<double>(gI, tI);
00129                                 
00130                         }
00131                 }
00132         }
00133         
00134         
00135         
00136         // TEMP for testing
00137         /*
00138         double currMin = 7500, currMax = 9000;
00139         //minMaxLoc(src, &currMin, &currMax);
00140         
00141         for (unsigned int iii = 0; iii < src.rows; iii++) {
00142                 for (unsigned int jjj = 0; jjj < src.cols; jjj++) {
00143                         
00144                         dst.at<float>(iii,jjj) = ((float(src.at<unsigned short>(iii,jjj)) - currMin) / (currMax - currMin)) * 30.0 + 20.0;
00145                         
00146                 }
00147         }
00148         
00149         double newMin, newMax;
00150         
00151         minMaxLoc(dst, &newMin, &newMax);
00152         */
00153         
00154         // printf("%s << (%f, %f)\n", __FUNCTION__, newMin, newMax);
00155 
00156 }
00157 


thermalvis
Author(s): Stephen Vidas
autogenerated on Sun Jan 5 2014 11:38:45