private void Fill2DArray(GaborFilterKernel fullKernel)
 {
     for (var i = 0; i < _kernelMatrix.Length; i++)
     {
         for (var j = 0; j < _kernelMatrix.Length; j++)
         {
             _kernelMatrix[i][j] = fullKernel[i - _definitionRange.Right, j - _definitionRange.Bottom];
         }
     }
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="GaborFilterKernelWithEnvelope"/> class.
        /// </summary>
        /// <param name="wavelength">The wavelength of the Gabor kernel.</param>
        /// <param name="orientation">The angle of the Gabor kernel.</param>
        /// <param name="envelopeWavelengthFactor">The side size of the definition range of the kernel.</param>
        public GaborFilterKernelWithEnvelope(double wavelength, double orientation, int envelopeWavelengthFactor)
        {
            var fullKernel = new GaborFilterKernel(wavelength, orientation);
            var sideSize   = (int)(wavelength * envelopeWavelengthFactor);

            // this is a quick fix dealing with even sized kernels.
            if (sideSize % 2 == 0)
            {
                sideSize += 1;
            }

            var left = -(sideSize / 2);

            _definitionRange    = new Rectangle(left, left, sideSize, sideSize);
            _kernelArrayXOffset = _definitionRange.Right - 1;
            _kernelArrayYOffset = _definitionRange.Bottom - 1;
            _kernelMatrix       = CreateSquareMatrix(sideSize);
            Fill2DArray(fullKernel);
            Factor = GetFactor();
        }