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
00041
00042
00043 float thermistorIndex = ((std::max(std::min(thermistorTemp, maxTemp), minTemp) - minTemp) / (maxTemp - minTemp)) * float(mappingMatrix.cols - 1);
00044
00045
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
00063
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
00105
00106
00107
00108
00109
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
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156 }
00157