private void apply_filter_twice(KpmImage dst, KpmImage src)
        {
            KpmImage tmp = new KpmImage(src.getWidth(), src.getHeight());

            apply_filter(tmp, src);
            apply_filter(dst, tmp);
        }
Ejemplo n.º 2
0
        /**
         * Sample a receptor given (x,y,octave,scale) and a pyramid.
         */
        private double SampleReceptor(GaussianScaleSpacePyramid pyramid, double x, double y, int octave, int scale)
        {
            // Get the correct image from the pyramid
            KpmImage image = pyramid.get(octave, scale);
            double   a     = 1.0f / (1 << octave);
            double   b     = 0.5f * a - 0.5f;

            return(image.bilinearInterpolation(ClipScalar(x * a + b, 0, image.getWidth() - 2), ClipScalar(y * a + b, 0, image.getHeight() - 2)));
        }
Ejemplo n.º 3
0
 /**
  * Compute the difference image.
  *
  * d = im1 - im2
  */
 public void difference_image_binomial(KpmImage im1, KpmImage im2)
 {
     // Compute diff
     double[] p0 = (double[])this.getBuffer();
     double[] p1 = (double[])im1.getBuffer();
     double[] p2 = (double[])im2.getBuffer();
     for (int i = im1.getWidth() * im1.getHeight() - 1; i >= 0; i--)
     {
         p0[i] = p1[i] - p2[i];
     }
     return;
 }
Ejemplo n.º 4
0
        virtual public void computePolarGradients(KpmImage i_img)
        {
            double dx, dy;

            double[] a_gradient = this._angle;
            double[] m_gradient = this._mag;
            int      width      = this._size.w;
            int      height     = this._size.h;

            Debug.Assert(this._size.isEqualSize(i_img.getSize()));
            double[] im = (double[])i_img.getBuffer();


            int width_minus_1;
            int height_minus_1;

            int p_ptr;
            int pm1_ptr;
            int pp1_ptr;

            width_minus_1  = width - 1;
            height_minus_1 = height - 1;
            int gradient_ptr = 0;

            // Top row
            pm1_ptr = 0;                    // pm1_ptr = im;
            p_ptr   = 0;                    // p_ptr = im;
            pp1_ptr = width;                // pp1_ptr = p_ptr+width;

            dx = im[p_ptr + 1] - im[p_ptr]; // dx = p_ptr[1] - p_ptr[0];
            dy = im[pp1_ptr] - im[pm1_ptr]; // dy = pp1_ptr[0] - pm1_ptr[0];
            // SET_GRADIENT(dx, dy)
            a_gradient[gradient_ptr] = (Math.Atan2(dy, dx) + PI);
            m_gradient[gradient_ptr] = Math.Sqrt(dx * dx + dy * dy);
            gradient_ptr++;
            p_ptr++;
            pm1_ptr++;
            pp1_ptr++;

            for (int col = 1; col < width_minus_1; col++)
            {
                dx = im[p_ptr + 1] - im[p_ptr - 1];
                dy = im[pp1_ptr] - im[pm1_ptr];
                // SET_GRADIENT(dx, dy)
                a_gradient[gradient_ptr] = (Math.Atan2(dy, dx) + PI);
                m_gradient[gradient_ptr] = Math.Sqrt(dx * dx + dy * dy);
                gradient_ptr++;
                p_ptr++;
                pm1_ptr++;
                pp1_ptr++;
            }

            dx = im[p_ptr] - im[p_ptr - 1];
            dy = im[pp1_ptr] - im[pm1_ptr];
            // SET_GRADIENT(dx, dy)
            a_gradient[gradient_ptr] = (Math.Atan2(dy, dx) + PI);
            m_gradient[gradient_ptr] = Math.Sqrt(dx * dx + dy * dy);
            gradient_ptr++;
            p_ptr++;
            pm1_ptr++;
            pp1_ptr++;

            // Non-border pixels
            pm1_ptr = 0;// pm1_ptr = im;
            p_ptr   = pm1_ptr + width;
            pp1_ptr = p_ptr + width;

            for (int row = 1; row < height_minus_1; row++)
            {
                dx = im[p_ptr + 1] - im[p_ptr];
                dy = im[pp1_ptr] - im[pm1_ptr];
                // SET_GRADIENT(dx, dy)
                a_gradient[gradient_ptr] = (Math.Atan2(dy, dx) + PI);
                m_gradient[gradient_ptr] = Math.Sqrt(dx * dx + dy * dy);
                gradient_ptr++;
                p_ptr++;
                pm1_ptr++;
                pp1_ptr++;

                for (int col = 1; col < width_minus_1; col++)
                {
                    dx = im[p_ptr + 1] - im[p_ptr - 1];
                    dy = im[pp1_ptr] - im[pm1_ptr];
                    // SET_GRADIENT(dx, dy)
                    a_gradient[gradient_ptr] = (Math.Atan2(dy, dx) + PI);
                    m_gradient[gradient_ptr] = Math.Sqrt(dx * dx + dy * dy);
                    gradient_ptr++;
                    p_ptr++;
                    pm1_ptr++;
                    pp1_ptr++;
                }
                dx = im[p_ptr] - im[p_ptr - 1];
                dy = im[pp1_ptr] - im[pm1_ptr];
                // SET_GRADIENT(dx, dy)
                a_gradient[gradient_ptr] = (Math.Atan2(dy, dx) + PI);
                m_gradient[gradient_ptr] = Math.Sqrt(dx * dx + dy * dy);
                gradient_ptr++;
                p_ptr++;
                pm1_ptr++;
                pp1_ptr++;
            }

            // Lower row
            p_ptr   = height_minus_1 * width;// p_ptr = &im[height_minus_1*width];
            pm1_ptr = p_ptr - width;
            pp1_ptr = p_ptr;

            dx = im[p_ptr + 1] - im[p_ptr];
            dy = im[pp1_ptr] - im[pm1_ptr];
            // SET_GRADIENT(dx, dy)
            a_gradient[gradient_ptr] = (Math.Atan2(dy, dx) + PI);
            m_gradient[gradient_ptr] = Math.Sqrt(dx * dx + dy * dy);
            gradient_ptr++;
            p_ptr++;
            pm1_ptr++;
            pp1_ptr++;

            for (int col = 1; col < width_minus_1; col++)
            {
                dx = im[p_ptr + 1] - im[p_ptr - 1];
                dy = im[pp1_ptr] - im[pm1_ptr];
                // SET_GRADIENT(dx, dy)
                a_gradient[gradient_ptr] = (Math.Atan2(dy, dx) + PI);
                m_gradient[gradient_ptr] = Math.Sqrt(dx * dx + dy * dy);
                gradient_ptr++;
                p_ptr++;
                pm1_ptr++;
                pp1_ptr++;
            }

            dx = im[p_ptr] - im[p_ptr - 1];
            dy = im[pp1_ptr] - im[pm1_ptr];
            // SET_GRADIENT(dx, dy)
            a_gradient[gradient_ptr] = (Math.Atan2(dy, dx) + PI);
            m_gradient[gradient_ptr] = Math.Sqrt(dx * dx + dy * dy);
            gradient_ptr++;
            p_ptr++;
            pm1_ptr++;
            pp1_ptr++;
        }
Ejemplo n.º 5
0
        override public void computePolarGradients(KpmImage i_img)
        {
            double[] a_gradient = this._angle;
            double[] m_gradient = this._mag;
            double   dx, dy;
            int      width  = this._size.w;
            int      height = this._size.h;

            double[] im = (double[])i_img.getBuffer();



            int p_ptr;


            int width_minus_2  = width - 2;
            int height_minus_2 = height - 2;


            //Left Top
            p_ptr = 0;                             // p_ptr = im;
            dx    = im[p_ptr + 1] - im[p_ptr];     // dx = p_ptr[1] - p_ptr[0];
            dy    = im[p_ptr + width] - im[p_ptr]; // dy = pp1_ptr[0] - pm1_ptr[0];
            // SET_GRADIENT(dx, dy)
            a_gradient[p_ptr] = FastMath.fastAtan2(dy, dx) + Math.PI;
            m_gradient[p_ptr] = Math.Sqrt(dx * dx + dy * dy);
            p_ptr++;

            //Top row
            for (int col = width_minus_2; col > 0; col--)
            {
                dx = im[p_ptr + 1] - im[p_ptr - 1];
                dy = im[p_ptr + width] - im[p_ptr];
                // SET_GRADIENT(dx, dy)
                a_gradient[p_ptr] = FastMath.fastAtan2(dy, dx) + Math.PI;
                m_gradient[p_ptr] = Math.Sqrt(dx * dx + dy * dy);
                p_ptr++;
            }

            //Right Top
            dx = im[p_ptr] - im[p_ptr - 1];
            dy = im[p_ptr + width] - im[p_ptr];
            // SET_GRADIENT(dx, dy)
            a_gradient[p_ptr] = FastMath.fastAtan2(dy, dx) + Math.PI;
            m_gradient[p_ptr] = Math.Sqrt(dx * dx + dy * dy);


            //Non-Border
            p_ptr = width;
            for (int row = height_minus_2; row > 0; row--)
            {
                //Left
                dx = im[p_ptr + 1] - im[p_ptr];
                dy = im[p_ptr + width] - im[p_ptr - width];
                // SET_GRADIENT(dx, dy)
                a_gradient[p_ptr] = FastMath.fastAtan2(dy, dx) + Math.PI;
                m_gradient[p_ptr] = Math.Sqrt(dx * dx + dy * dy);
                p_ptr++;

                for (int col = width_minus_2; col > 0; col--)
                {
                    dx = im[p_ptr + 1] - im[p_ptr - 1];
                    dy = im[p_ptr + width] - im[p_ptr - width];
                    // SET_GRADIENT(dx, dy)
                    a_gradient[p_ptr] = FastMath.fastAtan2(dy, dx) + Math.PI;//(Math.atan2(dy, dx) + PI);
                    m_gradient[p_ptr] = Math.Sqrt(dx * dx + dy * dy);
                    p_ptr++;
                }
                //Right
                dx = im[p_ptr] - im[p_ptr - 1];
                dy = im[p_ptr + width] - im[p_ptr - width];
                // SET_GRADIENT(dx, dy)
                a_gradient[p_ptr] = (FastMath.fastAtan2(dy, dx) + Math.PI);
                m_gradient[p_ptr] = Math.Sqrt(dx * dx + dy * dy);
                p_ptr++;
            }

            // Lower row
            p_ptr = (height - 1) * width;// p_ptr = &im[height_minus_1*width];
            dx    = im[p_ptr + 1] - im[p_ptr];
            dy    = im[p_ptr] - im[p_ptr - width];
            // SET_GRADIENT(dx, dy)
            a_gradient[p_ptr] = (FastMath.fastAtan2(dy, dx) + Math.PI);
            m_gradient[p_ptr] = Math.Sqrt(dx * dx + dy * dy);
            p_ptr++;
            for (int col = width_minus_2; col > 0; col--)
            {
                dx = im[p_ptr + 1] - im[p_ptr - 1];
                dy = im[p_ptr] - im[p_ptr - width];
                // SET_GRADIENT(dx, dy)
                a_gradient[p_ptr] = (FastMath.fastAtan2(dy, dx) + Math.PI);
                m_gradient[p_ptr] = Math.Sqrt(dx * dx + dy * dy);
                p_ptr++;
            }
            dx = im[p_ptr] - im[p_ptr - 1];
            dy = im[p_ptr] - im[p_ptr - width];
            // SET_GRADIENT(dx, dy)
            a_gradient[p_ptr] = (FastMath.fastAtan2(dy, dx) + Math.PI);
            m_gradient[p_ptr] = Math.Sqrt(dx * dx + dy * dy);
        }
 private void apply_filter(KpmImage dst, KpmImage src)
 {
     binomial_4th_order(
         (double[])dst.getBuffer(), this.mTemp_f32_1, (double[])src.getBuffer(), src.getWidth(), src.getHeight());
 }
 private void apply_filter(KpmImage dst, INyARGrayscaleRaster src)
 {
     Debug.Assert(src.isEqualBufferType(NyARBufferType.INT1D_GRAY_8));
     binomial_4th_order((double[])dst.getBuffer(), this.mTemp_us16, (int[])src.getBuffer(), src.getWidth(), src.getHeight());
 }