Opencv_contrib: weightedMedianFilter hangs with some input images

Created on 14 Apr 2018  Â·  5Comments  Â·  Source: opencv/opencv_contrib

System information (version)
  • OpenCV => 3.4.1-312-g7e5581c
  • opencv_contrib => 3.4.1-70-g2aaa67a
  • Operating System / Platform => GNU/Linux x86_64 (Linux Mint 18.3 Sylvia)
  • Compiler => gcc 5.4.0 20160609
Detailed description

The weightedMedianFilter () sometimes hangs with some particular input images.
The hang seems not depend on particular parameters (sigma, radius, weight type or mask image) as well as on joint image, but just on input image content.

It works fine with total majority of input images but fails with some particulars.

Steps to reproduce

Attached is an example of 16-bit single-channel grayscale png image (uint16_t), which causes weightedMedianFilter() hangup . The image was converted to CV_32FC1 before passing to weightedMedianFilter().

If I change pixel values in this image in a some way (for example convert the image to 8 bit, make some brighness/contrast stretch, etc) then no hangups happened.

ss-2 003

The outline of code example is below:

```.cpp

 // C++ code example
 Mat input_image = cv::imread("ss-2.003.png", IMREAD_UNCHANGED);

 input_image.convertTo(input_image, CV_32F);

 weightedMedianFilter(Mat::ones(input_image.size(), CV_8U),
    input_image, output_image, raduis, sigma,  WMF_OFF);

 // No return: hang up inside of weightedMedianFilter()

```

Attached is complete code exampe to reproduce.
weightedMedianFilter-hangup.tar.gz

Just unpack, make and run:
$ ./weightedMedianFilter-hangup ss-2.003.png

Will see 100% cpu load with no return.

bug ximgproc

All 5 comments

i could reproduce it, the problem is here:
https://github.com/opencv/opencv_contrib/blob/2aaa67a67abd6ca4437465a8c8467a22e1378732/modules/ximgproc/src/weighted_median_filter.cpp#L79-L100

with your example image, (r-l) reaches a final value of 0.000015 in iteration ~25 , and stops decreasing.

The example image I attached above is not unique problematic image, I can attach more examples if need.

@amyznikov Could you check this patch: #1613 ?

BTW, the most part of OpenCV algorithms expect 32F(64F) images within range 0..1.
So It is better to use something like this:

-input_image.convertTo(input_image, CV_32F);
+input_image.convertTo(input_image, CV_32F, 1.0f/65535.0f);  // CV_16U only

Hi @alalek , sorry for delay with responce,

I tested the patch #1613 on 200 potentially problematic images I have, everything works fine now, no hangups happened.

Thank you a lot!

i think, this can be closed, now.

(unfortunately, since we submit pr's to 3.4, it can no more be closed automatically)

Was this page helpful?
0 / 5 - 0 ratings