Skip to content

Losing last mat row and column during remap() with BORDER_TRANSPARENT #23562

@momasthagnum

Description

@momasthagnum

System Information

OpenCV python version: 4.7.0
Operating System / Platform: Windows 11
Python revision: 3.10.8

Detailed description

[EDIT: unquoted relevant part of my question..]

Hi,

first off thanks for the great work you guys are doing!
I'll try and break this down with the attached python snippet.

The docs say

When borderMode=BORDER_TRANSPARENT, it means that the pixels in the destination image that corresponds to the "outliers" in the source image are not modified by the function.

and sadly I cannot seem to find much more on this anywhere, so I may be using it wrong. In that case apologies for creating this issue. But my understanding is that in the example code, this should lead to pixels in the destination staying black when trying to map to a pixel in the source that doesn't exist (e.g. 20). However, in the example, all pixels in the mapping mats exist in the source, but still, the last row and column in the destination always remain 0 when using BORDER_TRANSPARENT. It works as expected with BORDER_CONSTANT:

BORDER_CONSTANT
grafik

BORDER_TRANSPARENT
grafik

Steps to reproduce

bgImage = np.zeros((8, 12, 1), dtype=np.float32)

source = np.array([[0.1, 0.2, 0.3],
                   [0.5, 0.6, 0.7],
                   [0.9, 1.0, 0.9]], dtype=np.float32).reshape(3, 3, 1)

imageSize = bgImage.shape[1], bgImage.shape[0]

map1 = np.array([[0, 1, 2],
                 [0, 1, 2],
                 [0, 1, 2]], dtype=np.float32)

map2 = np.array([[0, 0, 0],
                 [1, 1, 1],
                 [2, 2, 2]], dtype=np.float32)

destination = np.zeros((3, 3, 1), dtype=np.float32)

cv2.remap(source,
          map1,
          map2,
          interpolation=cv2.INTER_LINEAR,
          dst=destination,
          borderMode=cv2.BORDER_TRANSPARENT)

result = bgImage.copy()
result[2:2+3, 2:2+3] = destination
upscaledImage = cv2.resize(result, np.array([1200, 800]), interpolation=cv2.INTER_NEAREST)

cv2.imshow("test", upscaledImage)
cv2.waitKey(0)
cv2.destroyAllWindows()

Issue submission checklist

  • I report the issue, it's not a question
  • I checked the problem with documentation, FAQ, open issues, forum.opencv.org, Stack Overflow, etc and have not found any solution
  • I updated to the latest OpenCV version and the issue is still there
  • There is reproducer code and related data files (videos, images, onnx, etc)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions