         if ((x < cols * channels ) && (y < rows))
         {
             size_t idx = y * ( step >> shift_and_sizeof<T>::shift ) + x;
-            mat[idx] = scalar_d[ x % channels ];
+            mat[idx] = scalar_d[ threadIdx.x];
         }
     }
 


namespace mat_operators
{
    __constant__ double scalar_d[4];


    template <typename T>

            if (mask[y * step_mask + x / channels] != 0)
            {
                size_t idx = y * ( step >> shift_and_sizeof<T>::shift ) + x;
                mat[idx] = scalar_d[ threadIdx.x ];
            }
    }

