         {
             sum = VecTraits<value_type>::all(0);
 
-            sum = sum + 0.0625f * smem1[0][1 + ((tidx - 2) >> 1)];
-            sum = sum + 0.25f   * smem1[0][1 + ((tidx - 1) >> 1)];
-            sum = sum + 0.375f  * smem1[0][1 + ((tidx    ) >> 1)];
-            sum = sum + 0.25f   * smem1[0][1 + ((tidx + 1) >> 1)];
-            sum = sum + 0.0625f * smem1[0][1 + ((tidx + 2) >> 1)];
+            sum = sum + (tidx % 2 == 0) * 0.0625f * smem1[0][1 + ((tidx - 2) >> 1)];
+            sum = sum + (tidx % 2 != 0) * 0.25f   * smem1[0][1 + ((tidx - 1) >> 1)];
+            sum = sum + (tidx % 2 == 0) * 0.375f  * smem1[0][1 + ((tidx    ) >> 1)];
+            sum = sum + (tidx % 2 != 0) * 0.25f   * smem1[0][1 + ((tidx + 1) >> 1)];
+            sum = sum + (tidx % 2 == 0) * 0.0625f * smem1[0][1 + ((tidx + 2) >> 1)];
 
             smem2[threadIdx.y][tidx] = sum;
         }


        sum = VecTraits<value_type>::all(0);

        sum = sum + 0.0625f * smem2[2 + threadIdx.y - 2][tidx];
        sum = sum + 0.25f   * smem2[2 + threadIdx.y - 1][tidx];
        sum = sum + 0.375f  * smem2[2 + threadIdx.y    ][tidx];
        sum = sum + 0.25f   * smem2[2 + threadIdx.y + 1][tidx];
        sum = sum + 0.0625f * smem2[2 + threadIdx.y + 2][tidx];

        if (x < dst.cols && y < dst.rows)
            dst.ptr(y)[x] = saturate_cast<T>(sum);
    }

    template <typename T, int cn> void pyrUp_gpu(const DevMem2D& src, const DevMem2D& dst, cudaStream_t stream)

        {
            sum = VecTraits<value_type>::all(0);

            sum = sum + (tidx % 2 == 0) * 0.0625f * smem1[9][1 + ((tidx - 2) >> 1)];
            sum = sum + (tidx % 2 != 0) * 0.25f   * smem1[9][1 + ((tidx - 1) >> 1)];
            sum = sum + (tidx % 2 == 0) * 0.375f  * smem1[9][1 + ((tidx    ) >> 1)];
            sum = sum + (tidx % 2 != 0) * 0.25f   * smem1[9][1 + ((tidx + 1) >> 1)];
            sum = sum + (tidx % 2 == 0) * 0.0625f * smem1[9][1 + ((tidx + 2) >> 1)];

            smem2[4 + threadIdx.y][tidx] = sum;
        }
