1 | initial version |
test code for the function contrast_measure
#include "opencv2/imgproc.hpp"
#include "opencv2/highgui.hpp"
#include "iostream"
using namespace cv;
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];
}
int main( int argc, char** argv )
{
char* filename = argc >= 2 ? argv[1] : (char*)"lena.jpg";
Mat src = imread( filename );
if(src.data)
{
std::cout << "original image : " << contrast_measure( src ) / 1e3 << std::endl;
for( int i =3; i < 80; i+=2 )
{
Mat blurred;
GaussianBlur( src, blurred, Size(i,i), 0);
imshow( "blurred image", blurred );
waitKey(200);
std::cout << "blurred image : " << contrast_measure( blurred ) / 1e3 << std::endl;
}
}
return 0;
}
resuts :
original image : 11776.9
blurred image : 8875.25
blurred image : 7615.93
blurred image : 6441.79
blurred image : 5861.6
blurred image : 5255.5
blurred image : 4961.99
blurred image : 4524.56
blurred image : 4291.87
blurred image : 4021.77
blurred image : 3822.97
blurred image : 3622.91
blurred image : 3521.31
blurred image : 3320.35
blurred image : 3181.87
blurred image : 3105.9
blurred image : 2952.72
blurred image : 2878.29
blurred image : 2751.65
blurred image : 2689.6
blurred image : 2670.44
blurred image : 2539.05
.
.
2 | No.2 Revision |
test code for the function
which is an undocumented OpenCV functioncontrast_measurecalcBlurriness
#include "opencv2/imgproc.hpp"
#include "opencv2/highgui.hpp"
#include "iostream"
using namespace cv;
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];
}
int main( int argc, char** argv )
{
char* filename = argc >= 2 ? argv[1] : (char*)"lena.jpg";
Mat src = imread( filename );
if(src.data)
{
std::cout << "original image : " << contrast_measure( src ) / 1e3 << std::endl;
for( int i =3; i < 80; i+=2 )
{
Mat blurred;
GaussianBlur( src, blurred, Size(i,i), 0);
imshow( "blurred image", blurred );
waitKey(200);
std::cout << "blurred image : " << contrast_measure( blurred ) / 1e3 << std::endl;
}
}
return 0;
}
resuts : ( the lesser value means more sharpness )
original image : 11776.9
blurred image : 8875.25
blurred image : 7615.93
blurred image : 6441.79
blurred image : 5861.6
blurred image : 5255.5
blurred image : 4961.99
blurred image : 4524.56
blurred image : 4291.87
blurred image : 4021.77
blurred image : 3822.97
blurred image : 3622.91
blurred image : 3521.31
blurred image : 3320.35
blurred image : 3181.87
blurred image : 3105.9
blurred image : 2952.72
blurred image : 2878.29
blurred image : 2751.65
blurred image : 2689.6
blurred image : 2670.44
blurred image : 2539.05
4.97583e-005
blurred image : 7.70266e-005
blurred image : 9.97529e-005
blurred image : 0.000134977
blurred image : 0.000161698
blurred image : 0.00020089
blurred image : 0.000226519
blurred image : 0.000275304
blurred image : 0.00030933
blurred image : 0.000356515
blurred image : 0.000399192
blurred image : 0.000450388
blurred image : 0.000483238
blurred image : 0.00054965
blurred image : 0.000603829
blurred image : 0.000645158
blurred image : 0.00071919
blurred image : 0.000767566
blurred image : 0.000847372
blurred image : 0.000895128
blurred image : 0.000917833
blurred image : 0.00102065
blurred image : 0.00113219
.
.
3 | No.3 Revision |
test code for the function calcBlurriness
which is an undocumented OpenCV function
#include "opencv2/imgproc.hpp"
#include "opencv2/highgui.hpp"
#include "iostream"
using namespace cv;
double contrast_measure( float calcBlurriness( const Mat&img Mat &src )
{
Mat dx, dy;
Gx, Gy;
Sobel( img, dx, src, Gx, CV_32F, 1, 0, 3 0 );
Sobel( img, dy, src, Gy, CV_32F, 0, 1, 3 );
magnitude( dx, dy, dx );
1 );
double normGx = norm( Gx );
double normGy = norm( Gy );
double sumSq = normGx * normGx + normGy * normGy;
return sum(dx)[0];
static_cast<float>( 1. / ( sumSq / src.size().area() + 1e-6 ));
}
int main( int argc, char** argv )
{
char* filename = argc >= 2 ? argv[1] : (char*)"lena.jpg";
Mat src = imread( filename );
if(src.data)
{
std::cout << "original image : " << contrast_measure( calcBlurriness( src ) / 1e3 << std::endl;
for( int i =3; i < 80; i+=2 )
{
Mat blurred;
GaussianBlur( src, blurred, Size(i,i), 0);
imshow( "blurred image", blurred );
waitKey(200);
std::cout << "blurred image : " << contrast_measure( calcBlurriness( blurred ) / 1e3 << std::endl;
}
}
return 0;
}
resuts : ( the lesser value means more sharpness )
original image : 4.97583e-005
blurred image : 7.70266e-005
blurred image : 9.97529e-005
blurred image : 0.000134977
blurred image : 0.000161698
blurred image : 0.00020089
blurred image : 0.000226519
blurred image : 0.000275304
blurred image : 0.00030933
blurred image : 0.000356515
blurred image : 0.000399192
blurred image : 0.000450388
blurred image : 0.000483238
blurred image : 0.00054965
blurred image : 0.000603829
blurred image : 0.000645158
blurred image : 0.00071919
blurred image : 0.000767566
blurred image : 0.000847372
blurred image : 0.000895128
blurred image : 0.000917833
blurred image : 0.00102065
blurred image : 0.00113219
.
.