Try to search your question here, if you can't find : Ask Any Question Now ?

OpenCV merge failing to merge image channel

HomeCategory: stackoverflowOpenCV merge failing to merge image channel
Avatarrupesh asked 2 weeks ago

I’m attempting to add Gaussian noise to a single channel of an image.

import cv2 as cv
import numpy as np

img1 = cv.imread('input/foo.png')
img1_blue, img1_green, img1_red = cv.split(img1)
img1_h, img1_w, _ = img1.shape

s = 5
noise = np.random.normal(0, s, (img1_h, img1_w))
img1_gn = img1_green + noise

print(img1_green.shape) # (512, 384)
print(img1_gn.shape)    # (512, 384)
print(img1_blue.shape)  # (512, 384)

img1_g_noise = cv.merge((img1_blue, img1_gn, img1_red))

This results in the following error:

---------------------------------------------------------------------------
error                                     Traceback (most recent call last)
<ipython-input-34-049cf9e65133> in <module>
     13 
---> 14 img1_g_noise = cv.merge((img1_blue, img1_gn, img1_red))
     15 

error: OpenCV(3.4.5) /io/opencv/modules/core/src/merge.cpp:293: error: (-215:Assertion failed) mv[i].size == mv[0].size && mv[i].depth() == depth in function 'merge'

I’m not sure how or why this is happening. The resulting noisy green channel has the same dimensions and type as the other two channels. Recombining the original green channel works just fine. Any steering direction is appreciated, and thank you in advance.

1 Answers
Best Answer
AvatarJyoti answered 2 weeks ago
Your Answer

0 + 19 =

Popular Tags

WP Facebook Auto Publish Powered By : XYZScripts.com