opencv-python icon indicating copy to clipboard operation
opencv-python copied to clipboard

[Feature request] Make cv2.warpAffine work with image with any number of channels

Open ternaus opened this issue 10 months ago • 2 comments

Describe the feature and motivation

Currently cv2.warpAffine supports only 1, 3 and 4 channels images, while for problems of medical or satellite imagery we may have any. Would be great to add support for any number of channels.

ternaus avatar Feb 22 '25 17:02 ternaus

@ternaus Hi, I would like to work on this issue. Is it possible de have more details please ?

samybali avatar Mar 26 '25 09:03 samybali

   ...: import cv2
   ...: import numpy as np
   ...: from matplotlib import pyplot as plt
   ...:
   ...:
   ...:
   ...: rows, cols, ch = 256, 256, 11
   ...:
   ...: img = np.random.randint(0, 255, size=(rows, cols, ch))
   ...:
   ...: pts1 = np.float32([[50, 50],
   ...:                    [200, 50],
   ...:                    [50, 200]])
   ...:
   ...: pts2 = np.float32([[10, 100],
   ...:                    [200, 50],
   ...:                    [100, 250]])
   ...:
   ...: M = cv2.getAffineTransform(pts1, pts2)
   ...: dst = cv2.warpAffine(img, M, (cols, rows))
---------------------------------------------------------------------------
error                                     Traceback (most recent call last)
Cell In[2], line 20
     15 pts2 = np.float32([[10, 100],
     16                    [200, 50],
     17                    [100, 250]])
     19 M = cv2.getAffineTransform(pts1, pts2)
---> 20 dst = cv2.warpAffine(img, M, (cols, rows))

error: OpenCV(4.11.0) /Users/xperience/GHA-Actions-OpenCV/_work/opencv-python/opencv-python/opencv/modules/imgproc/src/imgwarp.cpp:1897: error: (-215:Assertion failed) ifunc != 0 in function 'remap'

@samybali and if you ch as 1, 3, or 4 it works

ternaus avatar Mar 26 '25 17:03 ternaus