Mat CmShow::HistBins(CMat& color3f, CMat& val, CStr& title, bool descendShow, CMat &with) { // Prepare data int H = 300, spaceH = 6, barH = 10, n = color3f.cols; CV_Assert(color3f.size() == val.size() && color3f.rows == 1); Mat binVal1i, binColor3b, width1i; if (with.size() == val.size()) with.convertTo(width1i, CV_32S, 400/sum(with).val[0]); // Default shown width else width1i = Mat(1, n, CV_32S, Scalar(600.0/(val.cols*val.rows))); // Default bin width = 10 int W = cvRound(sum(width1i).val[0]); color3f.convertTo(binColor3b, CV_8UC3, 255); double maxVal, minVal; minMaxLoc(val, &minVal, &maxVal); val.convertTo(binVal1i, CV_32S, H/max(maxVal, -minVal)); Size szShow(W, H + spaceH + barH); szShow.height += minVal < 0 && !descendShow ? H + spaceH : 0; Mat showImg3b(szShow, CV_8UC3, WHITE); int* binH = (int*)(binVal1i.data); Vec3b* binColor = (Vec3b*)(binColor3b.data); int* binW = (int*)(width1i.data); vector<CostiIdx> costIdx(n); if (descendShow) { for (int i = 0; i < n; i++) costIdx[i] = make_pair(binH[i], i); sort(costIdx.begin(), costIdx.end(), std::greater<CostiIdx>()); } // Show image for (int i = 0, x = 0; i < n; i++) { int idx = descendShow ? costIdx[i].second : i; int h = descendShow ? abs(binH[idx]) : binH[idx]; Scalar color(binColor[idx]); Rect reg(x, H + spaceH, binW[idx], barH); showImg3b(reg) = color; // Draw bar rectangle(showImg3b, reg, BLACK); reg.height = abs(h); reg.y = h >= 0 ? H - h : H + 2 * spaceH + barH; showImg3b(reg) = color; rectangle(showImg3b, reg, BLACK); x += binW[idx]; } putText(showImg3b, format("Min = %g, Max = %g", minVal, maxVal), Point(5, 20), CV_FONT_HERSHEY_PLAIN, 1, CV_RGB(255,0,0)); SaveShow(showImg3b, title); return showImg3b; }
void CmShow::Pseudocolor(CMat& matfd1, CStr& title) { Mat hsvMat[3], hsvM; matfd1.convertTo(hsvMat[0], CV_32FC1, -240, 240); hsvMat[1] = hsvMat[2] = Mat::ones(matfd1.size(), CV_32F); merge(hsvMat, 3, hsvM); cvtColor(hsvM, hsvM, CV_HSV2BGR); SaveShow(hsvM, title); }
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); }