CLAHE is not consistent with variable image size (Bug #3320)
Description
I am updating the CLAHE operator to work with 16-bit single channel imagery. In the process I have been digging into how this operator works. I believe the CLAHE operator will not produce consistent results with varying image sizes. This is due to the fact that the variables clipLimit and lutScale are calculated dependent upon source image size.
if (src.cols % tilesX_ == 0 && src.rows % tilesY_ == 0) { tileSize = cv::Size(src.cols / tilesX_, src.rows / tilesY_); srcForLut = src; } else { cv::copyMakeBorder(src, srcExt_, 0, tilesY_ - (src.rows % tilesY_), 0, tilesX_ - (src.cols % tilesX_), cv::BORDER_REFLECT_101); tileSize = cv::Size(srcExt_.cols / tilesX_, srcExt_.rows / tilesY_); srcForLut = srcExt_; } const int tileSizeTotal = tileSize.area(); const float lutScale = static_cast<float>(histSize - 1) / tileSizeTotal; int clipLimit = 0; if (clipLimit_ > 0.0) { clipLimit = static_cast<int>(clipLimit_ * tileSizeTotal / histSize); clipLimit = std::max(clipLimit, 1); }
Associated revisions
Merge pull request #3320 from ElenaGvozdeva:gemm_doc
History
Updated by Maria Dimashova over 11 years ago
Thanks for the report!
Could you please suggest the changes to get consistent results with varying image sizes and create the pull request here?
- Assignee set to Vadim Pisarevsky
- Category set to imgproc, video
Updated by Todd Pepper over 11 years ago
I am looking into this now. It may not be a bug if alternate modes of operation are also supported. I am reading other implementations to get an idea of the expected behavior.
Updated by Todd Pepper over 11 years ago
I do not believe this to be a bug. CLAHE is more of a concept without a real specification for implementation. This implementation is sufficient but it should be noted that the input variable clip_limit is not really the clip limit defined in CLAHE as it is adjusted per the image size. The CLAHE filter takes in a tile size parameter which does not specify the size of tiles for operation but instead the number of tiles to chop the image into. With varying image sizes the actual ROI of operation will change in size resulting in a different behavior for the same clip_limit value.
- Status changed from Open to Cancelled