hi
i am trying to find a way to sharpen a rgb image, which i get from the video grabber.
i used opencv blur before but there seems to be no direct sharpen function.
i found this code, that sharpens a greyscale image.
i am now trying to either split my rgb image in to its 3 separate channels.
this could do done by looping through all the pixel, but is probably too performance heavy.
or i find a way to re-write the following code to work with a 3 channel image.
any ideas?
thanks, stephan.
void testApp::doGraySharpening(IplImage* img ) {
//[http://permalink.gmane.org/gmane.comp.lib.opencv/35015](http://permalink.gmane.org/gmane.comp.lib.opencv/35015)
int w = img->width;
int h = img->height;
IplImage* gray2 = cvCreateImage( cvGetSize(img) , 32, 1 );
cvConvertScale( img, gray2, 1.0 );
IplImage* lapl = cvCreateImage( cvGetSize(img) , 32, 1 );
CvMat* ker = cvCreateMat( 3, 3, CV_32FC1);
cvSet( ker, cvScalarAll( -1.0 ) );
cvSet2D( ker, 1, 1, cvScalarAll( 15.0 ) );
cvFilter2D( gray2, lapl, ker );
cvReleaseMat( &ker );
double maxv = 0.0;
double minv = DBL_MAX;
cvMinMaxLoc( lapl, &minv, &maxv );
for( int i=0; i<w*h; i++ )
{
double lap_val = cvGet1D( lapl, i ).val[0];
int v = (int)( (255.0*lap_val/ maxv) +0.5);
cvSet1D( img, i, cvScalarAll( v) );
}
maxv = 0.0;
cvMinMaxLoc( img, &minv, &maxv );
for( int i=0; i<w*h; i++ )
{
double val = cvGet1D( img, i ).val[0];
int v = (int)( (255.0*val/maxv) + 0.5);
cvSet1D( img, i, cvScalarAll( v) );
}
cvReleaseImage( &gray2 );
}