forked from opencv/opencv
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request opencv#1758 from apavlenko:adaptive_bilateral_filter
- Loading branch information
Showing
9 changed files
with
173 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ | |
// Zero Lin, [email protected] | ||
// Zhang Ying, [email protected] | ||
// Yao Wang, [email protected] | ||
// Harris Gasparakis, [email protected] | ||
// | ||
// Redistribution and use in source and binary forms, with or without modification, | ||
// are permitted provided that the following conditions are met: | ||
|
@@ -1407,7 +1408,7 @@ void cv::ocl::GaussianBlur(const oclMat &src, oclMat &dst, Size ksize, double si | |
//////////////////////////////////////////////////////////////////////////////////////////////////// | ||
// Adaptive Bilateral Filter | ||
|
||
void cv::ocl::adaptiveBilateralFilter(const oclMat& src, oclMat& dst, Size ksize, double sigmaSpace, Point anchor, int borderType) | ||
void cv::ocl::adaptiveBilateralFilter(const oclMat& src, oclMat& dst, Size ksize, double sigmaSpace, double maxSigmaColor, Point anchor, int borderType) | ||
{ | ||
CV_Assert((ksize.width & 1) && (ksize.height & 1)); // ksize must be odd | ||
CV_Assert(src.type() == CV_8UC1 || src.type() == CV_8UC3); // source must be 8bit RGB image | ||
|
@@ -1418,18 +1419,32 @@ void cv::ocl::adaptiveBilateralFilter(const oclMat& src, oclMat& dst, Size ksize | |
int idx = 0; | ||
int w = ksize.width / 2; | ||
int h = ksize.height / 2; | ||
for(int y=-h; y<=h; y++) | ||
for(int x=-w; x<=w; x++) | ||
|
||
int ABF_GAUSSIAN_ocl = 1; | ||
|
||
if(ABF_GAUSSIAN_ocl) | ||
{ | ||
lut.at<float>(idx++) = sigma2 / (sigma2 + x * x + y * y); | ||
for(int y=-h; y<=h; y++) | ||
for(int x=-w; x<=w; x++) | ||
{ | ||
lut.at<float>(idx++) = expf( (float)(-0.5 * (x * x + y * y)/sigma2)); | ||
} | ||
} | ||
else | ||
{ | ||
for(int y=-h; y<=h; y++) | ||
for(int x=-w; x<=w; x++) | ||
{ | ||
lut.at<float>(idx++) = (float) (sigma2 / (sigma2 + x * x + y * y)); | ||
} | ||
} | ||
|
||
oclMat dlut(lut); | ||
int depth = src.depth(); | ||
int cn = src.oclchannels(); | ||
|
||
normalizeAnchor(anchor, ksize); | ||
const static String kernelName = "edgeEnhancingFilter"; | ||
const static String kernelName = "adaptiveBilateralFilter"; | ||
|
||
dst.create(src.size(), src.type()); | ||
|
||
|
@@ -1478,9 +1493,10 @@ void cv::ocl::adaptiveBilateralFilter(const oclMat& src, oclMat& dst, Size ksize | |
|
||
//LDATATYPESIZE is sizeof local data store. This is to exemplify effect of LDS on kernel performance | ||
sprintf(build_options, | ||
"-D VAR_PER_CHANNEL=1 -D CALCVAR=1 -D FIXED_WEIGHT=0 -D EXTRA=%d" | ||
"-D VAR_PER_CHANNEL=1 -D CALCVAR=1 -D FIXED_WEIGHT=0 -D EXTRA=%d -D MAX_VAR_VAL=%f -D ABF_GAUSSIAN=%d" | ||
" -D THREADS=%d -D anX=%d -D anY=%d -D ksX=%d -D ksY=%d -D %s", | ||
static_cast<int>(EXTRA), static_cast<int>(blockSizeX), anchor.x, anchor.y, ksize.width, ksize.height, btype); | ||
static_cast<int>(EXTRA), static_cast<float>(maxSigmaColor*maxSigmaColor), static_cast<int>(ABF_GAUSSIAN_ocl), | ||
static_cast<int>(blockSizeX), anchor.x, anchor.y, ksize.width, ksize.height, btype); | ||
|
||
std::vector<pair<size_t , const void *> > args; | ||
args.push_back(std::make_pair(sizeof(cl_mem), &src.data)); | ||
|
Oops, something went wrong.