In general, sum of magnitude of image shows focus fluctuations (smoothness).In special case, you can check the zero crossing in specific points of image.
For more accurate value for smoothness compute FFT for image then you can survey the high pass frequency of image.
C:
double calcGradients(const IplImage*src,intaperture_size=7)
{
CvSize sz=cvGetSize(src);
IplImage*img16_x=cvCreateImage(sz,IPL_DEPTH_16S,1);
IplImage*img16_y=cvCreateImage(sz,IPL_DEPTH_16S,1);
cvSobel(src,img16_x,1,0,aperture_size);
cvSobel(src,img16_y,0,1,aperture_size);
IplImage*imgF_x=cvCreateImage(sz,IPL_DEPTH_32F,1);
IplImage*imgF_y=cvCreateImage(sz,IPL_DEPTH_32F,1);
cvScale(img16_x,imgF_x);
cvScale(img16_y,imgF_y);
IplImage*magnitude=cvCreateImage(sz,IPL_DEPTH_32F,1);
cvCartToPolar(imgF_x,imgF_y,magnitude);
double res=cvSum(magnitude).val[0];
cvReleaseImage(&magnitude);
cvReleaseImage(&imgF_x);
cvReleaseImage(&imgF_y);
cvReleaseImage(&img16_x);
cvReleaseImage(&img16_y);
return
res;
}
C++:
double contrast_measure( const Mat&img )
{
Mat dx, dy;
Sobel( img, dx, CV_32F, 1, 0, 3 );
Sobel( img, dy, CV_32F, 0, 1, 3 );
magnitude( dx, dy, dx );
return sum(dx)[0];
}