Mat CmShow::Complex(CMat& _ang, CMat& _mag, CStr& title, float minMagShowAng, int flag) { CV_Assert(_ang.size() == _mag.size() && _ang.channels() == 1 && _mag.channels() == 1); Mat ang, mag; _ang.convertTo(ang, CV_32F); _mag.convertTo(mag, CV_32F); if (flag & SHOW_MAG_LOG) { cv::log(mag + 1, mag); CmCv::FFTShift(mag); } normalize(mag, mag, 0, 255, NORM_MINMAX, CV_8U); minMagShowAng *= 255; int rows = ang.rows, cols = ang.cols; Mat img8U3C(rows, flag & MAG_AS_SAT ? cols : cols * 2, CV_8UC3); if (!(flag & MAG_AS_SAT)) cvtColor(mag, img8U3C(Rect(cols, 0, cols, rows)), CV_GRAY2BGR); Mat showAng = img8U3C(Rect(0, 0, cols, rows)); Ornt2HueFunc ornt2HueFunc = flag & ORNT2HUE_SYM4 ? Ornt2HueSym4 : Ornt2Hue; for (int y = 0; y < rows; y++) { float* angV = ang.ptr<float>(y); byte* magV = mag.ptr<byte>(y); byte* angShow = showAng.ptr<byte>(y); for (int x = 0; x < cols; x++, angShow += 3) { if (magV[x] < minMagShowAng) continue; angShow[0] = ornt2HueFunc(angV[x]); angShow[1] = flag & MAG_AS_SAT ? magV[x] : 255; angShow[2] = 255; } } cvtColor(showAng, showAng, CV_HSV2BGR); SaveShow(img8U3C, title); return img8U3C; }
Mat CmShow::Complex(CMat& _cmplx, CStr& title, float minMagShowAng, int flag) { CV_Assert(_cmplx.channels() == 2 && _cmplx.data != NULL); Mat ang(_cmplx.size(), CV_32FC1), mag(_cmplx.size(), CV_32FC1), cmplx; _cmplx.convertTo(cmplx, CV_32F); for (int y = 0; y < cmplx.rows; y++) { float* cpV = cmplx.ptr<float>(y); float* angV = ang.ptr<float>(y); float* magV = mag.ptr<float>(y); for (int x = 0; x < cmplx.cols; x++, cpV+=2) { magV[x] = sqrt(cpV[0] * cpV[0] + cpV[1] * cpV[1]); angV[x] = cvFastArctan(cpV[1], cpV[0]); } } return Complex(ang, mag, title, minMagShowAng, flag); }
void BenchMarkLatex::printMat(CMat &_mat1d, CStr texFile, bool descendOrder) { FILE* f = fopen(_S(texFile), "w"); if (f == NULL){ printf("Can't open file %s\n", _S(texFile)); return; } CV_Assert(_mat1d.rows == _numMethod); Mat mat1d = _mat1d.reshape(1); int dataWidth = mat1d.cols; string strAlign = "|l||"; for (int i = 0; i < _mat1d.cols; i++){ for (int c = 0; c < _mat1d.channels(); c++) strAlign += "c"; strAlign += "|"; } fprintf(f, "\\begin{tabular}{%s} \\hline\n\t\\tabTitle \\\\", _S(strAlign)); const char* rankCommand[3] = {"\\first", "\\second", "\\third"}; Mat rnk1i = getRankIdx(mat1d, descendOrder); for (int i = 0; i < _numMethod; i++){ if (find(_subNumbers.begin(), _subNumbers.end(), i) != _subNumbers.end()) fprintf(f, "\t\\hline \\hline\n"); fprintf(f, "\t\\textbf{%-5s ", _S(_methodNames[i] + "}")); for (int j = 0; j < dataWidth; j++){ int idx = rnk1i.at<int>(i, j); if (idx < 3) fprintf(f, "& %s{%5.3f} ", rankCommand[idx], mat1d.at<double>(i, j)); else fprintf(f, "& %5.3f ", mat1d.at<double>(i, j)); } fprintf(f, "\\\\\n"); } fprintf(f, "\\hline\n\\end{tabular}\n"); fclose(f); }
void CmShow::mulChannelMat(CMat &mulChaMatNf, CStr &title, int numShow) { printf("An %dX%d mat with %d channels, with range:\n", mulChaMatNf.rows, mulChaMatNf.cols, mulChaMatNf.channels()); vecM mats; split(mulChaMatNf, mats); numShow = min((int)mats.size(), numShow); for (int i = 0; i < numShow; i++) { double minV, maxV; minMaxLoc(mats[i], &minV, &maxV); printf("\t%d[%g %g]\n", i, minV, maxV); normalize(mats[i], mats[i], 0, 1, NORM_MINMAX); SaveShow(mats[i], format(_S(title), i)); waitKey(1); } }