Skip to content

OpenCV 4.5.2 GaussianBlur not working properly with UInt16 image type #20121

@tintifax89

Description

@tintifax89
System information (version)
  • OpenCV => 4.5.2
  • Operating System / Platform => Linux 64 Bit and OS X 64 Bit
  • Compiler => clang
Detailed description

When performing cv::GaussianBlur() on an image of type CV_16UC1, it seems that all values above uint16::max/2 are clipped to uint16::max/2. When performing the gaussian blur using cv::getGaussianKernel() combined with cv::filter2D it works fine. The same problem was definitely not there when using OpenCV version 4.2.0. Running the cv::GaussianBlur() in-place or not doesn't make a difference. Probably internally at some point the pixel values are casted to a signed 16 bit integer and therefore are clipped to 32768.

Steps to reproduce
  cv::Mat img(100, 100, CV_16UC1);
  img = cv::Scalar(std::numeric_limits<uint16_t>::max());
  cv::imwrite(basePath + "gaussianDebugOriginal.png", img);
  cv::GaussianBlur(img, img, cv::Size(9, 9), 0.0);
  cv::imwrite(basePath + "gaussianDebugBlurred.png", img);

gaussianDebugBlurred.png:
gaussianDebugBlurred

gaussianDebugOriginal.png:
gaussianDebugOriginal

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions