double aniComputeFilterCoefficients( double* pFilterX, double* pFilterTanp, double sigmav, double sigmau, double phi ) { double sigmax, sigmay, tanp; double su2, sv2; double phirad; double a11, a21, a22; su2 = sigmau * sigmau; sv2 = sigmav * sigmav; phirad = phi; a11 = cos(phirad) * cos(phirad) * su2 + sin(phirad) * sin(phirad) * sv2; a21 = cos(phirad) * sin(phirad) * ( su2 - sv2 ); a22 = cos(phirad) * cos(phirad) * sv2 + sin(phirad) * sin(phirad) * su2; sigmax = sqrt( a11 - a21 * a21 / a22 ); tanp = a21 / a22; sigmay = sqrt(a22); /* calculate filter coefficients of x-direction*/ YvVfilterCoef(sigmax, pFilterX); /* calculate filter coefficients in tanp-direction */ YvVfilterCoef(sigmay, pFilterTanp); return tanp; }
void iir_gaussianFilter1D(std::vector<float>& curve, int smoothingKernelSize) { if (curve.size() < 3) { return; } double sigma = 5.; if (smoothingKernelSize > 1) { sigma *= smoothingKernelSize; } double filter[7]; // calculate filter coefficients YvVfilterCoef(sigma, filter); // filter iir_1d_filter(curve.begin(), curve.begin(), curve.size(), filter); }
static void computeHistogramStatic(const HistogramRequest & request, boost::shared_ptr<FinishedHistogram> ret, int histogramIndex) { const int upscale = 5; std::vector<float> *histo = 0; switch (histogramIndex) { case 1: histo = &ret->histogram1; break; case 2: histo = &ret->histogram2; break; case 3: histo = &ret->histogram3; break; default: break; } assert(histo); /// keep the mode parameter in sync with Histogram::DisplayMode int mode = request.mode; ///if the mode is RGB, adjust the mode to either R,G or B depending on the histogram index if (mode == 0) { mode = histogramIndex + 2; } ret->pixelsCount = request.rect.area(); // a histogram with upscale more bins std::vector<float> histo_upscaled; switch (mode) { case 1: //< A computeHisto<&pix_alpha::val>(request, upscale, &histo_upscaled); break; case 2: //<Y computeHisto<&pix_lum::val>(request, upscale, &histo_upscaled); break; case 3: //< R computeHisto<&pix_red::val>(request, upscale, &histo_upscaled); break; case 4: //< G computeHisto<&pix_green::val>(request, upscale, &histo_upscaled); break; case 5: //< B computeHisto<&pix_blue::val>(request, upscale, &histo_upscaled); break; default: assert(false); break; } double sigma = upscale; if (request.smoothingKernelSize > 1) { sigma *= request.smoothingKernelSize; } // smooth the upscaled histogram double filter[7]; /* calculate filter coefficients */ YvVfilterCoef(sigma, filter); // filter iir_1d_filter(histo_upscaled.begin(), histo_upscaled.begin(), histo_upscaled.size(), filter); // downsample to obtain the final histogram histo->resize(request.binsCount); assert(histo_upscaled.size() == histo->size() * upscale); std::vector<float>::const_iterator it_in = histo_upscaled.begin(); std::advance(it_in, (upscale - 1) / 2); std::vector<float>::iterator it_out = histo->begin(); while ( it_out != histo->end() ) { *it_out = *it_in * upscale; ++it_out; if ( it_out != histo->end() ) { std::advance (it_in,upscale); } } } // computeHistogramStatic