You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
OpenCV python version: 4.5.3 and 4.8.1 and 4.9.0
Operating System / Platform: Ubuntu 20.04 and windows 10
Python version: 3.9
Detailed description
The cv.multiply() function exhibits inconsistent and unexpected behavior when processing color images in OpenCV versions 4.5 to 4.8 compared to version 4.9. Specifically:
When using an integer as the multiplier, versions 4.5 to 4.8 only the blue channel is correctly multiplied by 2.0, while the green and red channels' pixel values become zero.
When using a one-dimensional NumPy array (np.array([2.0])) as the multiplier, versions 4.5 to 4.8 correctly multiply all channels (BGR) of the image by the given value. However, in OpenCV 4.9, only the blue channel is correctly multiplied, while the green and red channels' pixel values are set to zero.
These anomalies deviate from users' reasonable expectations for the cv.multiply() function, potentially leading to incorrect results or difficult-to-debug issues in applications.
Steps to reproduce
Sample Code
import cv2 as cv
import numpy as np
# Create a color image
gray_img = np.zeros((400, 400, 3), dtype=np.uint8)
gray_img[:, :, 0] = 50 # B
gray_img[:, :, 1] = 50 # G
gray_img[:, :, 2] = 50 # R
# Use an integer as the multiplier
tmp_img_int = cv.multiply(gray_img, 2)
# Use a one-dimensional NumPy array as the multiplier
tmp_img_array = cv.multiply(gray_img, np.array([2.0]))
# Output results
print(tmp_img_int[:2, :2])
print(tmp_img_array[:2, :2])
Expected Result
1 For both integer and one-dimensional NumPy array multipliers, the cv.multiply() function should correctly multiply all channels (BGR) of the color image by the specified value, regardless of the OpenCV version.
Umm, I read again. This behavious has been changed after 4.9.0, but I think OpenCV 4.9.0 behavious is correct
( More precisely, the case where src2 is Scalar is not described in the multiply function... )
When using an integer as the multiplier, versions 4.5 to 4.8 only the blue channel is correctly multiplied by 2.0, while the green and red channels' pixel values become zero.
When using a one-dimensional NumPy array (np.array([2.0])) as the multiplier, versions 4.5 to 4.8 correctly multiply all channels (BGR) of the image by the given value. However, in OpenCV 4.9, only the blue channel is correctly multiplied, while the green and red channels' pixel values are set to zero.
Note
Saturation is not applied when the output array has the depth CV_32S. You may even get result of an incorrect sign in the case of overflow.
(Python) Be careful to difference behaviour between src1/src2 are single number and they are tuple/array. multiply(src,X) means multiply(src,(X,X,X,X)). multiply(src,(X,)) means multiply(src,(X,0,0,0)).
System Information
OpenCV python version: 4.5.3 and 4.8.1 and 4.9.0
Operating System / Platform: Ubuntu 20.04 and windows 10
Python version: 3.9
Detailed description
The cv.multiply() function exhibits inconsistent and unexpected behavior when processing color images in OpenCV versions 4.5 to 4.8 compared to version 4.9. Specifically:
These anomalies deviate from users' reasonable expectations for the cv.multiply() function, potentially leading to incorrect results or difficult-to-debug issues in applications.
Steps to reproduce
Sample Code
Expected Result
1 For both integer and one-dimensional NumPy array multipliers, the cv.multiply() function should correctly multiply all channels (BGR) of the color image by the specified value, regardless of the OpenCV version.
Actual Result
OpenCV versions 4.5 to 4.8:
OpenCV version 4.9:
Reproduction Steps
Issue submission checklist
The text was updated successfully, but these errors were encountered: