mirror of
https://github.com/opencv/opencv.git
synced 2025-07-25 22:57:53 +08:00
Merge pull request #7538 from Tetragramm:CLAHEfix
This commit is contained in:
commit
c47267ef7f
@ -212,8 +212,12 @@ namespace
|
|||||||
for (int i = 0; i < histSize; ++i)
|
for (int i = 0; i < histSize; ++i)
|
||||||
tileHist[i] += redistBatch;
|
tileHist[i] += redistBatch;
|
||||||
|
|
||||||
for (int i = 0; i < residual; ++i)
|
if (residual != 0)
|
||||||
tileHist[i]++;
|
{
|
||||||
|
int residualStep = MAX(histSize / residual, 1);
|
||||||
|
for (int i = 0; i < histSize && residual > 0; i += residualStep, residual--)
|
||||||
|
tileHist[i]++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// calc Lut
|
// calc Lut
|
||||||
@ -359,7 +363,7 @@ namespace
|
|||||||
bool useOpenCL = cv::ocl::useOpenCL() && _src.isUMat() && _src.dims()<=2 && _src.type() == CV_8UC1;
|
bool useOpenCL = cv::ocl::useOpenCL() && _src.isUMat() && _src.dims()<=2 && _src.type() == CV_8UC1;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int histSize = _src.type() == CV_8UC1 ? 256 : 4096;
|
int histSize = _src.type() == CV_8UC1 ? 256 : 65536;
|
||||||
|
|
||||||
cv::Size tileSize;
|
cv::Size tileSize;
|
||||||
cv::_InputArray _srcForLut;
|
cv::_InputArray _srcForLut;
|
||||||
@ -416,7 +420,7 @@ namespace
|
|||||||
if (_src.type() == CV_8UC1)
|
if (_src.type() == CV_8UC1)
|
||||||
calcLutBody = cv::makePtr<CLAHE_CalcLut_Body<uchar, 256, 0> >(srcForLut, lut_, tileSize, tilesX_, clipLimit, lutScale);
|
calcLutBody = cv::makePtr<CLAHE_CalcLut_Body<uchar, 256, 0> >(srcForLut, lut_, tileSize, tilesX_, clipLimit, lutScale);
|
||||||
else if (_src.type() == CV_16UC1)
|
else if (_src.type() == CV_16UC1)
|
||||||
calcLutBody = cv::makePtr<CLAHE_CalcLut_Body<ushort, 4096, 4> >(srcForLut, lut_, tileSize, tilesX_, clipLimit, lutScale);
|
calcLutBody = cv::makePtr<CLAHE_CalcLut_Body<ushort, 65536, 0> >(srcForLut, lut_, tileSize, tilesX_, clipLimit, lutScale);
|
||||||
else
|
else
|
||||||
CV_Error( CV_StsBadArg, "Unsupported type" );
|
CV_Error( CV_StsBadArg, "Unsupported type" );
|
||||||
|
|
||||||
@ -426,7 +430,7 @@ namespace
|
|||||||
if (_src.type() == CV_8UC1)
|
if (_src.type() == CV_8UC1)
|
||||||
interpolationBody = cv::makePtr<CLAHE_Interpolation_Body<uchar, 0> >(src, dst, lut_, tileSize, tilesX_, tilesY_);
|
interpolationBody = cv::makePtr<CLAHE_Interpolation_Body<uchar, 0> >(src, dst, lut_, tileSize, tilesX_, tilesY_);
|
||||||
else if (_src.type() == CV_16UC1)
|
else if (_src.type() == CV_16UC1)
|
||||||
interpolationBody = cv::makePtr<CLAHE_Interpolation_Body<ushort, 4> >(src, dst, lut_, tileSize, tilesX_, tilesY_);
|
interpolationBody = cv::makePtr<CLAHE_Interpolation_Body<ushort, 0> >(src, dst, lut_, tileSize, tilesX_, tilesY_);
|
||||||
|
|
||||||
cv::parallel_for_(cv::Range(0, src.rows), *interpolationBody);
|
cv::parallel_for_(cv::Range(0, src.rows), *interpolationBody);
|
||||||
}
|
}
|
||||||
|
@ -201,7 +201,10 @@ __kernel void calcLut(__global __const uchar * src, const int srcStep,
|
|||||||
tHistVal += redistBatch;
|
tHistVal += redistBatch;
|
||||||
|
|
||||||
int residual = totalClipped - redistBatch * 256;
|
int residual = totalClipped - redistBatch * 256;
|
||||||
if (tid < residual)
|
int rStep = 256 / residual;
|
||||||
|
if (rStep < 1)
|
||||||
|
rStep = 1;
|
||||||
|
if (tid%rStep == 0 && (tid/rStep)<residual)
|
||||||
++tHistVal;
|
++tHistVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user