add gaussian noise to colour image
I want to add gaussian noise to colour image where the standard deviation of gaussian noise were varied from 0.2 to 2 at 0.2 intervals.
Asked: 2015-12-28 03:27:32 -0600
Seen: 2,370 times
Last updated: Dec 28 '15
And what have you tried?
I have tried to separate the colour channels and add noise to each of them and merge them. And succeed to do so. But I want to separate the Y Cr Cb components and then add noise to only Y. Finally merge the components but could not. My code for colour channels:
And why can't you add noise just to channel Y? Are you getting any errors or what?
I can split the Y Cr, and Cb. I can add noise to Y too. But while I am trying to merge I am getting assertion error.
which assertion error? and with which exact code? Please, provide all the relevant information, we can't imagine things...
my code:
Mat ycrcb = input.clone(); cvtColor(input, ycrcb, CV_BGR2YCrCb);
This is the error OpenCV Error: Assertion failed (mv[i].size == mv[0].size && mv[i].depth() == depth) in merge, file /Users/hossainmdshakhawat/opencv-3.0.0/modules/core/src/convert.cpp, line 950 libc++abi.dylib: terminating with uncaught exception of type cv::Exception: /Users/hossainmdshakhawat/opencv-3.0.0/modules/core/src/convert.cpp:950: error: (-215) mv[i].size == mv[0].size && mv[i].depth() == depth in function merge
Please suggest is there any better and simple way to add noise to colour with varying std of gaussian noise.
You're modifying Y channel and converting it to CV_32F, but your Cr and Cb channels are still CV_8U. Therefore, you can't merge them (all of them have to have the same depth).
Thanks it fixed the error but the resulting noisy image is some how different. It is a yellowish image. And this is not my desired target. Is my way is wrong ? I am very new at opencv and image processing