求图像梯度代码


void get_gradient_magnitude(Mat& _grey_img, Mat& _gradient_magnitude)
{
	Mat C = Mat_(_grey_img);

	Mat kernel = (Mat_(1, 3) << -1, 0, 1);
	Mat grad_x;
	filter2D(C, grad_x, -1, kernel, Point(-1, -1), 0, BORDER_DEFAULT);

	Mat kernel2 = (Mat_(3, 1) << -1, 0, 1);
	Mat grad_y;
	filter2D(C, grad_y, -1, kernel2, Point(-1, -1), 0, BORDER_DEFAULT);

	magnitude(grad_x, grad_y, _gradient_magnitude);
}
	// 	Mat gradient_magnitude = Mat_(tempC.size());
	// 	get_gradient_magnitude(tempC, gradient_magnitude);
	// 	gradient_magnitude.convertTo(gradient_magnitude, CV_8UC1);
	// 	//channels.push_back(gradient_magnitude);
	// 	imshow("gradient_magnitude", gradient_magnitude);


 
  

你可能感兴趣的:(opencv)