Пример #1
0
    void SBGaussian::SBGaussianImpl::fillXValue(tmv::MatrixView<double> val,
                                                double x0, double dx, int izero,
                                                double y0, double dy, int jzero) const
    {
        dbg<<"SBGaussian fillXValue\n";
        dbg<<"x = "<<x0<<" + i * "<<dx<<", izero = "<<izero<<std::endl;
        dbg<<"y = "<<y0<<" + j * "<<dy<<", jzero = "<<jzero<<std::endl;
        if (izero != 0 || jzero != 0) {
            xdbg<<"Use Quadrant\n";
            fillXValueQuadrant(val,x0,dx,izero,y0,dy,jzero);
        } else {
            xdbg<<"Non-Quadrant\n";
            assert(val.stepi() == 1);
            const int m = val.colsize();
            const int n = val.rowsize();
            typedef tmv::VIt<double,1,tmv::NonConj> It;

            x0 *= _inv_sigma;
            dx *= _inv_sigma;
            y0 *= _inv_sigma;
            dy *= _inv_sigma;

            // The Gaussian profile is separable:
            //    val = _norm * exp(-0.5 * (x*x + y*y)
            //        = _norm * exp(-0.5 * x*x) * exp(-0.5 * y*y)
            tmv::Vector<double> gauss_x(m);
            It xit = gauss_x.begin();
            for (int i=0;i<m;++i,x0+=dx) *xit++ = exp(-0.5 * x0*x0);
            tmv::Vector<double> gauss_y(n);
            It yit = gauss_y.begin();
            for (int j=0;j<n;++j,y0+=dy) *yit++ = exp(-0.5 * y0*y0);

            val = _norm * gauss_x ^ gauss_y;
        }
    }
Пример #2
0
    void SBGaussian::SBGaussianImpl::fillXImage(ImageView<T> im,
                                                double x0, double dx, int izero,
                                                double y0, double dy, int jzero) const
    {
        dbg<<"SBGaussian fillXImage\n";
        dbg<<"x = "<<x0<<" + i * "<<dx<<", izero = "<<izero<<std::endl;
        dbg<<"y = "<<y0<<" + j * "<<dy<<", jzero = "<<jzero<<std::endl;
        if (izero != 0 || jzero != 0) {
            xdbg<<"Use Quadrant\n";
            fillXImageQuadrant(im,x0,dx,izero,y0,dy,jzero);
        } else {
            xdbg<<"Non-Quadrant\n";
            const int m = im.getNCol();
            const int n = im.getNRow();
            T* ptr = im.getData();
            const int skip = im.getNSkip();
            assert(im.getStep() == 1);

            x0 *= _inv_sigma;
            dx *= _inv_sigma;
            y0 *= _inv_sigma;
            dy *= _inv_sigma;

            // The Gaussian profile is separable:
            //    im(x,y) = _norm * exp(-0.5 * (x*x + y*y)
            //            = _norm * exp(-0.5 * x*x) * exp(-0.5 * y*y)
            std::vector<double> gauss_x(m);
            std::vector<double> gauss_y(n);
            typedef std::vector<double>::iterator It;
            It xit = gauss_x.begin();
            for (int i=0; i<m; ++i,x0+=dx) *xit++ = fmath::expd(-0.5 * x0*x0);

            if ((x0 == y0) && (dx == dy) && (m==n)) {
                gauss_y = gauss_x;
            } else {
                It yit = gauss_y.begin();
                for (int j=0; j<n; ++j,y0+=dy) *yit++ = fmath::expd(-0.5 * y0*y0);
            }

            for (int j=0; j<n; ++j,ptr+=skip) {
                for (int i=0; i<m; ++i)
                    *ptr++ = _norm * gauss_x[i] * gauss_y[j];
            }
        }
    }