0

I am trying to do a transform of a RGB image using cv::remap so that the empty space is extrapolated by the average intensity:

cv::Mat mapX(sz, CV_32FC1), mapY(sz, CV_32FC1);
// filling maps
cv::remap(src, dst, mapX, mapY, cv::INTER_LINEAR, cv::BORDER_CONSTANT, cv::mean(src));

The output is a transformed image, but the empty space is filled with the intensity value in first row/column of the corresponding column/row because the default value for the last parameter of cv::remap is 0.

Example: enter image description here

If I do this (rotate):

cv::warpAffine(src, dst, rotationMatrix, bbox.size(), cv::INTER_LINEAR, cv::BORDER_CONSTANT, cv::mean(src));

I get correct output: enter image description here

How can I specify a constant color everywhere?

Egor
  • 107
  • 1
  • 8
  • 1
    The problem is in the way you are building `mapX` and `mapY`... The problem is in part of the code you are not sowing us: `// filling maps`. I think the coordinates that suppose to be outside the borders (in your code) are clipped to range `0`,`0` and `cols`,`rows` instead of getting negative values, and values above `cols` and rows`. – Rotem May 01 '21 at 08:29
  • @Rotem You are right, I added `-1.f` to the constructor of `cv::Mat` and everything worked as it should – Egor May 01 '21 at 12:19

0 Answers0