Ask Your Question
1

How to add gaussian noise in all channels of an image with randn? [closed]

asked 2015-12-17 09:59:00 -0600

shadowphoton gravatar image

I'm not sure if I'm doing something wrong, but I have a strange kind of "misunderstanding" with opencv function (in python) for random number generation - randn() http://docs.opencv.org/2.4/modules/co...

When I try to add gaussian noise to RGB image (adding normally distributed random numbers in "dst" matrix that has 3 channels), those random numbers get only distributed through one channel (the first one... blue). Other channels stay unchanged. I am implementing simple peace of code

cv2.randn(gauss, mean, sigma)

which with

bg, gg, rg = cv2.split(gauss)

shows that I haven't changed anything in gg and rg.

Am I doing something wrong?

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by shadowphoton
close date 2015-12-17 11:57:35.226276

Comments

show your mean and sigma (i'm already suspecting something ...)

berak gravatar imageberak ( 2015-12-17 10:46:23 -0600 )edit

Currently mean is 0, and sigma somwhere around 0.3... But there is no difference for R and G channels if I set mean to 0 or 255, or if I set sigma to 0.01 or 127 or whatever...

shadowphoton gravatar imageshadowphoton ( 2015-12-17 11:15:30 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
2

answered 2015-12-17 11:31:06 -0600

berak gravatar image

you need one sigma / mean per channel:

(else, you got mean=sigma=0, so no visible change)

m = (50,50,50) 
s = (50,50,50)
cv2.randn(img,m,s);
edit flag offensive delete link more

Comments

1

Yes, this solved it. Thank you.

shadowphoton gravatar imageshadowphoton ( 2015-12-17 11:47:59 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2015-12-17 09:59:00 -0600

Seen: 20,339 times

Last updated: Dec 17 '15