Bug in cvCopyMakeBorder(...BORDER_REFLECT_101) (Feature #748)


Added by Tomas Kazmar over 14 years ago. Updated about 14 years ago.


Status:Done Start date:
Priority:High Due date:
Assignee:Vadim Pisarevsky % Done:

0%

Category:imgproc, video
Target version:-
Difficulty: Pull request:

Description

When padding an image (cv::Mat_<float>) using a call to cvCopyMakeBorder with REFLECT_101 as border type, the added top and bottom rows of the image are not set correctly. Actually what happens is that source and destination pointers are switched so that when copying the data the uninitialized border overwrites the inner part of the image.

Sample code:
typedef int ValueType;
cv::Mat_<ValueType> image = cv::Mat_<ValueType>::zeros(3, 3);
int padding = 2;
cv::Mat_<ValueType> padded =
cv::Mat_<ValueType>::ones(image.rows + 2*padding, image.cols + 2*padding);
cv::copyMakeBorder(image, padded,
padding, padding, padding, padding,
cv::BORDER_REFLECT_101);

Resulting images:

image:
[
0 0 0
0 0 0
0 0 0
]
padded:
[
1 1 1 1 1 1 1
1 1 1 1 1 1 1
1 1 1 1 1 1 1
1 1 1 1 1 1 1
0 0 0 0 0 0 0
1 1 1 1 1 1 1
1 1 1 1 1 1 1
]

But one expects:
padded:
[
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
]

This affects matrices of all types (uchars, ints, floats...).

Tested with both OpenCV 2.1 and 2.2 and there is the bug in both.

A patch is attached.


imgproc_src_utils.cpp.patch - patch (1.1 kB) Tomas Kazmar, 2010-12-09 06:03 pm


Associated revisions

Revision a2d89ace
Added by Andrey Kamaev almost 12 years ago

Merge pull request #748 from asmorkalov:android_na_install_fix

History

Updated by Vadim Pisarevsky about 14 years ago

thank you for the patch! I decided to completely rewrite the function to simplify the logic and add support for other border modes. Your sample, as well as some other test cases, now work fine. Please, check the revision r4339

  • Status changed from Open to Done
  • (deleted custom field) set to fixed

Updated by Tomas Kazmar about 14 years ago

Thank you for the quick answer and for cleaning up the code as the previous state was really a little bit messy...

Updated by Vadim Pisarevsky about 14 years ago

looks like copyMakeBorder in r4339 has some bugs; fixed in r4353.

Also available in: Atom PDF