Using cv::magnitude instead of custom loop and Mat<float> instead of Mat<double> to compute gradient magnitude channel.