int main(){ Mat sar = imread("leap.jpg" , 1) ; namedWindow("leap") ; imshow("leap" , sar) ; waitKey(0) ; GaussianBlur(sar , sar , Size(3 , 3) , 0 , 0 , BORDER_DEFAULT) ; namedWindow("gauss") ; imshow("gauss" , sar) ; waitKey(0) ; Mat sar_grad ; cvtColor( sar , sar_grad , CV_RGB2GRAY ) ; namedWindow("grad") ; imshow("grad" , sar_grad) ; waitKey(0) ; int scale = 1 , delta = 0 , ddepth = CV_16S ; Mat grad_x , grad_y ; Sobel( sar_grad , grad_x , ddepth , 1 , 0 , 3 , scale , delta , BORDER_DEFAULT) ; Sobel( sar_grad , grad_y , ddepth , 0 , 1 , 3 , scale , delta , BORDER_DEFAULT) ; Mat abs_grad_x , abs_grad_y ; convertScaleAbs( grad_x , abs_grad_x) ; convertScaleAbs( grad_y , abs_grad_y) ; Mat ans ; addWeighted( abs_grad_x , 0.5 , abs_grad_y , 0.5 , 0 , ans) ; namedWindow("soble") ; imshow("soble" , ans) ; waitKey(0) ; cout<< ans.rows<< " " << ans.cols << endl ; //freopen("data.txt" , "w" , stdout) ; int n = 0 ; for(int i = 0 ; i < ans.rows ; i++){ for(int j = 0 ; j < ans.cols ; j++) { if( ans.at<uchar>(i , j) != 0 ) n++ ; } } cout<< n << endl ; system("pause") ; return 0 ; }